Claude Code API Key Setup:
Custom Base URL and settings.json

Run Claude Code on an API key instead of a Pro or Max plan: install, set ANTHROPIC_BASE_URL in settings.json or use CC Switch, and fix common errors.

Updated 7 min read

Claude Code can run on an API key instead of a Claude subscription. Point ANTHROPIC_BASE_URL at an Anthropic-compatible API, put your key in ANTHROPIC_AUTH_TOKEN, and that provider bills each request per token. Teams usually set it up this way for one of two reasons. Anthropic doesn’t offer Claude in their region, or they would rather pay for usage than buy a seat for every developer. This guide covers install, two ways to connect, a quick test and the common errors.

Written for Claude Code 2.1 and checked against the official Claude Code docs in November 2026. API usage is billed per token.

Ways to run Claude Code

Claude Code is Anthropic’s coding agent. It reads your code, edits files and runs commands from the terminal, VS Code or JetBrains. It needs a model service behind it. By default you sign in with a Claude account: Pro, Max, Ultra, Team, Enterprise or a Console (API) account. The free Claude plan doesn’t include Claude Code.

Claude accounts are only offered in Anthropic’s supported regions. The list doesn’t include Russia, Belarus, Iran, Hong Kong, Macau or mainland China, among others, and your payment method has to fit as well.

Claude Code also reads the ANTHROPIC_BASE_URL environment variable, which the official docs describe as the way to route requests through a proxy or gateway. That gives you three options:

Option What you need Good fit for
Claude account (Pro, Max, Ultra, Team, Console) An account and payment method in a supported region People and teams in supported regions who are fine with per-seat plans
Cloud provider (Amazon Bedrock, Google Cloud, Microsoft Foundry) A cloud account with access to Claude models Companies that already bill through that cloud
API service, for example Brioi One API key Teams in regions Anthropic doesn’t serve, and teams that want pay-as-you-go billing

Brioi works in regions where Claude accounts aren’t offered. You pay per token from one balance at about 10–50% of the official price, and the same balance covers GPT, Gemini and video models. Top up with USDT or an international card. No Claude subscription is involved.

Step 1: Install Claude Code

The official installer is the recommended route. On macOS, Linux and WSL:

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

Windows PowerShell:

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

Homebrew on macOS, or WinGet on Windows:

brew install --cask claude-code
winget install Anthropic.ClaudeCode

The native installer updates itself in the background. Homebrew and WinGet installs don’t, so run brew upgrade claude-code or winget upgrade Anthropic.ClaudeCode now and then.

If the install script fails, npm installs the same binary. It needs Node.js 22 or later:

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

The official docs warn against sudo npm install -g, because later auto-updates then run into permission errors.

Open a new terminal window and check the version:

claude --version

A version number means the install worked. For a fuller check of the install and your settings files, run claude doctor.

Step 2: Create an API key

  1. Open the Brioi API keys page. If you don’t have an account yet, sign up on the main site first.
  2. Click Create API key in the top right.
  3. Name it Claude Code.
  4. Choose the group Claude Code | CCMAX | 满血版. The console shows the group name exactly like this; 满血版 means full-strength.
  5. Leave the other settings at their defaults and save.

The group decides which models the key can call and how they are billed. This group includes every Claude model recommended below.

Step 3: Connect Claude Code

Pick one of the two methods. CC Switch is quicker if you don’t want to edit config files. The manual settings.json route is easier to copy across machines or roll out to a team.

CC Switch is an open-source desktop app that manages provider settings for Claude Code, Codex and similar tools. Download it only from its GitHub Releases page, install it and open it once.

  1. On the Brioi API keys page, click the ⋯ menu next to the key you just created and choose CC Switch.
  2. Set the app to Claude and pick the models from the table below.
  3. Click Open CC Switch. When the browser asks whether to open the external app, allow it, then click Import in the CC Switch dialog.
Setting Recommended model
Main model claude-fable-5
Haiku model claude-sonnet-5
Sonnet model claude-sonnet-5
Opus model claude-opus-5

