跳转到内容
免费注册
模型调用

Base URL 怎么填?

说明 Claude Code、Codex、Cursor、Cline 等工具中 Base URL、/v1 路径、API Key 和 Model ID 的匹配方式。

简短答案

Base URL 要跟工具协议匹配。Claude Code 通常使用 Anthropic-compatible 根地址;Codex、Cursor、Cline、OpenCode、OpenClaw 等外部工具通常使用 OpenAI-compatible /v1 地址。

在 BetterToken 中:

使用场景Base URL
Claude Code / Anthropic-compatiblehttps://bettertoken.ai
Codex / OpenAI-compatiblehttps://bettertoken.ai/v1
Cursor、Cline、OpenCode、OpenClawhttps://bettertoken.ai/v1

Claude Code 使用 https://bettertoken.ai,Codex CLI 和 OpenAI-compatible 工具使用 https://bettertoken.ai/v1。按客户端使用的协议填写对应地址。

为什么会有不同 Base URL

不同 SDK 对路径拼接方式不同。

协议或工具类型常见行为
OpenAI-compatible SDK通常基于 /v1 访问 chat completions、responses 等资源
Anthropic-compatible SDK通常由 SDK 拼接消息接口路径,不应重复添加 /v1
工具内置 provider可能自动补路径,也可能要求你填写完整 Base URL

Claude Code 使用 https://bettertoken.ai,Codex CLI 和 OpenAI-compatible 工具使用 https://bettertoken.ai/v1。按客户端使用的协议填写对应地址。

推荐速查

工具推荐配置
Claude Codehttps://bettertoken.ai,使用 BetterToken API Key
Claude Desktop Gateway按 Gateway 页面说明填写,注意 auth scheme
Codex CLIhttps://bettertoken.ai/v1,使用 BetterToken API Key
Cursorhttps://bettertoken.ai/v1,使用 BetterToken API Key
Clinehttps://bettertoken.ai/v1,选择 OpenAI Compatible provider
OpenCode / OpenClawhttps://bettertoken.ai/v1,使用 BetterToken API Key

常见错误

报错或现象可能原因
404 Not FoundBase URL 路径和 SDK 期望不一致
model not found核对模型广场中的准确 Model ID,并填入客户端的模型设置。
invalid_api_keyAPI Key 和 Base URL 不属于同一服务
认证通过但模型不可用核对模型广场中的准确 Model ID,并填入客户端的模型设置。
请求一直失败把 Anthropic-compatible 地址填进 OpenAI-compatible 工具,或反过来

推荐排查顺序

  1. 先确认工具要求 OpenAI-compatible 还是 Anthropic-compatible。
  2. 检查 Base URL 是否和工具协议匹配。
  3. 检查 API Key 是否来自同一个服务。
  4. 从模型广场复制准确的 Model ID。
  5. 发送一个最小请求测试,例如只问一句 hello。

代码示例

OpenAI-compatible 工具通常使用 /v1 地址:

from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://bettertoken.ai/v1"
)
response = client.chat.completions.create(
model="your-model-id",
messages=[{"role": "user", "content": "hello"}]
)

Claude / Anthropic-compatible 场景通常使用根地址:

import anthropic
client = anthropic.Anthropic(
api_key="YOUR_API_KEY",
base_url="https://bettertoken.ai"
)
message = client.messages.create(
model="your-model-id",
max_tokens=1024,
messages=[{"role": "user", "content": "hello"}]
)

关于 BetterToken

BetterToken 同时提供 Anthropic-compatible 和 OpenAI-compatible 的接入方式。你可以在同一个 dashboard 管理 API Key、余额和用量记录,但每个客户端仍然要填写它实际支持的协议地址。

简单记法:Claude Code 看 https://bettertoken.ai;Codex、Cursor、Cline、OpenCode、OpenClaw 看 https://bettertoken.ai/v1。