结构化输出
POST /v1/chat/completions
截至 2026 年 3 月 23 日,Crazyrouter 生产环境已验证 gpt-5.4 + response_format.type = "json_schema" 可以返回可直接解析的 JSON。
推荐路径:json_schema
curl https://crazyrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-5.4",
"messages": [
{
"role": "user",
"content": "Return the people and roles from: Alice is CTO. Bob is PM."
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "people_roles",
"strict": true,
"schema": {
"type": "object",
"properties": {
"people": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"role": {"type": "string"}
},
"required": ["name", "role"],
"additionalProperties": false
}
}
},
"required": ["people"],
"additionalProperties": false
}
}
}
}'
生产环境实际返回的 message.content 可直接解析为:
{
"people": [
{
"name": "Alice",
"role": "CTO"
},
{
"name": "Bob",
"role": "PM"
}
]
}
代码侧处理
import json
content = response["choices"][0]["message"]["content"]
data = json.loads(content)
本轮生产验证只确认了 json_schema 这条严格结构化输出路径。旧式 json_object 模式没有在本轮单独复测,因此不再作为当前主示例保留。