Agents & CLIsGuide reviewed 2026-09-13

Claude Code with RouterPlex

Point Claude Code at RouterPlex with ANTHROPIC_BASE_URL. One prepaid key, hard budgets, no local proxy.

Follow updates Share setup
On this page

Set it up with your coding agent #

Paste your key into the prompt's key field, then copy the prompt into Claude Code, Codex, Cursor, or any coding agent. It configures the tool and keeps testing until a real request goes through RouterPlex, fixing environment problems along the way. Prefer to do it by hand? Follow the manual setup below; your key fills those commands too.

prompt

Optional. It stays in this browser tab and is never saved or sent. No key yet? Create one in guided setup.

Set up Claude Code on this machine to use RouterPlex, an OpenAI- and Anthropic-compatible AI gateway. Keep working until a real request from Claude Code succeeds through RouterPlex.
 
My RouterPlex API key: YOUR_ROUTERPLEX_API_KEY
 
Key handling:
- If the key line above is a placeholder rather than a real key (real keys start with sk-), use my ROUTERPLEX_API_KEY environment variable. If that is empty too, ask me for the key once, then continue.
- Store the key only in user-level config or my user environment. Never put it in a project file, never commit it, and do not repeat the full key in your replies.
 
Full guide: https://docs.routerplex.com/claude-code
 
Step 1. Prove the key and the RouterPlex gateway work before changing anything else. Run:
curl -sS https://api.routerplex.com/v1/chat/completions -H "Authorization: Bearer YOUR_ROUTERPLEX_API_KEY" -H "Content-Type: application/json" -d '{"model":"claude-sonnet-4-6","max_tokens":32,"messages":[{"role":"user","content":"Reply with exactly: RouterPlex connected."}]}'
On Windows PowerShell, use curl.exe with the body in a file, or Invoke-RestMethod.
- A reply containing "RouterPlex connected.": go on.
- 401: the key is wrong or revoked. Stop and ask me for a correct key.
- 402: my balance or trial credit is used up. 403: this key reached its own spending limit. Stop and tell me; retrying cannot fix these.
- Network, DNS, TLS, or proxy errors: find and fix the cause (proxy variables, VPN, firewall, system clock, outdated CA certificates), then run it again.
 
Step 2. Configure Claude Code:
- Run claude --version. If Claude Code is missing, install it with the official installer (curl -fsSL https://claude.ai/install.sh | bash; Windows PowerShell: irm https://claude.ai/install.ps1 | iex).
- In my user-level Claude Code settings, ~/.claude/settings.json (Windows: %USERPROFILE%\.claude\settings.json), set these keys in the "env" object. Merge with what is there and keep my other settings:
ANTHROPIC_BASE_URL = https://api.routerplex.com (no /v1; Claude Code adds /v1/messages)
ANTHROPIC_AUTH_TOKEN = the key
ANTHROPIC_API_KEY = "" (empty, so a direct Anthropic key does not compete)
ANTHROPIC_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL = claude-sonnet-4-6
- Keeping the key in settings.json means Claude Code does not depend on shell variables.
 
Step 3. Test Claude Code itself from a new terminal or a restarted app, so you test the saved setup rather than the shell you changed:
From an empty temporary folder: claude --model 'claude-sonnet-4-6' -p 'Reply with exactly: RouterPlex connected. Do not read files or run tools.'
If the reply is wrong, run claude and check /status: it must show https://api.routerplex.com as the base URL.
Expected reply: "RouterPlex connected."
 
Step 4. If step 1 works but step 3 fails, the problem is Claude Code's configuration or environment, not RouterPlex. Check these, fix what is wrong, and repeat step 3:
- The key or base URL is set in one place but not where Claude Code starts: zsh vs bash startup files, login vs non-login shells, a desktop launcher, a background service, Windows vs WSL, or a remote SSH or container environment.
- Another setting wins: OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_API_BASE, ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL, or a project-level config that overrides the user-level one.
- Claude Code is outdated, or still needs a full restart to read the new settings.
- If an environment variable cannot be made to reach Claude Code reliably and Claude Code accepts a key in its user-level config, put the key there instead.
 
Keep repeating steps 3 and 4 until the test reply comes back. Stop early only for a 401, 402, or 403, or for a step only I can do, such as a click in a settings window or a login. Then tell me exactly what to do, wait for me, and continue testing afterwards.
 
When it works, tell me which files you changed, where the key is stored, and the final test output.

Manual setup #

Connect Claude Code directly to RouterPlex's Anthropic Messages endpoint. Start with a Claude model; other chat models may accept the protocol but differ in their support for Claude Code's tools.

1. Install or update #

macOS / Linux / WSL

bash
curl -fsSL https://claude.ai/install.sh | bash

Windows PowerShell

powershell
irm https://claude.ai/install.ps1 | iex

Reopen the terminal and run claude --version. Git for Windows is recommended for the Bash tool on native Windows; current Claude Code can use PowerShell when Git Bash is absent. If using WSL, follow the Linux instructions inside WSL.

2. Set the connection #

Create a key in guided setup. Paste the block for your shell, replacing YOUR_ROUTERPLEX_API_KEY with that key.

macOS / Linux — Bash or Zsh

bash
export ANTHROPIC_BASE_URL='https://api.routerplex.com'
export ANTHROPIC_AUTH_TOKEN='YOUR_ROUTERPLEX_API_KEY'
export ANTHROPIC_API_KEY=''
export ANTHROPIC_MODEL='claude-sonnet-4-6'
export ANTHROPIC_DEFAULT_HAIKU_MODEL='claude-sonnet-4-6'
export ANTHROPIC_DEFAULT_SONNET_MODEL='claude-sonnet-4-6'
export ANTHROPIC_DEFAULT_OPUS_MODEL='claude-sonnet-4-6'

Windows PowerShell

powershell
$env:ANTHROPIC_BASE_URL = 'https://api.routerplex.com'
$env:ANTHROPIC_AUTH_TOKEN = 'YOUR_ROUTERPLEX_API_KEY'
$env:ANTHROPIC_API_KEY = ''
$env:ANTHROPIC_MODEL = 'claude-sonnet-4-6'
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = 'claude-sonnet-4-6'
$env:ANTHROPIC_DEFAULT_SONNET_MODEL = 'claude-sonnet-4-6'
$env:ANTHROPIC_DEFAULT_OPUS_MODEL = 'claude-sonnet-4-6'

The base URL has no /v1 suffix. Claude Code adds /v1/messages. The empty ANTHROPIC_API_KEY avoids a competing direct-provider credential. The default model variables pin aliases and background work to the selected RouterPlex model. ANTHROPIC_SMALL_FAST_MODEL is deprecated; use ANTHROPIC_DEFAULT_HAIKU_MODEL.

3. Send a short test #

In the same terminal, from an empty folder:

text
claude --model claude-sonnet-4-6 -p "Reply with exactly: RouterPlex connected. Do not read files or run tools."

Confirm the reply and the request in Usage. Then run claude in your project. /status shows the active setup, and /model changes the model for a session.

Reusing the configuration #

The shell settings last for the current terminal session. For persistent setup, use Claude Code's user-level env settings in ~/.claude/settings.json (macOS/Linux) or %USERPROFILE%\.claude\settings.json (Windows), or configure your shell environment. Keep credentials out of project files and source control. Existing settings or organization policies may override the environment; review /status if the wrong route is used.

Give Claude Code a dedicated budget. A successful short reply proves connectivity, not every tool workflow with every model.

A longer install walkthrough is in Install Claude Code with RouterPlex.

Official references: Claude Code setup, model configuration.

Claude Code with RouterPlex — Docs