创建格式化输出 Claude原生
![]()
Claude Sonnet 5.5 默认启用 adaptive thinking。不要使用 thinking.type: disabled/enabled 或 budget_tokens。最低前置思考模式为 between_tools,effort 仅可为 low/medium/high。查看迁移与响应解析。
在 Header 添加参数 Authorization,其值为 Bearer 之后拼接 Token
Authorization: Bearer ********************
请求参数
完整 JSON 请求体
{
"model": "claude-sonnet-5-5",
"max_tokens": 4096,
"messages": [
{
"role": "user",
"content": "Extract the key information from this email: John Smith ([email protected]) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
}
],
"output_config": {
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"plan_interest": {
"type": "string"
},
"demo_requested": {
"type": "boolean"
}
},
"required": [
"name",
"email",
"plan_interest",
"demo_requested"
],
"additionalProperties": false
}
},
"effort": "high"
}
}
请求示例代码
curl --fail-with-body --request POST 'https://api.apizt.com/v1/messages' \
--header "Authorization: Bearer ${tokenba_API_KEY}" \
--header 'Content-Type: application/json' \
--header 'anthropic-version: 2023-06-01' \
--data-raw '{
"model": "claude-sonnet-5-5",
"max_tokens": 4096,
"messages": [
{
"role": "user",
"content": "Extract the key information from this email: John Smith ([email protected]) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
}
],
"output_config": {
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"plan_interest": {
"type": "string"
},
"demo_requested": {
"type": "boolean"
}
},
"required": [
"name",
"email",
"plan_interest",
"demo_requested"
],
"additionalProperties": false
}
},
"effort": "high"
}
}'async function main() {
const headers = {
"Authorization": "Bearer " + process.env.tokenba_API_KEY,
"anthropic-version": "2023-06-01",
"Content-Type": "application/json"
};
const body = JSON.stringify({
"model": "claude-sonnet-5-5",
"max_tokens": 4096,
"messages": [
{
"role": "user",
"content": "Extract the key information from this email: John Smith ([email protected]) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
}
],
"output_config": {
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"plan_interest": {
"type": "string"
},
"demo_requested": {
"type": "boolean"
}
},
"required": [
"name",
"email",
"plan_interest",
"demo_requested"
],
"additionalProperties": false
}
},
"effort": "high"
}
});
const response = await fetch("https://api.apizt.com/v1/messages", { method: "POST", headers, body });
if (!response.ok) throw new Error("HTTP " + response.status + ": " + await response.text());
const result = await response.json();
for (const block of result.content || []) {
if (block.type === "text") console.log(block.text);
else if (block.type === "tool_use") console.log(JSON.stringify(block));
}
}
main().catch(console.error);import os
import requests
headers = {"Authorization": "Bearer " + os.environ["tokenba_API_KEY"]}
headers.update({'anthropic-version': '2023-06-01'})
payload = {'model': 'claude-sonnet-5-5',
'max_tokens': 4096,
'messages': [{'role': 'user',
'content': 'Extract the key information from this email: John Smith '
'([email protected]) is interested in our Enterprise plan and '
'wants to schedule a demo for next Tuesday at 2pm.'}],
'output_config': {'format': {'type': 'json_schema',
'schema': {'type': 'object',
'properties': {'name': {'type': 'string'},
'email': {'type': 'string'},
'plan_interest': {'type': 'string'},
'demo_requested': {'type': 'boolean'}},
'required': ['name',
'email',
'plan_interest',
'demo_requested'],
'additionalProperties': False}},
'effort': 'high'}}
response = requests.post('https://api.apizt.com/v1/messages', headers=headers, json=payload, timeout=120)
response.raise_for_status()
result = response.json()
for block in result.get("content", []):
if block.get("type") == "text":
print(block["text"])
elif block.get("type") == "tool_use":
print(block)返回响应
按 content[].type 读取文本、思考或工具块;thinking 可能出现在首位。工具循环需原样保留思考块与签名,再提交 tool_result。max_tokens 同时覆盖思考和文本。
以下为结构示例,不代表实际调用结果。
{
"id": "msg_demo",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-5-5",
"content": [
{
"type": "text",
"text": "{\"name\": \"John Smith\", \"email\": \"[email protected]\", \"plan_interest\": \"Enterprise\", \"demo_requested\": true}"
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 10,
"output_tokens": 8
}
}
当前模型与版本
依据 apizt 价格页,同步于 。以下型号按目录声明的协议与本页用途筛选;不代表所有参数和功能通用。切换前请核对型号说明、令牌分组与参数差异。Gemini 原生接口需同时替换 URL 中的模型 ID。
| 模型 ID | 能力标签 | 支持分组 |
|---|---|---|
claude-sonnet-5-5 | 对话,识图,工具 | 分组(6)
|
claude-opus-5-5 | 对话,工具,识图 | 分组(6)
|
claude-sonnet-5 | 对话,识图,工具 | 分组(8)
|
claude-fable-5-1 | 对话,识图,工具 | 分组(5)
|
claude-opus-5 | 对话,工具,识图 | 分组(7)
|
claude-opus-4-8 | 对话,识图,工具 | 分组(8)
|
claude-opus-4-6 | 对话,识图,工具 | 分组(10)
|
claude-opus-4-7 | 对话,识图,工具 | 分组(8)
|
共列入 15 个候选型号。查看完整模型、版本与接口目录。