Claude Code
Connect Claude Code to TodAPI
Claude Code talks to an Anthropic-compatible gateway through two environment variables. On TodAPI the base URL is the site root — not the OpenAI-compatible /v1 path. This page only describes what the public guide already documents, plus the mistakes that usually break the first session.
Create an account if you do not have one yet, then top up — you must top up before the first API call; signing up does not include free usage. Create or configure a key when you are ready. The general OpenAI path is in the integration guide.
Before you set any variables
- Open API keys and create a key.
- Assign that key to an Anthropic group. The guide states that a key from the wrong group will fail when you call a model that group does not serve.
- Open the model plaza (no trailing slash), find that group, and copy the model ID exactly. Do not type a Claude marketing name from memory.
The two values Claude Code needs
| Variable | Value on TodAPI | Why |
|---|---|---|
ANTHROPIC_BASE_URL | https://todapi.work | Claude Code appends /v1/messages itself. If you add /v1 here, the request becomes /v1/v1/messages and fails. |
ANTHROPIC_AUTH_TOKEN | your sk-… key | Sent as Authorization: Bearer. This is the form the public guide uses. |
ANTHROPIC_MODEL (optional, useful) | the plaza model ID | Stops Claude Code from calling a default id that is not in your group. |
This is different from OpenAI-compatible clients, which must use https://todapi.work/v1. One key can be used for both protocols only if its group actually serves the models you call.
Shell (try this first)
export ANTHROPIC_BASE_URL="https://todapi.work"
export ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxx"
export ANTHROPIC_MODEL="your-plaza-model-id"
claude
Exports last only for that terminal. An editor started from a dock or Start menu will not see them. If the session looks right, move the same values into a settings file.
Persistent settings.json
User-level file: ~/.claude/settings.json (Windows: %USERPROFILE%\.claude\settings.json). Do not put the key in a project .claude/settings.json that may be committed.
{
"env": {
"ANTHROPIC_BASE_URL": "https://todapi.work",
"ANTHROPIC_AUTH_TOKEN": "sk-xxxxxxxx",
"ANTHROPIC_MODEL": "your-plaza-model-id"
}
}
If a shell export and the settings file both set the same variable, Claude Code’s current documentation says the settings file wins. Check with /status.
How to tell it worked
- You can also list models first with a regular request:
curl https://todapi.work/v1/models -H "Authorization: Bearer sk-xxxxxxxx". A list means the key and group already match. This uses the OpenAI-compatible path and does not replace a Claude Code session test. - In Claude Code, run
/status. You want an Anthropic base URL ofhttps://todapi.workand an auth line that namesANTHROPIC_AUTH_TOKEN. - Send a short prompt. A normal reply is the real check. If it fails, read the status code against the guide’s error table (401 key, 403 group mismatch, model 404, 429 rate or balance, 5xx upstream).
Usual failure points
| What happens | Likely cause |
|---|---|
| 404 on the first message | Base URL includes /v1, or the model ID is not in that group. |
| 401 | Wrong or truncated key, or ANTHROPIC_API_KEY was set instead of ANTHROPIC_AUTH_TOKEN when the gateway expects a Bearer token. |
| 403 or “model not found” | The key’s group is not the Anthropic group (or does not include that model). Switch group, or copy the ID again from the plaza. |
| Claude Code still uses a claude.ai login | The environment did not reach the process. Prefer settings.json, then open a new session and re-check /status. |
Price and terms, before you send paid traffic
- Rates, including cache and peak windows, are on the model plaza, not on this page.
- Accounts are prepaid in USD, and credit does not expire. You must top up before the first API call; signing up does not include free usage. Confirmed payment methods: WeChat Pay / Alipay for Asia-Pacific users, bank cards for users worldwide, and Web3 USDT. Use the signed-in top-up page for the exact checkout screen. This page does not publish a new minimum top-up amount.
- The published terms say no-reason refunds are not supported. How requests are forwarded and which logs are kept is in the privacy policy.
- The service is not offered to users in mainland China. Available payment methods do not change that service region.
The console can also generate a Claude Code snippet from the key list (“Use key”). That is a convenience; the values above are the ones that must be correct. A shorter pointer also lives in the guide.