接口详情
http调用
请求方式:POST
请求路径:https://ai.ctaigw.cn/v1/responses
说明
归属中国大陆区域的模型,HTTP 请求地址:https://ai.ctaigw.cn/v1/responses
归属全球区域的模型,根据算力所属区域,HTTP 请求地址存在差异,具体模型的请求地址详见控制台-模型广场-模型详情页-调用示例。
美洲:https://ai.ctaigw.com/amer/v1/responses,欧洲:https://ai.ctaigw.com/eu/v1/responses,亚洲:https://ai.ctaigw.com/as/v1/responses
您需要先获取与配置 APP Key。若通过 OpenAI SDK 进行调用,需要安装 SDK,并将
base_url配置为https://ai.ctaigw.cn/v1。不同模型对参数的支持范围存在差异(如
reasoning、内置工具、text.format的 json_schema 等),以模型官方介绍为准;未支持的参数可能被忽略或返回 400 错误。
请求头
| 参数 | 必填 | 说明 |
|---|---|---|
| Content-Type | 是 | 固定 application/json |
| Authorization | 是 | Bearer ${YOUR_APP_KEY} |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型调用名称 |
| input | string 或 array | 是 | 模型输入。传字符串时等价于一条 role=user 的纯文本消息;传数组时为输入条目列表,按顺序排列 |
| input[].type | string | 否 | 输入条目类型:message、function_call、function_call_output、reasoning、item_reference。默认 message |
| input[].role | string | 否 | 角色:user、assistant、system、developer。type 为 message 时必填 |
| input[].content | string 或 array | 否 | 消息内容。纯文本可直接传字符串;多模态需传内容数组 |
| input[].content[].type | string | 是 | 内容类型:input_text、input_image、input_file、input_audio |
| input[].content[].text | string | 否 | 输入文本。type 为 input_text 时必填 |
| input[].content[].image_url | string | 否 | 图片地址,支持公网 URL 或 data:image/xxx;base64,...。type 为 input_image 时必填 |
| input[].content[].detail | string | 否 | 图片解析精度:auto、low、high,默认 auto |
| input[].content[].file_id | string | 否 | 已上传文件的 ID。type 为 input_file 时与 file_url 二选一 |
| input[].content[].file_url | string | 否 | 文件地址。type 为 input_file 时与 file_id 二选一 |
| input[].content[].filename | string | 否 | 文件名,便于模型识别文件类型 |
| input[].content[].input_audio | object | 否 | 音频输入。type 为 input_audio 时必填 |
| input[].content[].input_audio.data | string | 是 | 音频数据,Base64 编码或可访问的音频 URL |
| input[].content[].input_audio.format | string | 是 | 音频格式,如 mp3、wav |
| input[].call_id | string | 否 | 工具调用 ID。type 为 function_call、function_call_output 时必填 |
| input[].name | string | 否 | 函数名。type 为 function_call 时必填 |
| input[].arguments | string | 否 | 函数入参,JSON 字符串。type 为 function_call 时必填 |
| input[].output | string | 否 | 工具执行结果,JSON 字符串。type 为 function_call_output 时必填 |
| instructions | string | 否 | 插入模型上下文的系统(或开发者)消息。与 previous_response_id 一起使用时,上一次响应的 instructions 不会延续到本次请求,便于随时替换系统提示 |
| previous_response_id | string | 否 | 上一次响应的 ID。传入后服务端自动拼接上一轮上下文,实现有状态多轮对话;不能与 conversation 同时使用 |
| conversation | string 或 object | 否 | 关联的会话 ID。会话中的历史条目会自动拼接到本次输入前,本次输入与输出也会写回该会话;不能与 previous_response_id 同时使用 |
| store | boolean | 否 | 是否存储本次响应以便后续通过 previous_response_id 检索,默认 true。设为 false 时为无状态调用,需自行回传全部历史条目 |
| stream | boolean | 否 | 默认 false。true 开启流式输出,以 SSE 事件流增量返回,长文本建议开启,降低超时风险 |
| stream_options | object | 否 | 仅 stream=true 生效 |
| stream_options.include_obfuscation | boolean | 否 | 是否在增量事件中加入混淆字段,默认 true;内网可信链路可设为 false 以减少带宽 |
| max_output_tokens | integer | 否 | 输出 Token 上限,包含可见输出与 reasoning tokens |
| max_tool_calls | integer | 否 | 单次响应中内置工具调用总次数上限,超出后的调用请求将被忽略 |
| temperature | float | 否 | 取值 [0,2],控制随机性;越高越发散,越低越确定;建议和 top_p 只设置其中一个 |
| top_p | float | 否 | 取值 (0,1.0],核采样;控制生成多样性 |
| top_logprobs | integer | 否 | 取值 0~20,返回每个 Token 位置上概率最高的若干候选及其对数概率 |
| tools | array | 否 | 模型可调用的工具列表,详见下方「工具参数」 |
| tool_choice | string 或 object | 否 | 工具选择策略:auto(默认,由模型决定)、none(不调用工具)、required(必须调用至少一个工具),或指定具体工具 {"type":"function","name":"get_weather"} |
| parallel_tool_calls | boolean | 否 | 是否允许模型并行发起多个工具调用,默认 true |
| reasoning | object | 否 | 推理模型配置 |
| reasoning.effort | string | 否 | 推理强度:minimal、low、medium、high(部分模型支持 xhigh) |
| reasoning.summary | string | 否 | 是否返回推理摘要:auto、concise、detailed |
| text | object | 否 | 文本输出配置 |
| text.format | object | 否 | 输出格式。{"type":"text"} 为默认纯文本;{"type":"json_schema","name":"...","schema":{...},"strict":true} 开启结构化 JSON 输出 |
| text.verbosity | string | 否 | 输出详略程度:low、medium、high(部分模型支持) |
| truncation | string | 否 | 上下文截断策略。auto:输入超出上下文窗口时从最早条目开始丢弃;disabled(默认):超出时直接返回 400 错误 |
| metadata | object | 否 | 附加到响应的键值对,最多 16 对,键最长 64 字符,值最长 512 字符 |
| user | string | 否 | 终端用户稳定标识,用于缓存分桶与风控;建议对用户名或邮箱做哈希,勿传原始个人信息 |
| safety_identifier | string | 否 | 更安全的终端用户标识,最长 64 字符,替代 user 字段 |
| prompt_cache_key | string | 否 | 提示词缓存键,用于提升相似请求的缓存命中率,替代 user 字段 |
| service_tier | string | 否 | 服务层级:auto、default、flex、priority(部分平台支持) |
| background | boolean | 否 | 是否后台异步执行,默认 false。为 true 时立即返回响应 ID,可通过 GET /v1/responses/{response_id} 轮询状态;需 store=true |
| include | array | 否 | 指定响应中额外返回的字段,如 message.output_text.logprobs、reasoning.encrypted_content、file_search_call.results、web_search_call.action.sources、code_interpreter_call.outputs |
工具参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| tools[].type | string | 是 | 工具类型:function、web_search、file_search、code_interpreter、image_generation、mcp、computer_use |
| tools[].name | string | 否 | 函数名,最长 64 字符,仅允许字母、数字、下划线、连字符。type 为 function 时必填 |
| tools[].description | string | 否 | 工具功能描述,模型据此判断是否调用,建议写清适用场景与限制 |
| tools[].parameters | object | 否 | 函数入参的 JSON Schema,type 为 function 时必填 |
| tools[].strict | boolean | 否 | 是否严格按 parameters 约束生成入参,默认 false |
| tools[].vector_store_ids | array | 否 | 向量库 ID 列表,type 为 file_search 时使用 |
| tools[].max_num_results | integer | 否 | 检索返回的最大条数,type 为 file_search 时使用 |
| tools[].filters | object | 否 | 检索过滤条件,支持 eq、ne、gt、gte、lt、lte、in、nin 及 and/or 组合 |
| tools[].server_label | string | 否 | MCP 服务标识,type 为 mcp 时必填 |
| tools[].server_url | string | 否 | MCP 服务地址,type 为 mcp 时使用 |
| tools[].require_approval | string 或 object | 否 | MCP 工具是否需要人工审批:never、always 或按工具名配置 |
说明:内置工具(web_search、file_search、code_interpreter、image_generation、computer_use、mcp)由平台侧执行,是否可用取决于模型与平台开通情况;function 工具由调用方自行执行,模型仅返回调用意图与入参。
非流式响应参数
| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | 响应唯一 ID,形如 resp_xxx |
| object | string | 固定值 response |
| created_at | number | 响应创建时间,Unix 时间戳(秒) |
| status | string | 响应状态:completed、incomplete、in_progress、failed、cancelled、queued |
| completed_at | number | 响应完成时间,仅 status 为 completed 时返回 |
| model | string | 实际使用的模型名称 |
| output | array | 模型生成的输出条目数组,长度与顺序由模型决定,详见「输出条目类型」 |
| output_text | string | SDK 聚合字段,将所有 output_text 内容拼接为完整文本;原始响应中可能不返回 |
| error | object | 生成失败时返回的错误对象,正常完成时为 null |
| error.code | string | 错误码,如 server_error、rate_limit_exceeded |
| error.message | string | 错误描述 |
| incomplete_details | object | 响应被截断时的详情,正常完成时为 null |
| incomplete_details.reason | string | 截断原因:max_output_tokens、content_filter、max_messages |
| instructions | string | 本次请求传入的系统消息,未传入时为 null |
| max_output_tokens | integer | 本次请求传入的输出 Token 上限,未传入时为 null |
| max_tool_calls | integer | 本次请求传入的工具调用次数上限 |
| previous_response_id | string | 上一轮响应 ID,单轮请求时为 null |
| conversation | object | 关联会话信息,包含 id |
| parallel_tool_calls | boolean | 是否允许并行工具调用 |
| temperature | float | 本次请求使用的采样温度 |
| top_p | float | 本次请求使用的核采样参数 |
| top_logprobs | integer | 本次请求的 top_logprobs 设置 |
| tool_choice | string 或 object | 本次请求的工具选择策略 |
| tools | array | 本次请求可用的工具列表 |
| text | object | 本次请求的文本输出配置 |
| reasoning | object | 本次请求的推理配置 |
| truncation | string | 本次请求的截断策略 |
| metadata | object | 本次请求传入的元数据 |
| user | string | 本次请求传入的终端用户标识 |
| service_tier | string | 实际生效的服务层级 |
| background | boolean | 是否为后台任务 |
| usage | object | Token 消耗统计 |
| usage.input_tokens | integer | 输入 Token 总数 |
| usage.input_tokens_details | object | 输入 Token 明细 |
| usage.input_tokens_details.cached_tokens | integer | 命中上下文缓存的 Token 数 |
| usage.input_tokens_details.cache_write_tokens | integer | 写入缓存的 Token 数(部分模型返回) |
| usage.output_tokens | integer | 输出 Token 总数(含 reasoning_tokens) |
| usage.output_tokens_details | object | 输出 Token 明细 |
| usage.output_tokens_details.reasoning_tokens | integer | 推理过程消耗的 Token 数 |
| usage.total_tokens | integer | 总消耗 Token = input_tokens + output_tokens |
输出条目类型
| type | 字段 | 说明 |
|---|---|---|
| message | id、status、role、content[] | 模型回复消息。role 固定 assistant;content[] 每项含 type(output_text、refusal)、text、annotations |
| message.content[].annotations | array | 引用与标注信息,如文件检索、网页搜索的出处 |
| function_call | id、call_id、name、arguments、status | function 工具调用。arguments 为 JSON 字符串,需在下一轮以 function_call_output 回传结果 |
| function_call_output | id、call_id、output、status | 工具执行结果条目(出现在 input 中,部分实现也会在 output 中回显) |
| reasoning | id、summary[]、encrypted_content | 推理条目。summary[] 为推理摘要,每项含 type(summary_text)、text |
| web_search_call | id、status、action | 联网搜索调用记录 |
| file_search_call | id、status、queries[]、results | 文件检索调用记录 |
| code_interpreter_call | id、status、code、outputs | 代码解释器调用记录 |
| image_generation_call | id、status、result | 图片生成调用记录,result 为 Base64 图片 |
| mcp_call | id、server_label、name、arguments、output、error | MCP 工具调用记录 |
| mcp_list_tools | id、server_label、tools[] | MCP 工具列表 |
| mcp_approval_request | id、server_label、name、arguments | MCP 工具人工审批请求 |
流式响应参数
流式模式返回 text/event-stream,每个事件由 event:(事件名)与 data:(JSON 载荷)两行组成,事件之间以空行分隔。所有事件均含 type 与 sequence_number 字段,sequence_number 单调递增,可用于断线重连后的续传定位。
| 事件(event / type) | 载荷字段 | 说明 |
|---|---|---|
| response.created | response | 响应对象已创建,status 为 in_progress,流开始 |
| response.in_progress | response | 响应进入生成中状态 |
| response.queued | response | 后台模式下响应排队中 |
| response.output_item.added | output_index、item | 新的输出条目开始生成 |
| response.content_part.added | item_id、output_index、content_index、part | 消息内新的内容分片开始 |
| response.output_text.delta | item_id、output_index、content_index、delta、logprobs | 增量文本,分片拼接得到完整回答 |
| response.output_text.done | item_id、output_index、content_index、text | 文本生成结束,返回完整文本 |
| response.content_part.done | item_id、output_index、content_index、part | 单个内容分片结束 |
| response.output_item.done | output_index、item | 单个输出条目结束,item 为完整条目 |
| response.reasoning_summary_text.delta | item_id、output_index、summary_index、delta | 增量推理摘要,开启 reasoning.summary 时返回 |
| response.reasoning_summary_text.done | item_id、output_index、summary_index、text | 推理摘要结束 |
| response.reasoning_text.delta | item_id、output_index、content_index、delta | 增量推理全文(部分模型返回) |
| response.reasoning_text.done | item_id、output_index、content_index、text | 推理全文结束 |
| response.function_call_arguments.delta | item_id、output_index、delta | 函数入参增量片段,需拼接为完整 JSON 字符串 |
| response.function_call_arguments.done | item_id、output_index、arguments | 函数入参生成结束 |
| response.web_search_call.in_progress / searching / completed | item_id、output_index | 联网搜索工具执行进度 |
| response.file_search_call.in_progress / searching / completed | item_id、output_index | 文件检索工具执行进度 |
| response.code_interpreter_call.in_progress / interpreting / completed | item_id、output_index | 代码解释器执行进度 |
| response.mcp_call.in_progress / completed / failed | item_id、output_index | MCP 工具执行进度 |
| response.image_generation_call.generating / completed | item_id、output_index | 图片生成进度 |
| response.completed | response | 生成成功结束,response 为完整响应对象,含 usage |
| response.incomplete | response | 生成被截断结束,response.incomplete_details 说明原因 |
| response.failed | response | 生成失败结束,response.error 说明错误 |
| error | code、message、param | 流中出现错误(如服务端异常、限流),可能单独下发后中断连接 |
说明:
以
response.completed、response.incomplete、response.failed作为一次流式响应的结束标志;部分实现会在末尾追加data: [DONE],客户端应兼容该行。开启
stream=true后,HTTP 状态码通常先返回 200,业务错误可能以error事件或response.failed的形式在流内下发,不能仅以 HTTP 状态码判断成功。流式模式下 usage 统计在
response.completed事件的 response.usage 中返回,中间事件不返回 usage。
请求/响应示例
基础文本请求
curl -X POST https://ai.ctaigw.cn/v1/responses \
-H "Authorization: Bearer ${YOUR_APP_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-max",
"instructions": "You are a helpful assistant.",
"input": "简单介绍向量数据库的用途"
}'多轮对话请求
curl -X POST https://ai.ctaigw.cn/v1/responses \
-H "Authorization: Bearer ${YOUR_APP_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-max",
"previous_response_id": "resp_xxxxxxxxxxxx",
"input": "再展开说说其中的近似最近邻检索"
}'多模态请求
curl -X POST https://ai.ctaigw.cn/v1/responses \
-H "Authorization: Bearer ${YOUR_APP_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen3-Omni-Flash",
"input": [
{
"type": "message",
"role": "user",
"content": [
{
"type": "input_image",
"image_url": "https://aaaa.ctyun.cn/pic/01.jpeg",
"detail": "auto"
},
{
"type": "input_text",
"text": "这是什么"
}
]
}
]
}'函数调用请求
curl -X POST https://ai.ctaigw.cn/v1/responses \
-H "Authorization: Bearer ${YOUR_APP_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-max",
"input": "厦门今天天气怎么样?",
"tools": [
{
"type": "function",
"name": "get_weather",
"description": "查询指定城市的实时天气",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string", "description": "城市名称" }
},
"required": ["city"]
},
"strict": true
}
],
"tool_choice": "auto"
}'工具结果回传(将上一轮 output 中的 function_call 条目与执行结果一并作为 input):
curl -X POST https://ai.ctaigw.cn/v1/responses \
-H "Authorization: Bearer ${YOUR_APP_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-max",
"previous_response_id": "resp_xxxxxxxxxxxx",
"input": [
{
"type": "function_call_output",
"call_id": "call_xxxxxxxxxxxx",
"output": "{\"temperature\":\"26℃\",\"weather\":\"多云\"}"
}
]
}'结构化输出请求
curl -X POST https://ai.ctaigw.cn/v1/responses \
-H "Authorization: Bearer ${YOUR_APP_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-max",
"input": "把以下订单信息抽取为 JSON:张三,13800000000,厦门市集美区,2 件",
"text": {
"format": {
"type": "json_schema",
"name": "order_info",
"strict": true,
"schema": {
"type": "object",
"properties": {
"name": { "type": "string" },
"phone": { "type": "string" },
"address": { "type": "string" },
"quantity": { "type": "integer" }
},
"required": ["name", "phone", "address", "quantity"],
"additionalProperties": false
}
}
}
}'非流式响应
{
"id": "resp_67ccd2bed1ec8190b14f964abc0542670bb6a6b452d3795b",
"object": "response",
"created_at": 1741382138,
"status": "completed",
"completed_at": 1741382139,
"model": "qwen3.7-max",
"output": [
{
"type": "message",
"id": "msg_67ccd2bf19e081909b2a8a5a3c7d0e12",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "向量数据库主要用于存储向量嵌入,支持相似度检索。",
"annotations": []
}
]
}
],
"output_text": "向量数据库主要用于存储向量嵌入,支持相似度检索。",
"parallel_tool_calls": true,
"tool_choice": "auto",
"tools": [],
"temperature": 1.0,
"top_p": 1.0,
"max_output_tokens": null,
"previous_response_id": null,
"reasoning": null,
"text": { "format": { "type": "text" } },
"truncation": "disabled",
"usage": {
"input_tokens": 20,
"input_tokens_details": { "cached_tokens": 0 },
"output_tokens": 11,
"output_tokens_details": { "reasoning_tokens": 0 },
"total_tokens": 31
},
"metadata": {},
"user": null,
"error": null,
"incomplete_details": null
}流式响应
event: response.created
data: {"type":"response.created","sequence_number":0,"response":{"id":"resp_67ccd2be","object":"response","status":"in_progress","model":"qwen3.7-max","output":[]}}
event: response.in_progress
data: {"type":"response.in_progress","sequence_number":1,"response":{"id":"resp_67ccd2be","object":"response","status":"in_progress"}}
event: response.output_item.added
data: {"type":"response.output_item.added","sequence_number":2,"output_index":0,"item":{"id":"msg_67ccd2bf","type":"message","status":"in_progress","role":"assistant","content":[]}}
event: response.content_part.added
data: {"type":"response.content_part.added","sequence_number":3,"item_id":"msg_67ccd2bf","output_index":0,"content_index":0,"part":{"type":"output_text","text":"","annotations":[]}}
event: response.output_text.delta
data: {"type":"response.output_text.delta","sequence_number":4,"item_id":"msg_67ccd2bf","output_index":0,"content_index":0,"delta":"向量数据库主要用于","logprobs":[]}
event: response.output_text.delta
data: {"type":"response.output_text.delta","sequence_number":5,"item_id":"msg_67ccd2bf","output_index":0,"content_index":0,"delta":"存储向量嵌入,支持相似度检索。","logprobs":[]}
event: response.output_text.done
data: {"type":"response.output_text.done","sequence_number":6,"item_id":"msg_67ccd2bf","output_index":0,"content_index":0,"text":"向量数据库主要用于存储向量嵌入,支持相似度检索。"}
event: response.content_part.done
data: {"type":"response.content_part.done","sequence_number":7,"item_id":"msg_67ccd2bf","output_index":0,"content_index":0,"part":{"type":"output_text","text":"向量数据库主要用于存储向量嵌入,支持相似度检索。","annotations":[]}}
event: response.output_item.done
data: {"type":"response.output_item.done","sequence_number":8,"output_index":0,"item":{"id":"msg_67ccd2bf","type":"message","status":"completed","role":"assistant","content":[{"type":"output_text","text":"向量数据库主要用于存储向量嵌入,支持相似度检索。","annotations":[]}]}}
event: response.completed
data: {"type":"response.completed","sequence_number":9,"response":{"id":"resp_67ccd2be","object":"response","status":"completed","model":"qwen3.7-max","output":[{"type":"message","id":"msg_67ccd2bf","status":"completed","role":"assistant","content":[{"type":"output_text","text":"向量数据库主要用于存储向量嵌入,支持相似度检索。","annotations":[]}]}],"usage":{"input_tokens":20,"input_tokens_details":{"cached_tokens":0},"output_tokens":11,"output_tokens_details":{"reasoning_tokens":0},"total_tokens":31}}}异常响应示例
{
"error": {
"type": "invalid_request_error",
"code": "missing_parameter",
"message": "Missing required parameter: 'input'.",
"param": "input"
}
}流内错误事件示例:
event: error
data: {"type":"error","code":"server_error","message":"The server had an error while processing your request.","param":null}错误码说明
| HTTP 状态码 | error.type | 常见 error.code | 说明 |
|---|---|---|---|
| 400 | invalid_request_error | missing_parameter、invalid_value、context_length_exceeded | 参数缺失、取值非法或输入超出上下文窗口 |
| 401 | authentication_error | invalid_api_key | APP Key 缺失、无效或已过期 |
| 403 | permission_error | model_not_allowed | 无该模型或该接口的访问权限 |
| 404 | not_found_error | model_not_found | 模型不存在或未开通 |
| 429 | rate_limit_error | rate_limit_exceeded、insufficient_quota | 触发限流或配额不足,建议退避重试 |
| 500 | server_error | internal_error | 服务端异常,可重试 |
| 503 | service_unavailable | model_overloaded | 模型负载过高,稍后重试 |
附录:与 Chat Completions 的主要差异
| 维度 | Chat Completions | Responses |
|---|---|---|
| 上下文 | messages 数组,需客户端维护全量历史 | input 条目 + previous_response_id 或 conversation,可由服务端维护状态 |
| 输出结构 | choices[].message,以文本为主 | output 条目数组,文本、工具调用、推理、图像等统一建模 |
| 工具调用 | tool_calls,arguments 需自行拼接解析 | function_call 条目 + call_id,配合 function_call_output 回传 |
| 推理内容 | reasoning_content | reasoning 条目与 summary,支持独立事件流式返回 |
| 内置工具 | 需自行实现 | 支持 web_search、file_search、code_interpreter、image_generation、mcp 等 |
| 流式协议 | chunk 增量,结构固定为 chat.completion.chunk | 语义化事件(response.created / output_text.delta / completed 等),带 sequence_number |
| 用量字段 | prompt_tokens / completion_tokens | input_tokens / output_tokens,附 cached_tokens、reasoning_tokens 明细 |