协议接口
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。
Anthropic 请求不自动转 OpenAI
Anthropic Messages 会选择当前协议下开放的模型商品和上游候选。OpenAI Chat 列表里的同名模型,不自动代表 Anthropic Messages 可用;必须在 Anthropic Messages 协议下也开放。
最后更新于