Skip to content

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 $body

max_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 $body

Chat 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 错误码速查

状态码含义常见原因处理方式
401UnauthorizedAPI Key 缺失、错误或已禁用检查 Key 是否完整、是否以 sk- 开头,或在密钥页面重新创建
402Payment Required余额不足(仅付费模型)充值后再试,或切换到免费模型
403Forbidden无权访问该模型或分组检查 API Key 绑定的分组是否正确,或联系客服
404Not FoundBase URL 或模型名称错误检查是否多加了 /v1、模型名是否拼写正确
429Too Many Requests请求频率或并发超限降低请求速率,或在代码中添加请求间隔
500Internal Server Error服务器内部错误稍后重试,持续存在请联系客服
502Bad Gateway上游服务异常等待 1~5 分钟后重试,持续存在则联系客服
503Service Unavailable上游服务维护中稍后重试,或切换到其他可用模型

各客户端填写规则速查表

客户端协议填写的 Base URL
Claude CodeAnthropichttps://fast.drivecode.top
Codex CLIOpenAI Responseshttps://fast.drivecode.top/v1
CursorOpenAI 兼容https://fast.drivecode.top/v1
Cherry Studio(OpenAI 模式)OpenAIhttps://fast.drivecode.top/v1
Cherry Studio(Anthropic 模式)Anthropichttps://fast.drivecode.top
LobeChatOpenAIhttps://fast.drivecode.top/v1
ChatBoxOpenAIhttps://fast.drivecode.top/v1
NextChatOpenAIhttps://fast.drivecode.top/v1
Open WebUIOpenAIhttps://fast.drivecode.top/v1
Python openai SDKOpenAIhttps://fast.drivecode.top/v1
Python anthropic SDKAnthropichttps://fast.drivecode.top
Node.js openai SDKOpenAIhttps://fast.drivecode.top/v1

协议不能混用

OpenAI Base URL 填入 Claude 客户端(或反过来)会导致认证失败或路径错误。 请根据你使用的客户端选择对应协议的 Base URL。

官方参考

本文档仅供 Drivecode API 用户参考,不代表任何 AI 模型服务商官方立场。