API Reference
API 文档
OpenAI 兼容协议:下游用户只需更换 Base URL 与 API Key,即可把现有接入切换到 ModelGate。
接入域名
正式域名
https://coziapi.china-yida.comTLS 证书与沙箱 443 已就绪、公网解析已生效;需平台完成该域名的流量映射后对外可用
外部平台接入(扣子供应商等)若提示 TLS validation failed,请改用「平台直连」域名作为 Base URL。
全类型调用端点
POST
https://coziapi.china-yida.com/api/v1/chat/completions对话生成POST
https://coziapi.china-yida.com/api/v1/images/generations图像生成POST
https://coziapi.china-yida.com/api/v1/videos/generations视频生成POST
https://coziapi.china-yida.com/api/v1/audio/speech语音合成POST
https://coziapi.china-yida.com/api/v1/audio/transcriptions语音识别POST
https://coziapi.china-yida.com/api/v1/embeddings向量表示POST
https://coziapi.china-yida.com/api/v1/search联网搜索GET
https://coziapi.china-yida.com/api/v1/models模型列表鉴权方式:请求头携带Authorization: Bearer sk-gw-xxxx,密钥在「API 密钥」页发行,同一把 Key 可调用全部类型端点。
SSE 流式帧格式
data: {"id":"chatcmpl-...","object":"chat.completion.chunk",
"choices":[{"delta":{"content":"你"},"finish_reason":null}]}
data: {"id":"chatcmpl-...", ...,
"choices":[{"delta":{},"finish_reason":"stop"}]}
data: [DONE]计费说明 · 积分体系
40 积分 = ¥1每次调用成功后按实际用量扣减密钥积分,余额不足返回 402;每次响应携带
gateway.credits_used / cost_cny / balance_after字段,可精确对账。请求参数
全类型参数速查
七类端点的请求参数规格一览(取各类型默认模型示例)。个别对话模型的 thinking 开关等差异,请在模型广场点击「参数详情」查看模型级规格,或通过 GET /api/v1/models 的 parameters 字段获取。
对话生成
POST /api/v1/chat/completionsmodel: doubao-seed-2-0-pro-260215| 参数 | 类型 | 必填 | 默认值 | 可选值 / 范围 | 说明 |
|---|---|---|---|---|---|
| model | string | 必填 | doubao-seed-2-1-turbo-260628 | — | 模型 ID,取模型广场中该模型的 ID |
| messages | array | 必填 | — | ≥ 1 条消息 | 对话消息列表,role 支持 system / user / assistant;多模态模型可在 content 数组中携带 image_url / video_url 分段 |
| stream | boolean | 可选 | false | — | 是否流式返回(SSE,data: chunk → [DONE]) |
| temperature | number | 可选 | 1.0 | 0 ~ 2 | 采样温度,越高输出越发散,越低越确定 |
| user | string | 可选 | — | — | 终端用户标识,用于安全审计与滥用追踪 |
| caching | enum | 可选 | disabled | enableddisabled | 上下文缓存开关,开启后重复对话前缀可命中缓存,按缓存命中价计费(参考价见模型广场四项价格) |
| thinking | enum | 可选 | disabled | enableddisabled | 深度思考模式开关,开启后模型先输出思考链再给出答案,适合复杂推理任务 |
curl -N -X POST https://coziapi.china-yida.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-gw-你的密钥" \
-d '{
"model": "doubao-seed-2-0-pro-260215",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "描述这张图片里的内容"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/photo.jpg",
"detail": "high"
}
}
]
}
],
"stream": true,
"temperature": 1,
"thinking": "disabled",
"caching": "enabled"
}'图像生成
POST /api/v1/images/generationsmodel: doubao-seedream-5-0-flash-260915| 参数 | 类型 | 必填 | 默认值 | 可选值 / 范围 | 说明 |
|---|---|---|---|---|---|
| model | string | 可选 | doubao-seedream-5-0-flash-260915 | — | 图像生成模型 ID |
| prompt | string | 必填 | — | 1 ~ 2000 字符 | 图像内容描述,支持中英文 |
| image | string | 可选 | — | — | 参考图 URL(图生图模式),支持数组实现多参考图,与 prompt 搭配使用 |
| size | enum | 可选 | 2K | 1K2K4K | 输出分辨率档位,推荐 2K;也可传自定义宽高(如 2048x2048) |
| watermark | boolean | 可选 | true | — | 是否添加水印标识 |
| optimize_prompt_mode | string | 可选 | standard | — | 提示词优化模式(standard = 上游自动润色 prompt) |
| sequential_image_generation | enum | 可选 | — | autodisabled | 组图生成:auto = 按语义自动拆分为多张连续画面 |
| sequential_image_generation_max_images | integer | 可选 | 15 | 1 ~ 15 | 组图模式最大出图数量,计费按实际生成张数 × 8.8 积分 |
| response_format | enum | 可选 | url | urlb64_json | 返回形式:对象存储签名 URL 或 Base64 |
curl -X POST https://coziapi.china-yida.com/api/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-gw-你的密钥" \
-d '{
"prompt": "深夜机房里一排机柜上的绿色运行指示灯,特写",
"size": "2K",
"watermark": true,
"optimize_prompt_mode": "standard",
"sequential_image_generation": "auto",
"sequential_image_generation_max_images": 4,
"response_format": "url"
}'视频生成
POST /api/v1/videos/generationsmodel: doubao-seedance-2-0-260128| 参数 | 类型 | 必填 | 默认值 | 可选值 / 范围 | 说明 |
|---|---|---|---|---|---|
| model | string | 可选 | doubao-seedance-2-0-260128 | — | 视频生成模型 ID |
| prompt | string | 必填 | — | ≤ 2000 字符 | 视频内容与镜头描述 |
| first_frame | string | 可选 | — | — | 首帧参考图 URL(图生视频),与多模态参考模式互斥 |
| last_frame | string | 可选 | — | — | 尾帧参考图 URL,必须与 first_frame 搭配组成首尾帧控制 |
| reference_images | array | 可选 | — | — | 多模态参考图列表(主体一致性),可与 reference_video / reference_audio 混用 |
| reference_video | string | 可选 | — | — | 参考视频 URL,风格/运镜迁移 |
| reference_audio | string | 可选 | — | — | 参考音频 URL,音色/配乐迁移 |
| duration | integer | 可选 | 5 | 4 ~ 12 秒(-1 智能时长) | 视频时长,计费按实际时长 × 分辨率单价(480p 32 / 720p 40 / 1080p 56 积分/秒) |
| ratio | enum | 可选 | 16:9 | 21:916:94:31:19:16 | 画面宽高比 |
| resolution | enum | 可选 | 720p | 480p720p1080p | 分辨率档位 |
| generate_audio | boolean | 可选 | true | — | 是否同步生成音频(Seedance 2.0 支持音视频同步) |
| watermark | boolean | 可选 | true | — | 是否添加 AI 生成水印 |
| seed | integer | 可选 | — | ≥ 0 | 随机种子,固定种子可复现同一画面 |
| camera_fixed | boolean | 可选 | false | — | 固定镜头(不运镜) |
| max_wait_seconds | integer | 可选 | 300 | 60 ~ 900 | 同步等待生成完成的最长时间,超时返回任务 ID 供轮询 |
curl -X POST https://coziapi.china-yida.com/api/v1/videos/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-gw-你的密钥" \
-d '{
"prompt": "镜头缓缓推进,机房里的绿色指示灯规律闪烁",
"first_frame": "https://example.com/first-frame.jpg",
"duration": 5,
"ratio": "16:9",
"resolution": "720p",
"generate_audio": true,
"watermark": false,
"camera_fixed": false,
"max_wait_seconds": 300
}'语音合成
POST /api/v1/audio/speechmodel: doubao-tts-bigmodel| 参数 | 类型 | 必填 | 默认值 | 可选值 / 范围 | 说明 |
|---|---|---|---|---|---|
| model | string | 可选 | doubao-tts-bigmodel | — | 语音合成模型 ID |
| input | string | 必填 | — | ≤ 1000 字符/次 | 待合成文本(与 ssml 二选一) |
| voice | string | 可选 | zh_female_xiaohe_uranus_bigtts | — | 音色 ID 自由透传(火山音色库任意 ID),当前环境已验证可用:zh_female_xiaohe_uranus_bigtts;未开通的音色上游返回 resource mismatch 错误 |
| audio_format | enum | 可选 | mp3 | mp3wavogg_opuspcm | 输出音频编码格式 |
| speech_rate | number | 可选 | 0 | -50 ~ 100 | 语速调节,0 为原速 |
| loudness_rate | number | 可选 | 0 | -50 ~ 50 | 响度调节,0 为原始响度 |
| sample_rate | integer | 可选 | 24000 | 8000160002205024000320004410048000 | 采样率(Hz) |
| ssml | string | 可选 | — | — | SSML 标记文本,可控制停顿、多音字、数字读法(传入后优先于 input) |
curl -X POST https://coziapi.china-yida.com/api/v1/audio/speech \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-gw-你的密钥" \
-d '{
"input": "您好,欢迎使用大模型统一网关。",
"voice": "zh_female_tianmeixiaoyuan",
"audio_format": "mp3",
"sample_rate": 24000,
"speech_rate": 0,
"loudness_rate": 0
}'语音识别
POST /api/v1/audio/transcriptionsmodel: doubao-asr-sauc| 参数 | 类型 | 必填 | 默认值 | 可选值 / 范围 | 说明 |
|---|---|---|---|---|---|
| model | string | 可选 | doubao-asr-sauc | — | 语音识别模型 ID |
| audio_url | string | 可选 | — | — | 音频文件公网 URL(与 audio_base64 二选一) |
| audio_base64 | string | 可选 | — | — | Base64 编码音频(与 audio_url 二选一) |
| audio_format | enum | 可选 | mp3 | mp3wavoggm4aaac | 音频编码格式 |
| audio_sample_rate | integer | 可选 | 16000 | 8000160003200044100 | 采样率(Hz) |
curl -X POST https://coziapi.china-yida.com/api/v1/audio/transcriptions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-gw-你的密钥" \
-d '{
"audio_url": "https://example.com/audio.mp3",
"audio_format": "mp3",
"audio_sample_rate": 16000
}'向量表示
POST /api/v1/embeddingsmodel: doubao-embedding-vision-251215| 参数 | 类型 | 必填 | 默认值 | 可选值 / 范围 | 说明 |
|---|---|---|---|---|---|
| model | string | 可选 | doubao-embedding-vision-251215 | — | 向量模型 ID |
| input | array | 可选 | — | ≤ 64 条 | 文本列表(字符串数组),与 image / video 至少传入一项 |
| image | string | 可选 | — | — | 图像 URL,参与多模态向量化 |
| video | string | 可选 | — | — | 视频 URL,参与多模态向量化 |
| dimensions | integer | 可选 | 模型默认 | 51210242048 | 输出向量维度档位,不传使用模型默认 |
| encoding_format | enum | 可选 | float | floatbase64 | 向量编码返回格式 |
| instructions | string | 可选 | — | — | 嵌入指令(如「为电商搜索优化」),引导向量偏向特定检索任务 |
| multi_embedding | boolean | 可选 | false | — | 多向量表示(Matryoshka 多表征),开启后 data 返回 multi_embedding 数组 |
| sparse_embedding | boolean | 可选 | false | — | 稀疏向量(词级权重),开启后 data 返回 sparse_embedding 列表,与稠密向量混检 |
curl -X POST https://coziapi.china-yida.com/api/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-gw-你的密钥" \
-d '{
"input": [
"大模型统一网关",
"支持多模态向量表示"
],
"dimensions": 1024,
"encoding_format": "float",
"instructions": "为技术文档检索优化向量表示",
"multi_embedding": false,
"sparse_embedding": false
}'联网搜索
POST /api/v1/searchmodel: web-search-pro| 参数 | 类型 | 必填 | 默认值 | 可选值 / 范围 | 说明 |
|---|---|---|---|---|---|
| model | string | 可选 | web-search-pro | — | 搜索模型 ID |
| query | string | 必填 | — | ≤ 400 字符 | 搜索关键词 |
| count | integer | 可选 | 10 | 1 ~ 20 | 返回结果条数 |
| search_type | enum | 可选 | web_summary | webweb_summaryimage | 检索类型:web 全文 / web_summary 网页+AI摘要 / image 图片 |
| need_summary | boolean | 可选 | true | — | 是否返回 AI 聚合摘要(search_type=web_summary 时生效) |
| need_content | boolean | 可选 | false | — | 是否返回网页正文全文(结果 content 字段) |
| need_url | boolean | 可选 | true | — | 是否返回结果 URL |
| time_range | enum | 可选 | noLimit | oneDayoneWeekoneMonthoneYearnoLimit | 时间范围过滤 |
| sites | array | 可选 | — | — | 限定站点列表(如 ["gov.cn"]),传入后仅检索指定站点 |
| block_hosts | array | 可选 | — | — | 屏蔽站点列表,命中域名的结果将被过滤 |
curl -X POST https://coziapi.china-yida.com/api/v1/search \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-gw-你的密钥" \
-d '{
"query": "豆包大模型 最新进展",
"search_type": "web_summary",
"count": 5,
"need_summary": true,
"need_content": false,
"need_url": true,
"time_range": "oneWeek",
"block_hosts": [
"ad.example.com"
]
}'代码示例
curl -N -X POST https://coziapi.china-yida.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-gw-你的密钥" \
-d '{
"model": "doubao-seed-2-0-pro-260215",
"messages": [{ "role": "user", "content": "你好,介绍一下你自己" }],
"stream": true
}'在线调试 Playground
POST https://coziapi.china-yida.com/api/v1/chat/completions错误码
当前内置模型共 16 个:doubao-seed-2-1-turbo-260628 · doubao-seed-2-0-pro-260215 · doubao-seed-2-0-lite-260215 · doubao-seed-2-0-mini-260215 · glm-5-2-260617 · glm-5-0-260211 · glm-5-turbo-260316 · minimax-m2-5-260212 · minimax-m2-7-260318 · qwen-3-5-plus-260215 · doubao-seedream-5-0-flash-260915 · doubao-seedance-2-0-260128 · doubao-tts-bigmodel · doubao-asr-sauc · doubao-embedding-vision-251215 · web-search-pro