Claude Messages API
Claude Messages API 兼容 Anthropic 官方 Messages 请求结构,适合迁移 Claude 风格对话应用。Endpoint
POST /v1/messages
鉴权
x-api-key: <YOUR_API_KEY>
同时需要版本请求头:
anthropic-version: 2023-06-01
参数说明
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | Claude 模型名称。 |
max_tokens | integer | 是 | 最大输出 token 数。 |
messages | array | 是 | 消息数组,元素包含 role 与 content。 |
messages[].content | string 或 array | 是 | 消息内容,可传字符串或 Claude content block 数组。 |
system | string 或 array | 否 | 系统提示词。 |
temperature | number | 否 | 采样温度。 |
top_p | number | 否 | nucleus sampling 参数。 |
stop_sequences | string[] | 否 | 停止序列。 |
stream | boolean | 否 | 是否启用 SSE 流式返回。 |
tools | array | 否 | 工具定义。 |
响应说明
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 消息 ID。 |
type | string | 响应类型。 |
role | string | 通常为 assistant。 |
model | string | 实际使用的模型。 |
content[] | array | 输出内容块。 |
content[].text | string | 输出文本。 |
stop_reason | string 或 null | 停止原因。 |
usage.input_tokens | integer | 输入 token 数。 |
usage.output_tokens | integer | 输出 token 数。 |