Anthropic Message API (订阅号)
本页记录的是订阅号渠道实测的参数支持范围。使用订阅号渠道 API Key 授权调用的模型,请以本页标注的参数状态为准。
/messages通过 Anthropic Messages 原生协议调用 Claude。参数状态来自官方文档和 U-Token 通用币/RelayPool 实测。
当前通道明确不支持的官方参数:speed、diagnostics、fallbacks、fallback_credit_token、mcp_servers、top_k、top_p。受限参数:temperature(仅 1 可通过)、inference_geo(组织类型受限);output_format 已弃用(改用 output_config.format);cache_control 不是顶层参数(写入 messages[].content[]、system 或 tools[] 块内)。具体拒绝方式见下方参数表各项说明。
鉴权
apiKey U-Token 通用币 API Key。
位置: header
请求头参数
| 参数名 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
x-api-key | string | 必填 | – | U-Token 通用币 API Key。 |
| 参数名 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
anthropic-version | string | 可选 | – | 推荐 2023-06-01。2026-08-25 U-Token 通用币 复测中省略该 Header 也成功;无效版本是否校验不能保证跨网关版本和账号一致。 |
| 参数名 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
anthropic-beta | string | 可选 | – | prompt-caching-2024-07-31 已验证。 |
| 参数名 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
anthropic-user-profile-id | string | 可选 | – | 2026-08-25 U-Token 通用币 复测接受该请求,但没有可观察证据证明 user profile 归因已生效;未得到账号确认前不要依赖。 |
请求体
application/json
TypeScript 类型定义
在 TypeScript 中使用 request body 类型。
| 参数名 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
model | string | 必填 | – | 模型 ID,使用 GET /v1/models 返回的授权 ID。 |
max_ | integer | 必填 | – | 最大输出 Token 数,必填,传入正整数。省略时本通道当前不报错,但生效的默认值不确定,且该行为不作保证。 |
messages | array | 必填 | – | user / assistant 消息;文本、图片、搜索结果、工具调用和工具结果已验证。完整 document 处理需要使用真实有效 PDF 验证。 |
messages[] | string | 条件必填 | – | 取值: |
messages[] | string | array | 条件必填 | – | |
messages[] | string | 可选 | – | 取值: |
messages[] | string | 可选 | – | |
messages[] | object | 可选 | – | |
messages[] | string | 可选 | – | |
messages[] | object | 可选 | – | |
system | string | array | 可选 | – | 顶层系统提示词,不要放进 messages。 |
system[] | string | 可选 | – | 取值: |
system[] | string | 可选 | – | |
stream | boolean | 可选 | false | 是否返回 SSE 流式事件。2026-08-25 U-Token 通用币 复测中传入 true、false 和省略最终均成功,但非流式请求当日曾观测到 |
stop_ | array | 可选 | – | 自定义停止字符串数组。 |
thinking | object | 可选 | – | 扩展思考配置;enabled、disabled、adaptive 已验证。 |
thinking. | string | 可选 | – | 取值: |
thinking. | integer | 可选 | – | type 为 enabled 时必填;最小值 1024(实测低于 1024 返回 400)。官方要求小于 max_tokens,本通道实测不强制校验:budget_tokens ≥ max_tokens 时仍返回 200,输出按 max_tokens 截断。 |
thinking. | string | 可选 | – | 取值: |
tools | array | 可选 | – | 客户端工具定义。strict schema 已验证;两轮 tool_result 语义闭环 Claude Opus 5 已验证,Claude Sonnet 5 存在返回 200 但未使用工具结果的已知问题(2026-08-18 实测)。 |
tools[] | string | 条件必填 | – | |
tools[] | string | 可选 | – | |
tools[] | object | 条件必填 | – | 工具输入 JSON Schema。object schema 且 strict=true 时必须包含 additionalProperties=false。 |
tools[] | boolean | 可选 | – | |
tool_ | object | 可选 | – | 工具选择对象。字符串 auto 会被拒绝,请使用 {type: auto}、{type: any}、{type: tool, name: ...} 或 {type: none}。 |
tool_ | string | 条件必填 | – | 取值: |
tool_ | string | 可选 | – | |
tool_ | boolean | 可选 | – | |
cache_ | object | 可选 | – | 不是顶层参数,在顶层传入不会生效。 |
cache_ | string | 可选 | – | 取值: |
cache_ | string | 可选 | – | 取值: |
context_ | object | 可选 | – | 上下文管理;测试形状已验证。 |
metadata | object | 可选 | – | 匿名请求元数据;user_id 已验证。 |
metadata. | string | 可选 | – | |
output_ | object | 可选 | – | JSON Schema 结构化输出;使用 output_config.format。 |
output_ | object | 可选 | – | |
output_ | string | 可选 | – | 取值: |
output_ | object | 可选 | – | |
service_ | string | 可选 | – | 服务等级;auto、standard_only 已验证。 取值: |
speed | string | 可选 | – | 不支持:standard 和 fast 返回 Extra inputs are not permitted。 |
diagnostics | object | 可选 | – | 不支持:返回 Extra inputs are not permitted。 |
fallbacks | array | 可选 | – | 不支持:返回 Extra inputs are not permitted。 |
fallback_ | string | 可选 | – | 不支持:当前通道不接受。 |
mcp_ | array | 可选 | – | 不支持:返回 Extra inputs are not permitted。 |
inference_ | string | 可选 | – | 账号受限:组织类型不支持。 |
output_ | object | 可选 | – | 已弃用:使用 output_config.format。 |
top_ | integer | 可选 | – | 本通道下 Claude Opus 5 不支持:针对该模型,上游会以 |
top_ | number | 可选 | – | 本通道下 Claude Opus 5 不支持:针对该模型,上游会以 |
temperature | number | 可选 | – | 本通道下该模型以 deprecated 拒绝此参数: |
container | object | 可选 | – | 请求形状待确认:包含 expires_at 的测试请求被拒绝,不能证明所有形状均不可用。 |
响应体
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/messages" \ -H "x-api-key: sk-你的KEY" \ -H "anthropic-version: 2023-06-01" \ -H "anthropic-beta: prompt-caching-2024-07-31" \ -H "anthropic-user-profile-id: usr_example" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-opus-5", "max_tokens": 256, "stream": true, "messages": [ { "role": "user", "content": "Go 快速排序一般为什么比较快" } ] }'{ "id": "string", "type": "message", "role": "assistant", "model": "string", "content": [ { "type": "string", "text": "string", "thinking": "string", "signature": "string", "id": "string", "name": "string", "input": {} } ], "stop_reason": "string", "stop_sequence": "string", "usage": { "input_tokens": 0, "output_tokens": 0, "cache_creation_input_tokens": 0, "cache_creation": { "ephemeral_1h_input_tokens": 0 }, "cache_read_input_tokens": 0 }}