Claude Code also uses the Haiku slot for background tasks. This setup keeps it on claude-sonnet-5; any model in the group works there. The import carries the key, the base URL and the models, so there is nothing to type by hand.

Option 2: Edit settings.json by hand

Claude Code reads ~/.claude/settings.json in your home directory (%USERPROFILE%\.claude\settings.json on Windows). Variables under env apply wherever you start claude. Create the file if it doesn’t exist:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://vip.brioi.com",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
    "ANTHROPIC_MODEL": "claude-fable-5",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-sonnet-5"
  }
}

What each variable does, per the official Claude Code docs:

  • ANTHROPIC_BASE_URL: sends requests to this endpoint instead of Anthropic’s API. Use the host only, without /v1; Claude Code adds the path itself.
  • ANTHROPIC_AUTH_TOKEN: the key, sent as Authorization: Bearer <key>. It takes precedence over ANTHROPIC_API_KEY and over a claude.ai login, so you don’t need to sign out of an existing subscription.
  • ANTHROPIC_MODEL: the default model.
  • ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL: the model each alias resolves to when you switch with /model opus, sonnet or haiku. The Haiku model also runs background tasks.

settings.json is strict JSON. No comments and no trailing comma after the last entry, or Claude Code reports a settings error at startup. The Claude Code extensions for VS Code and JetBrains read the same file.

These variables apply to the CLI and the IDE extensions. The Claude desktop app and cloud sessions don’t read them, and Remote Control turns off while the base URL points somewhere other than Anthropic.

Step 4: Check that it works

If Claude Code is already running, quit and start it again:

claude

Send a tiny prompt:

Reply with BRIOI_OK only

A reply means the connection works. You can also confirm the request in the request log in the Brioi console. This test uses a small amount of balance.

Common errors

Symptom Cause and fix
Clicking CC Switch does nothing CC Switch isn’t installed or hasn’t been opened yet. Open it once, then click CC Switch on the keys page again
Model unavailable, or 503 model_not_found The key’s group doesn’t include that model. Check that the group is Claude Code | CCMAX | 满血版, or switch to a model the group has
401 The key is missing, cut off when copied, or disabled. If you changed the key in the console, import it again
403 Balance is too low, or the key has no access to that group. Check your balance and the key’s group
429 Too many requests in a short time. Wait a moment and retry
Long tasks time out A request waited longer than the default 10 minutes. Add "API_TIMEOUT_MS": "1200000" under env to allow 20 minutes
Still asks you to sign in to a Claude account The settings didn’t load. Run claude doctor and look for settings-file errors

What it costs

With an API key, Claude Code is billed per token and there’s no monthly plan. Per-model prices for each route are on the pricing page. Brioi’s enterprise pricing is about 10–50% of the official price, and Claude, GPT and the other models all draw from one balance. For a month-by-month comparison with Pro, Max and Ultra, see Claude Code cost per month.

Keep your key safe

  • Don’t paste API keys or CC Switch import links into group chats, ticket screenshots, repositories or public logs.
  • settings.json holds your key, so keep it out of Git. Shared project settings go in .claude/settings.json inside the repo; the key stays in ~/.claude/settings.json in your home directory.
  • If you think a key has leaked, disable it on the Brioi API keys page right away and create a new one.

FAQ

Do I need a Claude Pro or Max subscription to use Claude Code?

No. With an API key you pay per token, and no Claude subscription is involved.

Anthropic doesn’t serve my country. Can I still use Claude Code?

Claude accounts aren’t offered there, but Claude Code itself is a free download and doesn’t need one when you use an API key. Brioi works in regions Anthropic doesn’t serve: create a key, point ANTHROPIC_BASE_URL at https://vip.brioi.com and top up with USDT or an international card. If the install script fails to download, use the npm install above.

Can a team share one setup?

Give each developer their own key. Each key can have its own spending limit, allowed models and expiry date, and all of them draw from the team’s one balance. When someone leaves, disable their key. See Claude Code and Codex for dev teams.

Does Codex work the same way?

Yes, with a different config file. See Codex CLI custom provider setup.