注册

创建格式化输出 Claude原生

Claude Formatted Output

POST https://api.quickrouter.ai/v1/messages 在线调试 →
Authorization

在 Header 添加参数 Authorization,其值为 Bearer 之后拼接 Token

示例: Authorization: Bearer ********************

请求参数

Header 参数
Content-Type string
必需
示例: application/json
Authorization string
必需
示例: Bearer $OPENAI_API_KEY
Body 参数 application/json
model string
必需
要使用的模型的 ID,如 claude-sonnet-4-5-20250929。
messages array [object]
必需
至今为止对话所包含的消息列表。
max_tokens integer
可选
生成的最大标记数。
output_format object
必需
指定输出格式,type 设为 json_schema,schema 中定义 JSON 结构。
示例
{
    "model": "claude-sonnet-4-5-20250929",
    "max_tokens": 1024,
    "messages": [
        {
            "role": "user",
            "content": "Extract the key information from this email: John Smith (john@example.com) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
        }
    ],
    "output_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
        }
    }
}

请求示例代码

curl --location --request POST 'https://api.quickrouter.ai/v1/messages' \
--header 'Accept: application/json' \
--header 'anthropic-beta: structured-outputs-2025-11-13' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "claude-sonnet-4-5-20250929",
    "max_tokens": 1024,
    "messages": [
        {
            "role": "user",
            "content": "Extract the key information from this email: John Smith (john@example.com) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
        }
    ],
    "output_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
        }
    }
}'
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("anthropic-beta", "structured-outputs-2025-11-13");
myHeaders.append("Authorization", "Bearer <token>");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
   "model": "claude-sonnet-4-5-20250929",
   "max_tokens": 1024,
   "messages": [
      {
         "role": "user",
         "content": "Extract the key information from this email: John Smith (john@example.com) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
      }
   ],
   "output_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
      }
   }
});

var requestOptions = {
   method: 'POST',
   headers: myHeaders,
   body: raw,
   redirect: 'follow'
};

fetch("https://api.quickrouter.ai/v1/messages", requestOptions)
   .then(response => response.text())
   .then(result => console.log(result))
   .catch(error => console.log('error', error));
import http.client
import json

conn = http.client.HTTPSConnection("api.quickrouter.ai")
payload = json.dumps({
   "model": "claude-sonnet-4-5-20250929",
   "max_tokens": 1024,
   "messages": [
      {
         "role": "user",
         "content": "Extract the key information from this email: John Smith (john@example.com) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
      }
   ],
   "output_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
      }
   }
})
headers = {
   'Accept': 'application/json',
   'anthropic-beta': 'structured-outputs-2025-11-13',
   'Authorization': 'Bearer <token>',
   'Content-Type': 'application/json'
}
conn.request("POST", "/v1/messages", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

返回响应

响应参数 🟢 200 OK · application/json
id string
必需
object string
必需
choices array [object]
必需
usage object
必需
示例
{
    "id": "chatcmpl-123",
    "object": "chat.completion",
    "created": 1677652288,
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "{\"name\": \"John Smith\", \"email\": \"john@example.com\", \"plan_interest\": \"Enterprise\", \"demo_requested\": true}"
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 50,
        "completion_tokens": 30,
        "total_tokens": 80
    }
}