跳转到主要内容

Claude 原生格式

POST /v1/messages
本文页只写入 2026-03-22 已在 Crazyrouter 生产环境复核过的 Claude Messages 用法。 当前主示例模型:
  • claude-sonnet-4-6
  • claude-opus-4-6-thinking

认证

本轮已复核以下两种写法都可用:
x-api-key: YOUR_API_KEY
Authorization: Bearer YOUR_API_KEY
同时保留:
anthropic-version: 2023-06-01

基本对话

cURL
curl https://crazyrouter.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 128,
    "messages": [
      {
        "role": "user",
        "content": "Explain quantum computing in one sentence."
      }
    ]
  }'
当前生产返回的关键结构:
{
  "type": "message",
  "content": [
    {
      "type": "text",
      "text": "..."
    }
  ]
}

Function Calling

当前生产环境中,Claude 4.6 的工具调用可稳定通过 /v1/messages 返回 tool_use 首轮联调建议:
  • 显式传 tool_choice
  • 提示词里写清楚“必须调用工具,不要直接回答”
cURL
curl https://crazyrouter.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 256,
    "tools": [
      {
        "name": "get_time",
        "description": "Get the current time for a timezone",
        "input_schema": {
          "type": "object",
          "properties": {
            "timezone": {
              "type": "string"
            }
          },
          "required": ["timezone"]
        }
      }
    ],
    "tool_choice": {
      "type": "any"
    },
    "messages": [
      {
        "role": "user",
        "content": "Use the get_time tool for Asia/Shanghai. Do not answer directly."
      }
    ]
  }'
当前生产验证返回的关键字段:
{
  "stop_reason": "tool_use",
  "content": [
    {
      "type": "tool_use",
      "name": "get_time",
      "input": {
        "timezone": "Asia/Shanghai"
      }
    }
  ]
}

Extended Thinking

本轮生产复核中,明确返回 thinking block 的组合是:
  • claude-opus-4-6-thinking
基础版 claude-opus-4-6 本轮没有拿到同等明确的 thinking block,因此这里优先写 thinking 变体。
cURL
curl https://crazyrouter.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-opus-4-6-thinking",
    "max_tokens": 320,
    "thinking": {
      "type": "enabled",
      "budget_tokens": 128
    },
    "messages": [
      {
        "role": "user",
        "content": "Which is larger, 9.11 or 9.9? Explain briefly."
      }
    ]
  }'
当前生产验证返回的关键字段:
{
  "content": [
    {
      "type": "thinking",
      "thinking": "..."
    },
    {
      "type": "text",
      "text": "..."
    }
  ]
}
使用 thinking 时,max_tokens 必须大于 budget_tokens。思考 Token 也计入成本。

当前建议

  • 普通文本对话:优先用 claude-sonnet-4-6
  • 工具调用:优先用 claude-sonnet-4-6,并在首轮验证里加 tool_choice
  • 明确需要 thinking block:优先用 claude-opus-4-6-thinking
相关页面: