Curated models for your best work
Join the waitlistRouter docs
Claude Code with TokenSpend
Point Claude Code at TokenSpend with a few environment variables.
Paste it into your coding agent. It carries no key and states how far this setup has been tested.
See what gets copied
# Connect Claude Code to TokenSpend API format: Messages API key: a TokenSpend key, read from the environment variable TOKENSPEND_API_KEY. Never write it into a project file or print it. Back up any existing config before you change it, and tell the user what you changed. Models: exact IDs are listed at https://tokenspend.dev/models (for example anthropic/claude-sonnet-4-6). Configuration (run in a subshell so your shell settings are not changed): ```bash ( export ANTHROPIC_BASE_URL=https://api.tokenspend.dev export ANTHROPIC_AUTH_TOKEN="$TOKENSPEND_API_KEY" unset ANTHROPIC_API_KEY export ANTHROPIC_MODEL="anthropic/claude-sonnet-4-6" export CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1 export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 claude ) ``` For a non-Claude model also set MAX_THINKING_TOKENS=0. In /status, check the TokenSpend base URL and the credential source. Check: 1. Send one small request with synthetic content. It is billable. Note the request ID, not the key. 2. Open https://tokenspend.dev/dashboard/router and match the request ID, model, status, token counts and cost. If something fails, check the error code at https://tokenspend.dev/docs/router/reliability#errors and https://tokenspend.dev/status. Do not send keys or private prompts to support.
1. Set your key
Create a rail key in Router, then load it into this terminal. It stays in your environment, not in a project file.
printf 'TokenSpend rail key: ' read -r -s TOKENSPEND_API_KEY printf '\n' export TOKENSPEND_API_KEY
2. Connect Claude Code
Claude Code
Install Claude Code from Claude's setup guide, set your key as above, then start it from that terminal. Keep keys out of project files.
This example uses Sonnet 4.6. It turns off adaptive thinking and experimental betas.
( export ANTHROPIC_BASE_URL=https://api.tokenspend.dev export ANTHROPIC_AUTH_TOKEN="$TOKENSPEND_API_KEY" unset ANTHROPIC_API_KEY export ANTHROPIC_MODEL="anthropic/claude-sonnet-4-6" export CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1 export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 claude )
Models that work in Claude Code (23)
- anthropic/claude-opus-5-5
- anthropic/claude-sonnet-4-6
- zai/glm-5.3
- zai/glm-5.3-flash
- qwen/qwen3.5-397b
- qwen/qwen3.8-27b
- qwen/qwen3.8-flash
- qwen/qwen3.8-2.4t-a95b
- qwen/qwen3.7-max
- qwen/qwen3.7-plus
- qwen/qwen3.6-plus
- qwen/qwen3.5-9b
- thinking-machines/inkling
- amazon/nova-lite
- google/gemini-3.8-flash
- google/gemini-3.6-flash
- google/gemini-3.5-flash-lite
- google/gemini-3.1-flash-lite
- google/gemini-3.1-pro
- xai/grok-4.6
- xai/grok-4.5
- xai/grok-4.3
- xai/grok-build-0.1
For a non-Claude model, also set MAX_THINKING_TOKENS=0. For a smaller output limit, such as Nova's 5,000, set CLAUDE_CODE_MAX_OUTPUT_TOKENS to it.
In /status, check the base URL and the credential source. A settings file can override both. Exit the subshell to go back to your normal settings.
Adaptive thinking, server-side tools and unlisted beta fields return a 400. Keep tool results in Messages format.
Sources: gateway authentication · feature compatibility.
3. Check the receipt
A response is only half the check. Send one small request, then match its request ID, model and cost in Router activity. The full steps are in Verify the receipt.