UniRoute
Docs

Claude Code third-party API setup

Configure Claude Code with a UniRoute API key, base URL, and model, verify a first request and charge, and troubleshoot authentication and connections.

Claude Code · pay-as-you-go API

Connect Claude Code to UniRoute with a Messages API key and a model. The setup command preserves your settings and completes API onboarding.

Best for: Developers coding in a terminal on macOS, Linux, or Windows.

Quick setup

Sign in to create a key and fill it in automatically Sign in

bash
UNIROUTE_API_KEY=YOUR_UNIROUTE_API_KEY npx -y uniroute-setup@latest configure claude --model claude-sonnet-5-5

The command requires Node.js 22+. It merges the selected model and credentials into settings, removes an old ANTHROPIC_API_KEY that could compete with the token, and sets hasCompletedOnboarding to true. Existing changed files are backed up first. Add --dry-run to preview without writing.

Manual configuration

1. Quit Claude Code and back up both files

On macOS / Linux: ~/.claude/settings.json and ~/.claude.json. On Windows: $HOME\.claude\settings.json and $HOME\.claude.json. Create missing files as JSON objects.

2. Merge the API settings

json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.uniroute.app",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_UNIROUTE_API_KEY"
  },
  "model": "claude-sonnet-5-5"
}

Preserve permissions, plugins, and unrelated settings. Remove an existing ANTHROPIC_API_KEY from this file. The client appends /v1/messages, so use the root URL without /v1.

3. Complete API onboarding

json
{
  "hasCompletedOnboarding": true
}

Merge this field into ~/.claude.json and preserve every other key. This skips the Anthropic login selection for the configured API flow. Terminal theme and project trust are still chosen in the client.

4. Use the same settings directory and restart

If CLAUDE_CONFIG_DIR is set, use that directory for settings.json and .claude.json. The setup tool honours this variable. For an isolated --home /path/to/test-home run, unset an absolute CLAUDE_CONFIG_DIR first; a relative directory is resolved under the selected home. Run claude in your project, then use claude auth status --text to inspect authentication without printing your key.

What these fields do

FieldPurpose
ANTHROPIC_BASE_URLUniRoute API root; Claude Code appends the Messages path.
ANTHROPIC_AUTH_TOKENYour UniRoute key used to authenticate requests.
modelThe complete Claude model ID to select at startup.
hasCompletedOnboardingMarks the API setup as initialized in the client preference file.

Choose a model

Confirm the connection

Check status with /status to inspect the active model and service.

Send a short test: claude -p "Reply only: hello"

Open usage logs to review the model, request status and charge. The test is a real, billed API request.

Use /cost for the client view and the console record for the actual UniRoute charge.

Switch back / restore a backup

Quit Claude Code. Restore both settings.json.uniroute-….bak and .claude.json.uniroute-….bak from the paths printed by the tool. To return to an Anthropic subscription, restore the previous credentials and onboarding preference, remove API variables you set in the launching shell, then reopen and sign in. Preserve unrelated settings changed after setup.

If a file was new and has no backup, remove only the fields added by this setup and preserve settings added later.

Not installed yet?

Install Node.js 22+, then follow the official Claude Code installation guide. For npm installation:

npm install -g @anthropic-ai/claude-code
claude --version

FAQ

Do I need an Anthropic subscription?

Use your UniRoute key for this API setup. UniRoute API usage is billed separately from an Anthropic subscription.

Can I keep my plugins and permissions?

Yes. The tool merges only its configuration fields and backs up existing changed files. Keep your key in private configuration and out of repositories.

Why does login still appear?

Check the operating system user, CLAUDE_CONFIG_DIR, and project or managed overrides. Then check the onboarding field in the matching preference file and restart. See settings precedence.

Troubleshooting

401 / invalid key

The key is incomplete, revoked, or another credential is selected.

Paste a valid key, remove the conflicting API key field, and rerun setup.

404 / incorrect endpoint

The base URL includes a duplicated path.

Set ANTHROPIC_BASE_URL to https://api.uniroute.app without /v1.

403 / model not found

The model ID, key permission, or wallet funds need attention.

Check the model catalog, key settings, and wallet in the console.

Timeout / partial stream

The connection stopped before the client received the full response.

Check usage records before retrying; compare network and proxy settings.

Related links

Claude Code API pricing · Error 500 diagnosis · Stream timeout diagnosis

Manage API keys

· Protocols and addresses ·

Model prices

· Usage records · Setup Skill