Configuration Guide配置指南
Use WoAiToken API Key
with Claude Code
在 Claude Code 中使用
WoAiToken API Key
Prerequisites前置条件
-
Claude Code installed — claude.ai/code
已安装 Claude Code — claude.ai/code -
A WoAiToken account with credits — to.woaitoken.com
已有 WoAiToken 账号并完成充值 — to.woaitoken.com -
Your sub2api API key (we’ll get it in Step 1)
您的 sub2api API Key(Step 1 中获取)
Get Your API Key获取 API Key
Log in to your WoAiToken sub2api account and generate an API key.
登录 WoAiToken sub2api 账号,生成一个 API Key。
1 · Open the console
1 · 打开控制台
Visit to.woaitoken.com/console and sign in.
访问 to.woaitoken.com/console 并登录。
2 · Create an API key
2 · 创建 API Key
Navigate to Account → API Keys. Click + New Key, give it a name (e.g. “Claude Code”), and copy the generated key — it starts with sk-.
进入 账号 → API 密钥,点击 + 新建密钥,输入名称(如”Claude Code”),复制生成的密钥 —— 以 sk- 开头。
[ Screenshot: sub2api API Keys page — new key button ]
[ 截图:sub2api API 密钥页面 — 新建密钥按钮 ]
Save your key now. sub2api only shows the full key once. If you lose it, delete and create a new one.
立即保存密钥。 sub2api 只会完整展示一次。如果丢失,请删除并重新创建。
Configure Claude Code配置 Claude Code
Claude Code reads two environment variables to connect to a custom API endpoint:
Claude Code 通过两个环境变量连接自定义 API 端点:
ENV
ANTHROPIC_BASE_URL = "https://to.woaitoken.com" ANTHROPIC_API_KEY = "sk-your-key-here"
Choose one of the three methods below. Method A is recommended for daily use.
以下三种方式任选其一。方式 A 是日常使用的推荐方案。
Method A — settings.json方式 A — settings.json
✦ Recommended✦ 推荐
Edit (or create) ~/.claude/settings.json. This file applies to all projects and all terminal sessions automatically.
编辑(或创建)~/.claude/settings.json,对所有项目、所有终端会话永久生效。
JSON
{
"env": {
"ANTHROPIC_BASE_URL": "https://to.woaitoken.com",
"ANTHROPIC_API_KEY": "sk-your-key-here"
}
}
Save the file, then run claude — no restart needed.
保存文件后直接运行 claude,无需重启终端。
Method B — Shell profile方式 B — Shell 配置文件
Persistent永久生效
Add the two lines below to your shell profile, then reload it.
在 Shell 配置文件末尾添加以下两行,然后重新加载。
BASH
export ANTHROPIC_BASE_URL="https://to.woaitoken.com" export ANTHROPIC_API_KEY="sk-your-key-here" # Reload (run once after saving) source ~/.zshrc
POWERSHELL
[Environment]::SetEnvironmentVariable( "ANTHROPIC_BASE_URL", "https://to.woaitoken.com", "User") [Environment]::SetEnvironmentVariable( "ANTHROPIC_API_KEY", "sk-your-key-here", "User")
On Windows, open a new terminal window after running these commands for the changes to take effect.
Windows 下需要重新打开终端窗口才能生效。
Method C — One-time (test only)方式 C — 临时生效(仅测试用)
Session only仅当次
Prefix the variables inline when launching Claude Code. Useful for a quick test before committing to a permanent config.
在启动命令前内联环境变量。适合在正式配置前快速测试。
BASH
ANTHROPIC_BASE_URL="https://to.woaitoken.com" \ ANTHROPIC_API_KEY="sk-your-key-here" \ claude
These variables are only active for the current terminal session. Use Method A or B for permanent setup.
这些变量仅在当前终端窗口有效。日常使用请选方式 A 或 B。
Verify the Connection验证连接
Run the health check运行健康检查
Open a terminal and run:
打开终端,执行:
claude doctor
Claude Code performs a full connectivity check. A green ✓ next to “API connectivity” means everything is working.
Claude Code 会进行完整的连接检查。”API connectivity” 旁出现绿色 ✓ 表示配置成功。
[ Screenshot: claude doctor — all checks passing ]
[ 截图:claude doctor 所有检查通过 ]
Alternatively, just run claude and send a short message like “hi”. A response means it’s working.
也可以直接运行 claude,发送一条”你好”测试响应。
Troubleshooting常见问题
401 Unauthorized / “API key invalid”
401 Unauthorized / “API key invalid”
sk- prefix) with no trailing spaces.检查 API Key 是否完整(含
sk- 前缀,无多余空格)。
Connection timeout / “Could not reach server”
连接超时 / “Could not reach server”
ANTHROPIC_BASE_URL is exactly https://to.woaitoken.com — no trailing slash, no /v1 suffix. Claude Code appends path segments automatically.确认
ANTHROPIC_BASE_URL 的值为 https://to.woaitoken.com,末尾无斜杠,无 /v1 后缀——Claude Code 会自动拼接路径。
429 Too Many Requests / quota error
429 Too Many Requests / 额度不足
账号额度已用尽,请前往 woaitoken.com 充值后重试。
settings.json not taking effect
settings.json 不生效
~/.claude/settings.json (not in a project subfolder). Check JSON syntax — a missing comma breaks the whole file.确认文件路径为
~/.claude/settings.json(不是项目子目录)。检查 JSON 语法,缺少逗号会导致整个文件失效。