Guide

How to connect AlRouter in your CLI

You can set environment variables directly, or register everything at once with CC Switch.

Watch the video, or follow the step-by-step guide below.

Video not loading? You can follow the written steps below

Step-by-step

1

Sign in to AlRouter

Sign in to your AlRouter account before creating an API key.

2

Create an API key

Go to the 'API Keys' menu, create a new API key, and copy it.
You'll use this single key for all the setup below.

API key creation screen
2-1. Create the API key
Copying the generated API key
2-2. Copy the generated key
3

Set environment variables

Add the environment variables for your CLI to your shell config file, then apply the changes.

A shell config file runs automatically every time you open a terminal (~/.zshrc for zsh, ~/.bash_profile or ~/.bashrc for bash).
Adding the environment variables there means every new terminal picks them up automatically, so you don't have to re-enter them each time.

1Add the environment variables to your shell config
Note

Replace the example key below with your actual issued key.

Anthropic
~/.zshrc
export ANTHROPIC_BASE_URL="https://alrouter.ai"
export ANTHROPIC_API_KEY="sk-your-key"
Google
~/.zshrc
export GOOGLE_GEMINI_BASE_URL="https://alrouter.ai/v1beta"
export GEMINI_API_KEY="sk-your-key"
OpenAI
~/.zshrc
export OPENAI_API_KEY="sk-your-key"

Codex — Codex CLI manages the Base URL in a separate config file, not an environment variable.
Keep the API key as is, and add the value below to ~/.codex/config.toml.

~/.codex/config.toml
openai_base_url = "https://alrouter.ai/v1"

After adding the setting above, using Codex may show a "Falling back from WebSockets to HTTPS" warning.
This doesn't affect functionality, but if you'd rather not see the warning, add the following to the same file.

~/.codex/config.toml
[features]
responses_websockets_v2 = false
Editing the shell config file to add environment variables
3-1. Add environment variables to the shell config
2Apply the changes

Open a new terminal, or apply the changes to your current one right away with the command below.

$ source ~/.zshrc
Terminal after applying the settings
3-2. Apply the changes
4

Verify the connection

Run claude in a new terminal, then use /status to verify the AlRouter connection.
If the base URL shows alrouter.ai, you're all set.

Note

Environment variables apply only to newly opened terminals. If a terminal was open before you set them, open a new one.

$ claude
> /status
Anthropic base URL: https://alrouter.ai
/status connection check screen
4-1. /status connection check
5

Test

Enter a simple prompt to confirm the connection works.

$ claude
> This is an integration test. Please reply only with "Claude Code connection successful."
Claude Code connection successful.
Test prompt response screen
5-1. Test prompt response
6

Check usage

Every request is tracked per key — including tokens and cost — under the 'Usage Logs' menu.
The 'Overview' and 'Dashboard' pages also show your usage trends as charts at a glance.

Usage logs screen
6-1. Usage Logs
Dashboard chart screen
6-2. Dashboard chart
Video not loading? You can follow the written steps below

Step-by-step

0

Install CC Switch

If it's already installed, you can skip this step.

1macOS · Homebrew (recommended)
$ brew tap farion1231/ccswitch
$ brew install --cask cc-switch
2macOS / Windows · GitHub Releases

Download and run the installer for your OS.

Download from GitHub Releases
1

Sign in to AlRouter

Sign in to your AlRouter account before creating an API key.

2

Create an API key

Go to the 'API Keys' menu, create a new API key, and copy it.
You'll use this single key for all the setup below.

API key creation screen
2-1. Create the API key
Copying the generated API key
2-2. Copy the generated key
3

Register automatically with CC Switch

From the API key's More menu, select "CC Switch," then enter the provider and default model — CC Switch opens.
Review the details and click "Import" to complete the registration.

CC Switch input form
3-1. Select the provider and default model
CC Switch import confirmation screen
3-2. Review the details and click "Import"
CC Switch import complete screen
3-3. Import complete
TIP

Switching your selection in the CC Switch list lets you easily switch back to the official provider anytime.

4

Verify the connection

Restart Claude Code, then check the AlRouter connection with /status.
If the Anthropic base URL shows alrouter.ai, it's working correctly.

Note

Settings take effect after restarting. If a session was open before registering, quit it completely and start a new one.

$ claude
> /status
Anthropic base URL: https://alrouter.ai
/status connection check screen
4-1. /status connection check
5

Test

Enter a simple prompt to confirm the connection works.

$ claude
> This is an integration test. Please reply only with "Claude Code connection successful."
Claude Code connection successful.
Test prompt response screen
5-1. Test prompt response
6

Check usage

Every request is tracked per key — including tokens and cost — under the 'Usage Logs' menu.
The 'Overview' and 'Dashboard' pages also show your usage trends as charts at a glance.

Usage logs screen
6-1. Usage Logs
Dashboard chart screen
6-2. Dashboard chart