/v1/chat/completions 接口。Bearer sk-xxxxxxxxxxclaude-opus-4-5-20251101 - Claude Opus 4.5(最新,最强推理能力)claude-haiku-4-5-20251001 - Claude Haiku 4.5(最新,速度最快)claude-sonnet-4-5-20250929 - Claude Sonnet 4.5(最新,平衡性能)claude-opus-4-1-20250805 - Claude Opus 4.1claude-sonnet-4-20250514 - Claude Sonnet 4role(user/assistant)和 content。content 可以是字符串或媒体内容数组。system 和 messages 中使用 cache_control 参数。
system 数组元素和 messages 的 content 数组元素。type: 缓存类型
"ephemeral": 5分钟缓存(默认,成本最优)"persistent": 1小时缓存(适用于长期稳定的上下文)cache_control 标记的内容块会被缓存ephemeral: 5分钟内有效persistent: 1小时内有效system 中,多次提问budget_tokens 必须大于 1024temperature: 1.0 和 top_p: 0stream: true)才能看到思考过程tool_choice 控制模型如何使用工具:
| 值 | 说明 |
|---|---|
{"type": "auto"} | 自动决定是否使用工具(默认) |
{"type": "any"} | 必须使用至少一个工具 |
{"type": "none"} | 不使用任何工具 |
{"type": "tool", "name": "tool_name"} | 必须使用指定的工具 |
ephemeral 缓存在 5分钟内有效persistent 缓存在 1小时内有效cache_control 的块会被缓存input_tokens: 当前请求的非缓存输入 tokenscache_creation_input_tokens: 首次缓存创建的 tokens(仅首次请求时有值)cache_read_input_tokens: 从缓存读取的 tokens(缓存命中时有值)output_tokens: 生成的输出 tokens| 错误类型 | HTTP 状态码 | 说明 |
|---|---|---|
invalid_request | 400 | 请求参数错误(如缺少必填字段) |
authentication_error | 401 | API 密钥无效或未授权 |
rate_limit_error | 429 | 请求频率超限 |
upstream_error | 500 | 上游服务错误 |
nebula_api_error | 500 | 系统内部错误 |
| 特性 | /v1/messages | /v1/chat/completions |
|---|---|---|
| 认证方式 | Authorization: Bearer | Authorization: Bearer |
| 响应格式 | Anthropic 原生格式 | OpenAI 兼容格式 |
| 扩展思考 | 原生支持 thinking 参数 | 通过 reasoning_effort 或 reasoning 参数 |
| 工具调用 | 原生 tools 和 tool_choice | OpenAI 兼容格式 |
| 适用客户端 | Anthropic SDK、Claude Code | OpenAI SDK、兼容客户端 |
max_tokens 是必填参数,必须大于 0messages 数组不能为空budget_tokens 必须大于 1024