Responses API

本文说明火山引擎模型在 AI Gateway 中的 Responses API 调用方式。对于火山文本生成、视觉理解、结构化输出和工具调用等新接入场景,建议优先使用 Responses API,而不是 Chat API。

一、请求地址

POST https://cn-shanghai-alicloud-aimesh.api.clickzetta.com/gateway/api/v3/responses

请求头:

Authorization: Bearer <API_KEY> Content-Type: application/json

二、为什么优先使用 Responses API

Responses API 覆盖能力更完整,适合承载文本、多模态输入、工具调用和后续高级能力。Chat API 更适合存量 OpenAI Chat Completions 代码兼容。

能力Chat APIResponses API
文本生成支持支持
视觉理解支持支持
结构化输出beta 阶段beta 阶段
函数调用 Function Calling支持支持
联网搜索 Web Search不支持支持
图像处理 Image Process不支持支持
私域知识库搜索 Knowledge Search不支持支持
云部署 MCP不支持支持
上下文缓存不支持支持,具体模型版本以模型广场为准

选择建议:

  • 新业务默认使用 Responses API。
  • 已有 Chat Completions 代码可以继续使用 Chat API,后续逐步迁移。
  • 需要联网搜索、图像处理、知识库检索、MCP 或上下文缓存时,必须使用 Responses API。
  • 如果模型广场详情页没有 Responses 示例,请以模型详情页为准。

三、基础文本生成

curl -X POST "$AI_GATEWAY_VOLC_BASE_URL/responses" \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "doubao-seed-2.0-lite", "input": "请总结 AI Gateway 的三个核心能力。", "max_output_tokens": 512 }'

Python 示例:

from openai import OpenAI client = OpenAI( base_url="https://cn-shanghai-alicloud-aimesh.api.clickzetta.com/gateway/api/v3", api_key="<your-api-key>", ) response = client.responses.create( model="doubao-seed-2.0-lite", input="请总结 AI Gateway 的三个核心能力。", max_output_tokens=512, ) print(response.output_text)

四、请求字段

字段类型必填说明
model
model
string模型名称。以模型广场详情页为准,例如
doubao-seed-2.0-lite
doubao-seed-2.0-lite
input
input
string / array输入内容,可以是字符串,也可以是多轮、多模态数组。
instructions
instructions
string系统指令,类似 Chat API 中的
system
system
消息。
stream
stream
boolean是否流式输出。
temperature
temperature
number采样温度。
top_p
top_p
number核采样参数。
max_output_tokens
max_output_tokens
integer最大输出 Token 数。
response_format
response_format
object结构化输出配置。
tools
tools
array工具定义。
tool_choice
tool_choice
string / object工具选择策略。
parallel_tool_calls
parallel_tool_calls
boolean是否允许并行工具调用。是否支持取决于模型能力。
metadata
metadata
object业务自定义元数据。
previous_response_id
previous_response_id
string用于衔接上一轮响应。是否支持取决于模型和网关能力。
store
store
boolean是否存储响应。企业场景应按合规要求设置。

五、input 写法

字符串输入

{ "model": "doubao-seed-2.0-lite", "input": "请把下面这句话翻译成英文:AI Gateway 支持统一模型治理。", "max_output_tokens": 512 }

多轮输入

{ "model": "doubao-seed-2.0-pro", "instructions": "你是企业知识库助手,回答要简洁准确。", "input": [ { "role": "user", "content": "AI Gateway 支持哪些能力?" }, { "role": "assistant", "content": "支持统一模型接入、API Key 管理、路由、用量统计等能力。" }, { "role": "user", "content": "请补充 BYOK 和权限管理。" } ] }

视觉理解输入

支持视觉输入的模型可以在

input
input
中传入文本和图片。

curl -X POST "$AI_GATEWAY_VOLC_BASE_URL/responses" \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "doubao-seed-1.6-vision", "input": [ { "role": "user", "content": [ { "type": "input_text", "text": "请识别图片中的主要内容,并输出 JSON。" }, { "type": "input_image", "image_url": "https://example.com/demo.png" } ] } ], "max_output_tokens": 1024 }'

注意:

  • 图片 URL 需要能被模型服务访问,不要使用本地路径。
  • 图片数量、大小和格式限制以模型详情页为准。
  • 视觉理解任务也建议优先使用 Responses API。

六、流式输出

curl -N -X POST "$AI_GATEWAY_VOLC_BASE_URL/responses" \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "doubao-seed-2.0-pro", "input": "请分步骤说明如何接入 AI Gateway。", "stream": true, "max_output_tokens": 1024 }'

流式返回通常为 SSE 事件。客户端需要按事件类型读取增量文本、工具调用和结束事件。

七、结构化输出

结构化输出仍处于 beta 阶段。需要稳定 JSON 时,可以使用

response_format
response_format
,同时在
instructions
instructions
中明确只输出 JSON。

curl -X POST "$AI_GATEWAY_VOLC_BASE_URL/responses" \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "doubao-seed-2.0-pro", "instructions": "你只输出合法 JSON,不要输出 Markdown。", "input": "抽取工单信息:客户反馈 API 调用 429,影响生产报表。字段包括 priority、category、summary。", "response_format": { "type": "json_object" }, "max_output_tokens": 512 }'

建议业务侧仍进行 JSON 解析和 Schema 校验。

八、工具调用

Responses API 支持函数调用,适合查询订单、检索知识库、调用内部服务等场景。

{ "model": "doubao-seed-2.0-pro", "input": "查询订单 202606150001 的物流状态。", "tools": [ { "type": "function", "name": "get_order_status", "description": "根据订单号查询物流状态", "parameters": { "type": "object", "properties": { "order_id": { "type": "string", "description": "订单号" } }, "required": ["order_id"] } } ], "tool_choice": "auto" }

基本处理流程:

  1. 客户端发送用户问题和工具定义。
  2. 模型返回工具调用意图和参数。
  3. 业务系统执行真实工具。
  4. 将工具结果回传给模型。
  5. 模型基于工具结果生成最终回答。

九、高级能力说明

Responses API 是火山后续高级能力的推荐承载接口。以下能力需以模型广场和接入点展示为准:

能力说明
Web Search联网搜索,适合需要实时网页信息的问答。
Image Process图像处理,适合图片编辑、分析或多模态处理任务。
Knowledge Search私域知识库搜索,适合企业内部知识问答。
MCP云部署 MCP 工具,适合统一接入外部工具能力。
Context Cache上下文缓存,适合重复长上下文、多轮长会话等场景。

如果业务需要这些能力,请优先选择 Responses API,并以模型详情页示例为准。

联系我们
预约咨询
微信咨询
电话咨询
邮件咨询