跳转到主要内容
厂商: Anthropic Model ID: claude-sonnet-4-5 能力: 200K context · tool use · vision · prompt caching · streaming 价格: 按 token,Sonnet 档(实时价格 Sonnet 4.5 是 4 系列的主力。如果你的 prompt 能塞进 200K token、想要原 生工具调用、宁愿把钱花在多发几次而不是等一次 Opus 往返,这就是默认。 对多数生产 agent 流,把 Opus 4.7 换成 Sonnet 4.5 是约 3 倍的成本下降, 质量降幅比价格差小得多 —— 在认定要 Opus 之前先两个都跑一跑测一测。

请求

curl https://llm.bytespike.ai/v1/messages \
  -H "x-api-key: $BYTESPIKE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 4096,
    "messages": [
      {"role": "user", "content": "Refactor this Python function for readability."}
    ]
  }'

Body 参数

字段类型是否必填默认说明
modelstringclaude-sonnet-4-5
messagesarray对话历史。
max_tokensinteger硬上限。本模型最大:16384。
systemstring | arrayarray 形式支持 cache_control
temperaturenumber1.0范围 0.0–1.0。
top_pnumber1.0Nucleus sampling。
toolsarray支持,包括并行工具调用。
tool_choiceobject{"type":"auto"}auto / any / tool(指定名)。
streambooleanfalseSSE 流式。

响应

{
  "id": "msg_sonnet_…",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4-5",
  "content": [
    {"type": "text", "text": "Here's the refactor..."}
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 142,
    "output_tokens": 318
  }
}

代码示例

curl https://llm.bytespike.ai/v1/messages \
  -H "x-api-key: $BYTESPIKE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 4096,
    "messages": [{"role": "user", "content": "Refactor this Python function for readability."}]
  }'

流式

"stream": true 走标准 Anthropic 格式 SSE。估算 credits 在第一个事件 之前的 HTTP 头里给出。

Cache control

cache_control 块在 Sonnet 上大约 3 次重复调用同一个 system prompt 就 能回本。命中按 pricing table 中的折 扣价计费。
{
  "model": "claude-sonnet-4-5",
  "system": [
    {
      "type": "text",
      "text": "<long static system prompt>",
      "cache_control": {"type": "ephemeral"}
    }
  ],
  "messages": [...]
}

错误

Code触发是否计费
400Body 校验失败
401key 缺失 / 已撤销
402钱包用尽
403范围拒绝 / IP 未在白名单
429速率限制
5xx上游 provider 问题否(自动重试信封)

何时使用

  • 一发即中的质量重要、能等 1–2 秒的生产 agent loop。
  • Haiku 开始漏步骤的代码评审 / 重构 / 结构化输出。
  • 要更高吞吐、可降质量的,见 Haiku 4.5
  • 长上下文深度推理,见 Opus 4.7
  • 较新的 Sonnet 4.6 是现在推荐的 Sonnet —— 只在已经针对 4.5 跑过基准、确认旧版更适合时才留着 4.5。

限制

限制
Context window200K tokens
Max output16384 tokens
支持 tool use是(并行)
支持 vision
支持 streaming
支持 prompt caching