Skip to main content

Claude Code with B.AI API

Table of Contents


Getting Started

Complete the following two prerequisites before proceeding with configuration.

Step 1: Install Claude Code

Choose the installation method for your operating system:

macOS / Linux / WSL:

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

Windows PowerShell:

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

npm (requires Node.js 18+):

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

Step 2: Obtain a B.AI API Key

  1. Log in to the B.AI Chat Platform
  2. Navigate to the API Key Management Page
  3. Click to create a new API Key

Note: Keep your API Key secure — you will need it in the configuration steps below.

Once both prerequisites are complete, choose either option below to configure the B.AI API.


This approach configures Claude Code via its own settings file, without modifying system environment variables.

Steps

  1. Locate the settings.json file in the Claude Code installation directory. If it does not exist, create a new one.
  2. Add the following content:
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "Your-B.AI-API-Key",
"ANTHROPIC_BASE_URL": "https://api.b.ai",
"ANTHROPIC_MODEL": "claude-sonnet-4.6",
"API_TIMEOUT_MS": "3000000"
}
}

Tip: You can replace the ANTHROPIC_MODEL value with any model from the Available Models list.

  1. Save the file and restart your terminal.
  2. Verify the configuration:
claude --version
claude

If Claude Code starts successfully and responds using the B.AI model, the configuration is complete.


Option 2: Environment Variables

This approach is suitable when you need the configuration to take effect globally.

Set Environment Variables

Add the following lines to the appropriate shell configuration file:

Bash (Linux / macOS)

Edit ~/.bashrc (or ~/.bash_profile on macOS):

# Claude Code - B.AI Provider Configuration
export ANTHROPIC_BASE_URL="https://api.b.ai"
export ANTHROPIC_AUTH_TOKEN="your-api-key-here"
export ANTHROPIC_MODEL="claude-sonnet-4.6"
# End of B.AI Provider Configuration

Apply the changes:

source ~/.bashrc

Zsh (Linux / macOS)

Edit ~/.zshrc:

# Claude Code - B.AI Provider Configuration
export ANTHROPIC_BASE_URL="https://api.b.ai"
export ANTHROPIC_AUTH_TOKEN="your-api-key-here"
export ANTHROPIC_MODEL="claude-sonnet-4.6"
# End of B.AI Provider Configuration

Apply the changes:

source ~/.zshrc

PowerShell (Windows)

Edit your $PROFILE file:

# Claude Code - B.AI Provider Configuration
$env:ANTHROPIC_BASE_URL = "https://api.b.ai"
$env:ANTHROPIC_AUTH_TOKEN = "your-api-key-here"
$env:ANTHROPIC_MODEL = "claude-sonnet-4.6"
# End of B.AI Provider Configuration

Apply the changes:

. $PROFILE

Configuration File Path Reference

OSShellConfiguration File
LinuxBash~/.bashrc
LinuxZsh~/.zshrc
macOSBash~/.bashrc or ~/.bash_profile
macOSZsh~/.zshrc
WindowsPowerShell$PROFILE

Verify the Configuration

claude --version
claude

If Claude Code starts successfully and responds using the B.AI model, the configuration is complete.


Switching Models

Temporary Switch (Current Session Only)

Linux / macOS:

ANTHROPIC_MODEL=claude-opus-4.6 claude

Windows PowerShell:

$env:ANTHROPIC_MODEL="claude-opus-4.6"; claude

Permanent Switch

Update the ANTHROPIC_MODEL value in your settings.json or shell configuration file, then restart the terminal or reload the configuration.


Available Models

Model NameProvider
claude-opus-4.6Anthropic
claude-opus-4.5Anthropic
claude-sonnet-4.6Anthropic
claude-sonnet-4.5Anthropic
claude-haiku-4.5Anthropic
gpt-5.2OpenAI
gpt-5-miniOpenAI
gpt-5-nanoOpenAI
gemini-3.1-proGoogle
gemini-3-flashGoogle
kimi-k2.5Moonshot
glm-5Zhipu AI
minimax-m2.5MiniMax

For the full and up-to-date model list, query the Models API provided by B.AI.


FAQ

Q: I get "claude command not found" — what should I do?

Install Claude Code first:

  • Linux / macOS: curl -fsSL https://claude.ai/install.sh | bash
  • Windows: irm https://claude.ai/install.ps1 | iex

Restart your terminal after installation.

Q: The setup script fails — what should I check?

Verify the following:

  1. Claude Code is installed (claude --version outputs a version number)
  2. curl is available (Linux / macOS)
  3. Your network can reach https://api.b.ai

If the issue persists, try Option 2: Environment Variables for manual configuration.

Q: How do I verify the configuration is working?

Check that the environment variables are set:

Linux / macOS:

echo $ANTHROPIC_BASE_URL
echo $ANTHROPIC_MODEL

Windows PowerShell:

$env:ANTHROPIC_BASE_URL
$env:ANTHROPIC_MODEL
Q: How do I check which model is currently in use?

After launching Claude Code, type:

/status
Q: Why do I get 403 access_denied when calling some models?

Models with a Premium tag may return 403 access_denied if your B.AI account has not been recharged before.

A valid API key alone is not sufficient for Premium models. Please recharge your account first, then try again.

Q: How do I remove the B.AI provider configuration?

Edit your shell configuration file and delete everything between the following comment blocks:

# Claude Code - B.AI Provider Configuration
...
# End of B.AI Provider Configuration

Then reload the configuration file (e.g., source ~/.zshrc).


Version: v1.0 | Last Updated: 2026-03-27