Skip to content
Sign Up Free
Coding Agent setup

Claude Code installation, API Key, Base URL, and models

Connect Claude Code with a BetterToken API Key, Base URL, and Model ID. Set your model before launch or switch with /model during a session.

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.

Key settings

FieldValue
API KeyBetterToken API Key
Base URLhttps://bettertoken.ai
ModelYOUR_MODEL_ID

Prerequisites

Sign up and get a BetterToken API Key

Already have an account? Sign in, top up, then create a key in the console.

Install

Anthropic recommends the native installer, which does not require Node.js. If you prefer npm, install Node.js 22 or later, then run:

Terminal window
npm install -g @anthropic-ai/claude-code

Command-line setup

The BetterToken Automatic setup script writes the Claude Code provider configuration. It requires Node.js and prompts for the API Key when one is not passed as an argument.

macOS / Linux

Terminal window
curl -fsSL "https://bettertoken.ai/install-claudecode-provider.sh" | bash

Windows

Terminal window
iwr "https://bettertoken.ai/install-claudecode-provider.ps1" -OutFile "$env:TEMP\install-claudecode-provider.ps1"; powershell -ExecutionPolicy Bypass -File "$env:TEMP\install-claudecode-provider.ps1"

After it finishes, inspect ~/.claude/settings.json (or %USERPROFILE%\.claude\settings.json on Windows) and fully restart Claude Code. Use the manual setup below when you want to control each field yourself.

Manual setup

SystemFile
macOS / Linux~/.claude/settings.json
Windows%USERPROFILE%\.claude\settings.json

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.

The examples include the optional CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 setting. It disables automatic updates, error reporting, and some availability checks and account features; authentication does not require it. To update manually, run claude update, or use your package manager if it manages the installation. See update instructions and the setting’s effects.

VS Code extension

The extension uses VS Code settings.json. Add a separate claudeCode.environmentVariables configuration:

{
"claudeCode.environmentVariables": [
{
"name": "ANTHROPIC_BASE_URL",
"value": "https://bettertoken.ai"
},
{
"name": "ANTHROPIC_AUTH_TOKEN",
"value": "YOUR_API_KEY"
},
{
"name": "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC",
"value": "1"
},
{
"name": "API_TIMEOUT_MS",
"value": "3000000"
},
{
"name": "ANTHROPIC_MODEL",
"value": "YOUR_MODEL_ID"
},
{
"name": "ANTHROPIC_DEFAULT_HAIKU_MODEL",
"value": "YOUR_MODEL_ID"
},
{
"name": "ANTHROPIC_DEFAULT_SONNET_MODEL",
"value": "YOUR_MODEL_ID"
},
{
"name": "ANTHROPIC_DEFAULT_OPUS_MODEL",
"value": "YOUR_MODEL_ID"
}
]
}

Verify the connection

Start Claude Code in your project:

Terminal window
claude

Send a short message. A normal response without 401, connection, or model errors confirms the setup. In the interactive session, run /status and check two lines:

  • Anthropic base URL should show the BetterToken Base URL: https://bettertoken.ai. If the line is missing, the variable did not reach the current session. Check the settings.json path and fully restart Claude Code.
  • The authentication line should show ANTHROPIC_AUTH_TOKEN, rather than a claude.ai account login.

To verify the connection from a script, send a short prompt:

Terminal window
claude -p "Reply with only: OK"

A normal OK response confirms the connection works.

Conflicts with an existing login

Credentials in environment variables take priority over a saved claude.ai login. If you see a warning about two credential sources at startup, unset one of them. To keep only your BetterToken API Key, run /logout. If your shell also sets ANTHROPIC_API_KEY, clear it first.

Switch models

Update the Model ID in your configuration and restart Claude Code. To switch during a session, use /model YOUR_MODEL_ID.

For other aliases, such as fable with ANTHROPIC_DEFAULT_FABLE_MODEL, follow the official alias mapping and use an available Model ID. If Claude Code assumes the wrong context window for a custom ID, follow the custom-model window guidance using the model’s confirmed limit.

Show BetterToken models in /model (optional)

Use a recent Claude Code release. Add "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1" to the existing env block in ~/.claude/settings.json, then fully restart Claude Code. At startup, Claude Code queries /v1/models at https://bettertoken.ai for available models. See the official gateway setup guide.

To confirm discovery, start claude --debug and look for [gatewayDiscovery] lines in ~/.claude/debug/<session-id>.txt. A line reporting cached models confirms discovery succeeded.

Claude Code lists only gateway models whose Model ID contains claude or anthropic (case-insensitive), as described in its gateway protocol. Other models returned by /v1/models, including GPT models, do not appear in /model even when BetterToken serves them. Claude Code can still call such a model when you set its Model ID directly; a GPT model passed this way answered text and file-read requests through Anthropic Messages in testing with Claude Code 2.1.309.

Common errors

ErrorFix
401 or authentication failureCheck ANTHROPIC_AUTH_TOKEN and remove spaces around the API Key.
ConnectionRefusedUse exactly https://bettertoken.ai; do not append /v1.
Model IDCheck the exact Model ID in the model plaza and enter it in the client model settings.
Configuration not appliedCheck the file path, clear conflicting environment variables, and fully restart Claude Code.
Warning about two conflicting credential sources at startupUnset one source or run /logout.
Certificate / TLS error, often with a corporate proxySet NODE_EXTRA_CA_CERTS to the CA certificate file path and restart Claude Code.
400 mentioning an unrecognized field, such as Extra inputs are not permittedAdd "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1" to env and fully restart Claude Code. If the error persists, contact support.
Context too long during a long sessionRun /compact to compress the session.

Features unavailable with an API Key

Remote Control and voice input require a claude.ai account login. They are unavailable when you use a BetterToken API Key and a custom Base URL. This is a Claude Code client limitation and does not affect normal coding conversations.

Advanced setup

To manage several tool configurations in one app, see CC Switch.

Technical details

Protocol and endpoint

Claude Code uses Anthropic Messages. Set ANTHROPIC_BASE_URL to https://bettertoken.ai; the client appends /v1/messages, so do not add /v1 to the Base URL.