Anthropic Message API (订阅号)

本页记录的是订阅号渠道实测的参数支持范围。使用订阅号渠道 API Key 授权调用的模型,请以本页标注的参数状态为准。

POST/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
x-api-key<token>

U-Token 通用币 API Key。

位置: header

请求头参数

参数名类型必填默认值描述
x-api-keystring必填–

U-Token 通用币 API Key。

参数名类型必填默认值描述
anthropic-versionstring可选–

推荐 2023-06-01。2026-08-25 U-Token 通用币 复测中省略该 Header 也成功;无效版本是否校验不能保证跨网关版本和账号一致。

参数名类型必填默认值描述
anthropic-betastring可选–

prompt-caching-2024-07-31 已验证。

参数名类型必填默认值描述
anthropic-user-profile-idstring可选–

2026-08-25 U-Token 通用币 复测接受该请求,但没有可观察证据证明 user profile 归因已生效;未得到账号确认前不要依赖。

请求体

application/json

TypeScript 类型定义

在 TypeScript 中使用 request body 类型。

参数名类型必填默认值描述
modelstring必填–

模型 ID,使用 GET /v1/models 返回的授权 ID。

max_tokensinteger必填–

最大输出 Token 数,必填,传入正整数。省略时本通道当前不报错,但生效的默认值不确定,且该行为不作保证。

messagesarray必填–

user / assistant 消息;文本、图片、搜索结果、工具调用和工具结果已验证。完整 document 处理需要使用真实有效 PDF 验证。

messages[].rolestring条件必填–

取值: "user" "assistant"

messages[].contentstring | array条件必填–
messages[].content[].typestring可选–

取值: "text" "image" "document" "search_result" "tool_use" "tool_result"

messages[].content[].textstring可选–
messages[].content[].sourceobject可选–
messages[].content[].namestring可选–
messages[].content[].inputobject可选–
systemstring | array可选–

顶层系统提示词,不要放进 messages。

system[].typestring可选–

取值: "text"

system[].textstring可选–
streamboolean可选false

是否返回 SSE 流式事件。2026-08-25 U-Token 通用币 复测中传入 true、false 和省略最终均成功,但非流式请求当日曾观测到 424 波动;稳定性以 stream: true 为准。

stop_sequencesarray可选–

自定义停止字符串数组。

thinkingobject可选–

扩展思考配置;enabled、disabled、adaptive 已验证。

thinking.typestring可选–

取值: "enabled" "disabled" "adaptive"

thinking.budget_tokensinteger可选–

type 为 enabled 时必填;最小值 1024(实测低于 1024 返回 400)。官方要求小于 max_tokens,本通道实测不强制校验:budget_tokens ≥ max_tokens 时仍返回 200,输出按 max_tokens 截断。

thinking.displaystring可选–

取值: "summarized" "omitted"

toolsarray可选–

客户端工具定义。strict schema 已验证;两轮 tool_result 语义闭环 Claude Opus 5 已验证,Claude Sonnet 5 存在返回 200 但未使用工具结果的已知问题(2026-08-18 实测)。

tools[].namestring条件必填–
tools[].descriptionstring可选–
tools[].input_schemaobject条件必填–

工具输入 JSON Schema。object schema 且 strict=true 时必须包含 additionalProperties=false。

tools[].strictboolean可选–
tool_choiceobject可选–

工具选择对象。字符串 auto 会被拒绝,请使用 {type: auto}、{type: any}、{type: tool, name: ...} 或 {type: none}。

tool_choice.typestring条件必填–

取值: "auto" "any" "tool" "none"

tool_choice.namestring可选–
tool_choice.disable_parallel_tool_useboolean可选–
cache_controlobject可选–

不是顶层参数,在顶层传入不会生效。cache_control 是打在需要缓存的块内部的标记,写进 messages[].content[] 块、system 块或 tools[] 条目里。提示词缓存在本通道可用:正确标记后,重复请求的响应会返回 cache_read_input_tokens。

cache_control.typestring可选–

取值: "ephemeral"

cache_control.ttlstring可选–

取值: "5m" "1h"

context_managementobject可选–

上下文管理;测试形状已验证。

metadataobject可选–

匿名请求元数据;user_id 已验证。

metadata.user_idstring可选–
output_configobject可选–

JSON Schema 结构化输出;使用 output_config.format。

output_config.formatobject可选–
output_config.format.typestring可选–

取值: "json_schema"

output_config.format.schemaobject可选–
service_tierstring可选–

服务等级;auto、standard_only 已验证。

取值: "auto" "standard_only"

speedstring可选–

不支持:standard 和 fast 返回 Extra inputs are not permitted。

diagnosticsobject可选–

不支持:返回 Extra inputs are not permitted。

fallbacksarray可选–

不支持:返回 Extra inputs are not permitted。

fallback_credit_tokenstring可选–

不支持:当前通道不接受。

mcp_serversarray可选–

不支持:返回 Extra inputs are not permitted。

inference_geostring可选–

账号受限:组织类型不支持。

output_formatobject可选–

已弃用:使用 output_config.format。

top_kinteger可选–

本通道下 Claude Opus 5 不支持:针对该模型,上游会以 deprecated 错误拒绝请求。该参数在 Anthropic 官方 API 中仍然有效——受限的是模型,不是协议。官方用途:每个 token 仅从概率最高的 K 个候选中采样。

top_pnumber可选–

本通道下 Claude Opus 5 不支持:针对该模型,上游会以 deprecated 错误拒绝请求。该参数在 Anthropic 官方 API 中仍然有效——受限的是模型,不是协议。官方用途:核采样,取值 0 到 1。

temperaturenumber可选–

本通道下该模型以 deprecated 拒绝此参数:temperature: 0 返回 400(message 为 temperature is deprecated for this model.),仅 1(即默认值)可通过。省略该字段时按模型默认值处理。

containerobject可选–

请求形状待确认:包含 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  }}