深色模式
API 地址与协议说明
基本概念
- Base URL — API 请求的基础服务器地址,不同协议使用不同的地址
- API Key — 身份凭证,格式
sk-xxxxxxxxxxxxxxxx,每次请求必须携带 - 模型名称 (Model ID) — 指定使用哪个 AI 模型,必须是后台实际开放的模型 ID
- 渠道 (Channel) — 模型的来源分组,标注该模型由哪个上游渠道提供
Claude / Anthropic 兼容协议
适用于直接调用 Claude SDK、Claude Code 等 Anthropic 原生工具。
Base URL: https://fast.drivecode.top不要在末尾加 /v1
Anthropic SDK 会自动追加 /v1/messages 等路径。 写成 https://fast.drivecode.top/v1 会导致 https://fast.drivecode.top/v1/v1/messages 报 404。
powershell
$env:DRIVECODE_API_KEY = "sk-xxxxxxxxxxxxxxxx"
$body = @{
model = "<MODEL_ID>"
max_tokens = 1024
messages = @(
@{ role = "user"; content = "Hello" }
)
} | ConvertTo-Json -Depth 10 -Compress
curl.exe https://fast.drivecode.top/v1/messages `
-H "x-api-key: $env:DRIVECODE_API_KEY" `
-H "anthropic-version: 2023-06-01" `
-H "Content-Type: application/json" `
-d $bodymax_tokens 与 API 版本头
max_tokens是 Anthropic Messages API 的必填输出上限,不是模型上下文长度,也不是协议版本。1024只是便于演示的上限,实际按业务需要调整。anthropic-version: 2023-06-01是 Anthropic 当前稳定 API schema 版本号,不是要求填写当前年份。截至 2026-07-24,Anthropic 官方 SDK 仍默认发送该值;不要自行改成2026-xx-xx。
OpenAI 兼容协议
OpenAI 兼容协议包含两个常用接口:
- Responses API:
/v1/responses,Codex CLI 必须使用此接口 - Chat Completions API:
/v1/chat/completions,常用于 Cherry Studio、Cursor、LobeChat 等兼容客户端
同一个模型是否同时支持两个接口,需要分别发送请求验证;/v1/models 列表本身通常不会标明接口兼容性。
Base URL: https://fast.drivecode.top/v1注意 /v1 的位置
OpenAI SDK 默认不会自动追加 /v1,所以 Base URL 必须包含 /v1。 不要写 https://fast.drivecode.top/v1/v1/...,也不要用 https://fast.drivecode.top(少 /v1)。
Responses API 示例
powershell
$env:DRIVECODE_API_KEY = "sk-xxxxxxxxxxxxxxxx"
$body = @{
model = "<MODEL_ID>"
input = "Hello"
} | ConvertTo-Json -Depth 10 -Compress
curl.exe https://fast.drivecode.top/v1/responses `
-H "Authorization: Bearer $env:DRIVECODE_API_KEY" `
-H "Content-Type: application/json" `
-d $bodyChat Completions API 示例
powershell
$env:DRIVECODE_API_KEY = "sk-xxxxxxxxxxxxxxxx"
$body = @{
model = "<MODEL_ID>"
messages = @(
@{ role = "user"; content = "Hello" }
)
} | ConvertTo-Json -Depth 10 -Compress
curl.exe https://fast.drivecode.top/v1/chat/completions `
-H "Authorization: Bearer $env:DRIVECODE_API_KEY" `
-H "Content-Type: application/json" `
-d $body查询当前可用模型
powershell
curl.exe https://fast.drivecode.top/v1/models `
-H "Authorization: Bearer $env:DRIVECODE_API_KEY"返回的 JSON 中每条 id 字段就是可用模型名称。
模型列表实时更新
新模型上线或旧模型下线时列表会动态变化,调用前建议先确认目标模型是否在列表中。
API 错误码速查
| 状态码 | 含义 | 常见原因 | 处理方式 |
|---|---|---|---|
| 401 | Unauthorized | API Key 缺失、错误或已禁用 | 检查 Key 是否完整、是否以 sk- 开头,或在密钥页面重新创建 |
| 402 | Payment Required | 余额不足(仅付费模型) | 充值后再试,或切换到免费模型 |
| 403 | Forbidden | 无权访问该模型或分组 | 检查 API Key 绑定的分组是否正确,或联系客服 |
| 404 | Not Found | Base URL 或模型名称错误 | 检查是否多加了 /v1、模型名是否拼写正确 |
| 429 | Too Many Requests | 请求频率或并发超限 | 降低请求速率,或在代码中添加请求间隔 |
| 500 | Internal Server Error | 服务器内部错误 | 稍后重试,持续存在请联系客服 |
| 502 | Bad Gateway | 上游服务异常 | 等待 1~5 分钟后重试,持续存在则联系客服 |
| 503 | Service Unavailable | 上游服务维护中 | 稍后重试,或切换到其他可用模型 |
各客户端填写规则速查表
| 客户端 | 协议 | 填写的 Base URL |
|---|---|---|
| Claude Code | Anthropic | https://fast.drivecode.top |
| Codex CLI | OpenAI Responses | https://fast.drivecode.top/v1 |
| Cursor | OpenAI 兼容 | https://fast.drivecode.top/v1 |
| Cherry Studio(OpenAI 模式) | OpenAI | https://fast.drivecode.top/v1 |
| Cherry Studio(Anthropic 模式) | Anthropic | https://fast.drivecode.top |
| LobeChat | OpenAI | https://fast.drivecode.top/v1 |
| ChatBox | OpenAI | https://fast.drivecode.top/v1 |
| NextChat | OpenAI | https://fast.drivecode.top/v1 |
| Open WebUI | OpenAI | https://fast.drivecode.top/v1 |
Python openai SDK | OpenAI | https://fast.drivecode.top/v1 |
Python anthropic SDK | Anthropic | https://fast.drivecode.top |
Node.js openai SDK | OpenAI | https://fast.drivecode.top/v1 |
协议不能混用
OpenAI Base URL 填入 Claude 客户端(或反过来)会导致认证失败或路径错误。 请根据你使用的客户端选择对应协议的 Base URL。