Claude Code Custom API Endpoint: API Key and Base URL
Connect Claude Code with your BetterToken API Key, Base URL BetterToken, and the Model ID you want to use.
Claude Code custom API endpoint: quick answer
A Claude Code custom API endpoint must be Anthropic-compatible. In this documentation, Claude Code uses https://bettertoken.ai. Do not add /v1.
For general Claude API access, available models, and ways to get started, use the BetterToken Claude API page. This FAQ only covers using an existing BetterToken API key with Claude Code through its Base URL and environment variables; it does not duplicate the general API overview.
The API Key authenticates the request. The Base URL tells Claude Code where to send model requests. Both must belong to the same provider and protocol.
Connect Claude Code with your BetterToken API Key, Base URL https://bettertoken.ai, and the Model ID you want to use. Copy the exact Model ID from the model plaza.
When this matters
- You want Claude Code to use a custom API gateway
- You have an API Key but are unsure which Base URL to use
- Claude Code reports an authentication or endpoint error
- You are choosing between
https://bettertoken.aiandhttps://bettertoken.ai/v1
Key concepts
| Field | Meaning |
|---|---|
| API Key | Credential for model API requests |
| Base URL | The API address where requests are sent |
| Anthropic-compatible API | Endpoint that follows Anthropic / Claude request conventions |
| OpenAI-compatible API | Endpoint that follows OpenAI-style conventions, often used by Codex, Cursor, and Cline |
| Model ID | The model name or mapping value requested by the tool |
Recommended setup
Connect Claude Code with your BetterToken API Key, Base URL https://bettertoken.ai, and the Model ID you want to use.
Copy the exact Model ID from the model plaza.
{ "env": { "ANTHROPIC_BASE_URL": "https://bettertoken.ai", "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1", "API_TIMEOUT_MS": "3000000", "ANTHROPIC_MODEL": "YOUR_MODEL_ID", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "YOUR_MODEL_ID", "ANTHROPIC_DEFAULT_SONNET_MODEL": "YOUR_MODEL_ID", "ANTHROPIC_DEFAULT_OPUS_MODEL": "YOUR_MODEL_ID" }}Replace YOUR_MODEL_ID with the Model ID you copied. Set ANTHROPIC_MODEL for the main model and the three ANTHROPIC_DEFAULT_*_MODEL variables for the Haiku, Sonnet, and Opus aliases. You can map them to the same model or choose a different model for each role.
Update the Model ID in your configuration and restart Claude Code. To switch during a session, use /model YOUR_MODEL_ID.
Common mistakes
-
Adding
/v1to the Claude Code Base URL. -
Changing the API Key but leaving requests pointed at the default endpoint.
-
Putting an OpenAI-compatible endpoint into Claude Code’s Anthropic-compatible fields.
-
Defining old environment variables in a shell profile that override the new config.
About BetterToken
BetterToken provides two endpoint types: the Anthropic-compatible https://bettertoken.ai for Claude Code and the OpenAI-compatible https://bettertoken.ai/v1 for Codex and external tools.
This lets you manage API Keys, balance, and usage history in one dashboard, but it does not change Claude Code’s requirement for Anthropic-compatible request formatting.
Related docs
- Claude Code setup guide
- Does Claude Code use a Claude.ai account or an API Key?
- OpenAI-compatible API vs Anthropic-compatible API
- Why Claude Code uses so many tokens and how to reduce cost

