跳转到主要内容

Claude OpenAI 兼容格式

POST /v1/chat/completions
截至 2026 年 3 月 23 日,Crazyrouter 生产环境已验证:
  • claude-sonnet-4-6 非流式请求返回 object: "chat.completion"
  • message 当前稳定包含 rolecontent
  • 流式请求返回 chat.completion.chunk
  • SSE 仍以 data: [DONE] 结束

非流式请求

curl https://crazyrouter.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Compare PostgreSQL and MySQL in one paragraph."}
    ],
    "max_tokens": 256,
    "temperature": 0.2
  }'
关键响应形态:
{
  "object": "chat.completion",
  "model": "claude-sonnet-4-6",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "PostgreSQL and MySQL are both popular..."
      }
    }
  ]
}

流式请求

curl https://crazyrouter.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [
      {"role": "user", "content": "Say hello in one sentence."}
    ],
    "max_tokens": 128,
    "stream": true
  }'
2026-03-23 的生产环境流式探针里,开头片段如下:
data: {"object":"chat.completion.chunk","model":"claude-sonnet-4-6","choices":[{"delta":{"role":"assistant"}}]}
data: {"object":"chat.completion.chunk","model":"claude-sonnet-4-6","choices":[{"delta":{"content":"Hello! ..."}}]}
data: [DONE]
如果你需要 Claude 原生的 thinking、原生工具块或文档输入,优先使用 Claude Messages