{
"type": "message",
"id": "msg_example",
"role": "assistant",
"stop_reason": "end_turn",
"content": [
{
"type": "text",
"text": "Hello."
}
]
}{}API 参考
Claude Messages
创建 Claude 原生消息,保留内容块与结束原因。
{
"type": "message",
"id": "msg_example",
"role": "assistant",
"stop_reason": "end_turn",
"content": [
{
"type": "text",
"text": "Hello."
}
]
}{}POST /v1/messages
使用 x-api-key 发送网关令牌,显式设置 anthropic-version。原生请求包含 model、messages;本例显式提供 max_tokens,系统指令放在顶层 system。参数表保留网关允许缺省预算的行为,实际原生供应商请求仍应提供模型支持的预算。
非流式响应读取 content[] 并检查 stop_reason。end_turn 之外的状态需要相应处理;tool_use 不是最终文本,max_tokens 可能截断。设置 stream: true 时按 Claude SSE 读取,不能套用 Chat / Responses 事件解析。
原生 Claude 指南与完整 TypeScript 示例包含环境变量、执行命令及失败行为。本站只展开常用文本字段,不承诺所有原生扩展或转换路径可用。/v1/messages/count_tokens 尚未启用。
核对版本:d851a5faa49a00abaafd27bf91b311506fbfbc52. 源文件记录在此操作的 x-source-files。
原生 SSE 与工具闭环的 Python 示例提供纯文本和工具两种模式,保留原生结果关联与签名。
Read in English
原生缓存与推理控制
请求级与内容块的cache_control、顶层 thinking、output_config 和 context_management 已在项目 DTO 中表达,实际支持、TTL、预算和模式取决于渠道及模型。context_management 是 Claude 专用对象,转换成 Responses 时不会直接复制;同名字段不代表跨协议等价。
原生缓存用量可能包含 usage.cache_read_input_tokens 与 cache_creation_input_tokens。缓存、推理和压缩状态都不能自动增加模型上下文窗口;thinking / signature / redacted_thinking 等续聊项按原生协议完整保留。
新增字段核对版本:30a6d88a4。
提示词缓存 · 推理模型 · 上下文管理授权
ClaudeApiKeyBearerAuth
网关令牌 / Gateway token
请求头
适配器缺省版本;建议显式发送 / Adapter fallback version; send explicitly.
请求体
application/json
Minimum string length:
1示例:
"YOUR_MODEL_ID"
Minimum array length:
1Show child attributes
Show child attributes
输出预算,实际范围依赖模型;调用原生供应商时应显式设置 / Output budget; model limits apply. Set explicitly for native provider requests.
必填范围:
0 <= x <= 1073741823示例:
256
Show child attributes
Show child attributes
原生缓存控制;依赖渠道,TTL 与断点限制不能跨供应商假定一致 / Native cache control; channel dependent, TTL and breakpoint limits vary
示例:
{ "type": "ephemeral" }
原生推理配置;模式与预算由目标模型决定 / Native reasoning configuration; target model determines modes and budgets
原生输出配置,包含条件支持的 effort / Native output configuration, including conditional effort support
Claude 专用上下文编辑对象;Claude 转 Responses 不直接复制 / Claude-specific context editing; not copied directly into Responses