Anthropic Messages
Anthropic Messages 接口。
Anthropic 使用 x-api-key
Claude Code 或 Anthropic-compatible 工具应该走 Messages 入口,并把顶级AI用户 API Key 填到 x-api-key。只传 Bearer 不会通过 Anthropic 鉴权。
路径
| 用途 | 方法与路径 |
|---|---|
| 模型调用 | POST /v1/messages |
| 兼容路径 | POST /anthropic/v1/messages |
| 模型列表 | GET /anthropic/v1/models 或 GET /anthropic/v1/models/ |
请求示例
curl https://dingjiai.com/v1/messages \
-H "x-api-key: YOUR_USER_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "从 Anthropic 模型列表复制的模型名",
"max_tokens": 256,
"messages": [
{ "role": "user", "content": "用一句话介绍你自己" }
]
}'流式请求
curl -N https://dingjiai.com/v1/messages \
-H "x-api-key: YOUR_USER_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "从 Anthropic 模型列表复制的模型名",
"max_tokens": 256,
"stream": true,
"messages": [
{ "role": "user", "content": "分三点说明接入流程" }
]
}'Header 与版本
Prop
Type
usage 与计费
结算读取 usage.input_tokens、usage.output_tokens,以及可选的 usage.cache_creation_input_tokens 和 usage.cache_read_input_tokens。
真实 usage 始终优先。按 token 计费的合法 JSON 对象,或已经交付至少一个上游/model chunk 的 stream,在 usage 缺失或无效时,可能按可见文本、thinking、tool_use.input 等已生成输出使用保守下界估算;合法已交付 envelope/上游 chunk 没有可提取输出时最少按 1 个 output token。真正空白/畸形 non-stream body 会对客失败并零扣费;上游/model 零 chunk 流已经提交 2xx,body 可能为空或只含网关 SSE keepalive,不能改写成错误体,网关会记录失败、释放预留并零扣费。已交付内容后断流或客户端取消,仍按 partial usage 或已交付输出下限结算。
Anthropic 请求不自动转 OpenAI
Anthropic Messages 会选择当前 Anthropic 调用入口下开放的模型商品和上游候选。OpenAI Chat 列表里的同名模型,不自动代表 Anthropic Messages 可用;必须在 Anthropic Messages 调用入口下也开放。
最后更新于