XRouter API Key 通常以 sk- 开头。不同接口格式使用的认证头不同,但都使用同一把 XRouter API Key。
不要把真实 API Key 写入客户端前端代码、公开仓库、Issue、截图或聊天记录中。
OpenAI 兼容接口
OpenAI 兼容接口使用 Bearer token。
Authorization: Bearer sk-your-api-key
示例:
curl "https://api.xrouter.dev/v1/models" \
-H "Authorization: Bearer sk-your-api-key"
适用端点包括:
/v1/models
/v1/chat/completions
/v1/responses
Anthropic Messages 接口
Anthropic Messages 格式通常使用 x-api-key,并带上 anthropic-version。
x-api-key: sk-your-api-key
anthropic-version: 2023-06-01
示例:
curl "https://api.xrouter.dev/v1/messages" \
-H "x-api-key: sk-your-api-key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "your-claude-model-id",
"max_tokens": 256,
"messages": [
{ "role": "user", "content": "Hello" }
]
}'
XRouter 也兼容 Bearer token:
Authorization: Bearer sk-your-api-key
Gemini 兼容接口
Gemini 兼容接口推荐使用 x-goog-api-key。
x-goog-api-key: sk-your-api-key
示例:
curl "https://api.xrouter.dev/v1beta/models/your-gemini-model-id:generateContent" \
-H "x-goog-api-key: sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"parts": [
{ "text": "Hello" }
]
}
]
}'
部分客户端只支持 key 查询参数,XRouter 也兼容:
https://api.xrouter.dev/v1beta/models/your-gemini-model-id:generateContent?key=sk-your-api-key
优先使用请求头。查询参数可能被浏览器历史、代理日志或应用日志记录。
模型列表的返回格式
/v1/models 会根据请求头判断返回格式:
| 请求头 | 返回格式 |
|---|
Authorization: Bearer ... | OpenAI 模型列表 |
x-api-key + anthropic-version | Anthropic 模型列表 |
x-goog-api-key 或 key 查询参数 | Gemini 模型列表 |