You need to enable JavaScript to run this app.
文档中心
火山方舟

火山方舟

复制全文
下载 pdf
使用 Responses API
结构化输出(beta)
复制全文
下载 pdf
结构化输出(beta)
当需要模型输出程序可处理的标准格式(主要是 JSON)而非自然语言时,可开启结构化输出能力,以支持标准化处理或展示。​
通过配置 text.format 对象,指定模型输出 JSON 格式,还可以通过定义 JSON 结构,限定模型输出字段信息。​
相较于通过提示词控制模型输出 JSON 格式,使用结构化输出能力具有以下优势:​
  • 输出可靠:输出结构符合预期数据类型,包括字段层级、名称、类型、顺序等,避免必要字段缺失或枚举值幻觉。​
  • 使用简单:通过 API 字段定义输出格式,提示词更加简单,无需在提示词中反复强调或使用强约束措辞。​
说明​
该能力尚在 beta 阶段,受资源与平台负载影响,服务可用性可能随访问情况产生波动,请谨慎在生产环境使用。​
支持模型​
250615及之后版本的大语言模型,如无特殊说明,默认支持 Responses API,方舟平台大语言模型列表,请参见:结构化输出能力(beta)。​
API文档​
json_object 模式​
这段代码展示了如何利用 Responses API 实现 JSON Object 结构化输出。​
​
Curl
Python
Go
Java
OpenAI SDK
​
​
curl https://ark.cn-beijing.volces.com/api/v3/responses \​
-H "Authorization: Bearer $ARK_API_KEY" \​
-H "Content-Type: application/json" \​
-d '{​
"model": "doubao-seed-2-1-pro-260915",​
"thinking": { "type": "disabled" },​
"text": {​
"format": {​
"type": "json_object"​
}​
},​
"input": [​
{​
"role": "system",​
"content": "你是一位专业的数学助教,收到用户提出的数学问题后,需以结构化 JSON 格式输出。返回的json中应包含explanation和answer字段"​
},​
{​
"role": "user",​
"content": "根号三的近似值是多少"​
}​
]​
}'​
​
​
返回预览​
​
{​
"explanation": "根号三即√3,其近似值可通过逐步逼近法确定。首先,1²=1,2²=4,故√3在1和2之间。进一步计算,1.7²=2.89,1.8²=3.24,因此√3在1.7和1.8之间。继续精确,1.73²=2.9929,1.732²=2.999824(接近3),1.7321²≈3.00017(略大于3)。综上,√3的近似值通常取1.732。",​
"answer": "1.732"​
}​
​
json_schema 模式​
这段代码展示了如何利用 Responses API 实现遵循 schema 字段定义的 JSON 结构化输出。​
​
Curl
OpenAI SDK
​
​
curl https://ark.cn-beijing.volces.com/api/v3/responses \​
-H "Content-Type: application/json" \​
-H "Authorization: Bearer $ARK_API_KEY" \​
-d '{​
"model": "doubao-seed-2-1-pro-260915",​
"input": [​
{​
"role": "user",​
"content": [​
{​
"type": "input_text",​
"text": "return in json format how can I solve 8x + 7 = -23"​
}​
]​
}​
],​
"thinking": {​
"type": "disabled"​
},​
"stream": false,​
"text": {​
"format": {​
"type": "json_schema",​
"name": "math_reasoning",​
"schema": {​
"type": "object",​
"properties": {​
"steps": {​
"type": "array",​
"items": {​
"type": "object",​
"properties": {​
"explanation": {​
"type": "string"​
},​
"output": {​
"type": "string"​
}​
},​
"required": [​
"explanation",​
"output"​
],​
"additionalProperties": false​
}​
},​
"final_answer": {​
"type": "string"​
}​
},​
"required": [​
"steps",​
"final_answer"​
],​
"additionalProperties": false​
}​
}​
}​
}'​
​
​
返回预览​
​
{​
"steps": [​
{​
"explanation": "Subtract 7 from both sides to isolate the term with x",​
"output": "8x = -23 - 7"​
},​
{​
"explanation": "Simplify the right side",​
"output": "8x = -30"​
},​
{​
"explanation": "Divide both sides by 8 to solve for x",​
"output": "x = -30/8"​
},​
{​
"explanation": "Simplify the fraction",​
"output": "x = -15/4"​
}​
],​
"final_answer": "x = -15/4"​
}​
​
模式对比:json_object 与 json_schema​
json_schema 是 json_object 的演进版本,两种模式都支持 JSON 结构化输出,具体的异同如下。​
​
结构化输出​
json_schema​
json_object​
生成 JSON 回复​
是​
是​
可定义 JSON 结构​
是​
否​
仅保障回复是合法 JSON​
是否推荐​
是​
否​
支持的模型​
严格模式​
支持​
通过设置 strict 为 true 生效。​
不涉及​
配置方式​
​
"text": {​
"format": {​
"type": "json_schema",​
"name": "my_schema",​
"strict": true,​
"schema": {​
...​
}​
}​
}​
​
​
"text": {​
"format": {​
"type": "json_object"​
}​
}​
​
​
使用限制​
  • Responses API QPS 限流如下。如果需要提升限流值,请提交 工单。​
​
接口名称​
账号维度的 QPS 限流​
创建模型响应​
无​
查询模型响应​
20​
列出输入项​
20​
删除模型响应​
20​
​
​
最近更新时间:2026.09.22 16:52:18
这个页面对您有帮助吗?
有用
有用
无用
无用