cURL 使用指南
使用 cURL 命令行工具直接调用 ClawdRouter API。
基础请求
curl https://api.clawdrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "你好"}
]
}'
带系统提示词
curl https://api.clawdrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "你是一个专业的翻译助手,将中文翻译为英文"},
{"role": "user", "content": "今天天气真好"}
]
}'
流式输出
curl https://api.clawdrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-N \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "写一首关于春天的诗"}
],
"stream": true
}'
提示
-N 参数禁用 cURL 的输出缓冲,使流式响应可以实时显示。
调节参数
curl https://api.clawdrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "给我讲一个创意故事"}
],
"temperature": 1.5,
"max_tokens": 1000,
"top_p": 0.9
}'
使用不同厂商的模型
Anthropic (Claude)
curl https://api.clawdrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "claude-sonnet-4-6",
"messages": [
{"role": "user", "content": "解释一下相对论"}
]
}'
Google (Gemini)
curl https://api.clawdrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gemini-2.5-flash",
"messages": [
{"role": "user", "content": "介绍一下量子计算"}
],
"reasoning_effort": "low"
}'
携带 Request-Id
curl https://api.clawdrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Request-Id: my-request-12345" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "你好"}
]
}'
查看完整响应头
使用 -v 参数查看请求和响应的详细信息:
curl -v https://api.clawdrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "你好"}
]
}'
Anthropic 原生协议
以下示例使用 Anthropic 原生协议 (/v1/messages) 调用 Claude 模型。
认证方式不同
Anthropic 原生协议使用 x-api-key 请求头进行认证,而非 Authorization: Bearer。
基础请求
curl https://api.clawdrouter.com/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "你好"}
]
}'
带系统提示词
Anthropic 协议的系统提示词是独立的 system 参数,而非放在 messages 中:
curl https://api.clawdrouter.com/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"system": "你是一个专业的翻译助手,将中文翻译为英文",
"messages": [
{"role": "user", "content": "今天天气真好"}
]
}'
流式输出
curl https://api.clawdrouter.com/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-N \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"stream": true,
"messages": [
{"role": "user", "content": "写一首关于春天的诗"}
]
}'