图像、音频、视频与检索接入

这些能力与对话使用相同的 Base URL 和 Bearer 密钥,但各自有独立的端点和请求体。下面的模型 ID 是可用的示例;上线前请到控制台 → 模型广场查看最新的模型目录。

图像生成

POST /v1/images/generations

以 JSON 格式发送提示词。生成结果从 data[0].url 读取;如果所选模型返回 base64,则从 data[0].b64_json 读取。

关键参数:prompt 和 model 为必填。用 size 设置分辨率,用 n 设置图片数量,用 response_format 选择 url 或 b64_json。quality 和 style 因模型而异,常见取值有 standard、hd 或 auto。

curl · image
curl https://api.chinaapi.ai/v1/images/generations \
  -H "Authorization: Bearer $CHINAAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seedream-4-5-251128",
    "prompt": "A cinematic skyline at blue hour",
    "size": "1024x1024",
    "response_format": "url",
    "n": 1
  }'

Gemini 图像生成

POST /v1/chat/completions

Gemini 图像模型使用 OpenAI Chat Completions 的请求结构。生成的 Markdown 图片从 choices[0].message.content 读取;图片数据是一个 data:image/... URL。

关键参数:在 model 中填写登录后在目录中看到的模型 ID,在 messages 中填写图像提示词。不要把这个模型发往 /v1/images/generations。

curl · Gemini image chat
curl https://api.chinaapi.ai/v1/chat/completions \
  -H "Authorization: Bearer $CHINAAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<GEMINI_IMAGE_MODEL>",
    "messages": [
      {
        "role": "user",
        "content": "Generate a cinematic skyline at blue hour"
      }
    ],
    "stream": false
  }'

语音转文字

POST /v1/audio/transcriptions

以 multipart 表单数据上传音频;不要手动设置 Content-Type 请求头。识别出的文本在 text 字段中返回。

关键参数:以 multipart 字段发送 model 和 file。所选模型支持时,可将 response_format 设为 json、text 或 verbose_json。

curl · transcription
curl https://api.chinaapi.ai/v1/audio/transcriptions \
  -H "Authorization: Bearer $CHINAAPI_KEY" \
  -F "model=qwen3-asr-flash" \
  -F "file=@speech.wav" \
  -F "response_format=json"

文字转语音

POST /v1/audio/speech

响应体是二进制音频,请将其写入文件。alloy 会选用该模型的默认音色;模型也可能提供厂商专属的音色 ID。

关键参数:使用 input、model 和 voice。通过 response_format 选择输出格式,例如 mp3 或 wav;所选模型支持时,还可以使用 speed 和 instructions。

curl · speech
curl https://api.chinaapi.ai/v1/audio/speech \
  -H "Authorization: Bearer $CHINAAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mimo-v2.5-tts",
    "input": "Hello from ChinaAPI.",
    "voice": "alloy",
    "response_format": "mp3"
  }' \
  --output speech.mp3

视频生成

POST /v1/video/generations

视频生成是异步的。只需提交一次,保存返回的 task_id,然后轮询 GET /v1/video/generations/{task_id},直到任务成功或失败。创建任务可能会消耗额度。

关键参数:有 prompt 和 model 即可发起任务。在支持的情况下,可以使用 duration、width、height、fps 和 n。分辨率是通用的清晰度控制方式。quality、quality_level、negative_prompt 或镜头设置等厂商专属参数,只有在该模型列出时才放进 metadata。

curl · video
curl https://api.chinaapi.ai/v1/video/generations \
  -H "Authorization: Bearer $CHINAAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "happyhorse-1.1-t2v",
    "prompt": "A paper boat crossing a moonlit lake",
    "duration": 5,
    "width": 1280,
    "height": 720
  }'

curl https://api.chinaapi.ai/v1/video/generations/$TASK_ID \
  -H "Authorization: Bearer $CHINAAPI_KEY"