原生 Claude 格式
Anthropic Claude Messages API 格式的请求。
需要在请求头中包含 anthropic-version。
接口描述
POST /v1/messages
Headers:
anthropic-version: (必填) 2023-06-01 (或其他版本号)
x-api-key: your-api-key
Authorization: Bearer <token>
Content-Type: application/json
Body:
┣━ model string (必填) 模型 ID (例如: claude-3-opus-20240229)
┣━ messages array[object] (必填) 对话消息列表
┃ ┣━ role enum
┃ ┣━ content string (必填) 消息内容
┣━ system string|array[object] (可选) 系统提示词,用于指定模型行为
┣━ max_tokens integer (必填) 最大生成的 Token 数量
┣━ temperature number (可选) 采样温度,介于 0 到 1 之间
┣━ top_p number (可选) 核采样概率阈值
┣━ top_k integer (可选) 采样时保留的 top-K 个候选 Token
┣━ stream boolean (可选) 是否流式传输响应
┣━ stop_sequences array[string] (可选) 停止序列,模型遇到这些字符串将停止生成
┣━ tools array[object] (可选) 模型可以调用的工具列表
┃ ┣━ name string 工具名称
┃ ┣━ description string 工具的功能描述
┃ ┣━ input_schema object 遵循 JSON Schema 格式的参数定义
┣━ tool_choice object (可选) 控制模型如何调用工具
┃ ┣━ type enum
┃ ┣━ name string (可选) 当 type 为 tool 时指定的具体工具名称
┣━ thinking object (可选) 扩展推理(思维链)配置
┃ ┣━ type enum
┃ ┣━ budget_tokens integer 推理过程允许消耗的 Token 预算
┣━ metadata object (可选) 元数据对象
┃ ┣━ user_id string 终端用户的唯一标识符
Response 200
┣━ id string 消息的唯一标识符
┣━ type string 对象类型,固定为 message
┣━ role enum
┣━ content array[object] 消息内容块列表
┃ ┣━ type string 内容块类型 (例如: text, tool_use, thinking)
┃ ┣━ text string 文本内容
┣━ model string 使用的模型名称
┣━ stop_reason enum
┃ 枚举值: end_turn, max_tokens, stop_sequence, tool_use
┣━ usage object Token 使用情况统计
┃ ┣━ input_tokens integer 输入(提示)消耗的 Token 数量
┃ ┣━ output_tokens integer 输出(回复)消耗的 Token 数量
┃ ┣━ cache_creation_input_tokens integer (可选) 写入缓存的 Token 数量
┃ ┣━ cache_read_input_tokens integer (可选) 从缓存读取的 Token 数量