Claude Code with B.AI API
Table of Contents
- Getting Started
- Option 1: settings.json (Recommended)
- Option 2: Environment Variables
- Switching Models
- Available Models
- FAQ
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
- Log in to the B.AI Chat Platform
- Navigate to the API Key Management Page
- 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.
Option 1: settings.json (Recommended)
This approach configures Claude Code via its own settings file, without modifying system environment variables.
Steps
- Locate the
settings.jsonfile in the Claude Code installation directory. If it does not exist, create a new one. - 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_MODELvalue with any model from the Available Models list.
- Save the file and restart your terminal.
- 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
| OS | Shell | Configuration File |
|---|---|---|
| Linux | Bash | ~/.bashrc |
| Linux | Zsh | ~/.zshrc |
| macOS | Bash | ~/.bashrc or ~/.bash_profile |
| macOS | Zsh | ~/.zshrc |
| Windows | PowerShell | $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 Name | Provider |
|---|---|
claude-opus-4.6 | Anthropic |
claude-opus-4.5 | Anthropic |
claude-sonnet-4.6 | Anthropic |
claude-sonnet-4.5 | Anthropic |
claude-haiku-4.5 | Anthropic |
gpt-5.2 | OpenAI |
gpt-5-mini | OpenAI |
gpt-5-nano | OpenAI |
gemini-3.1-pro | |
gemini-3-flash | |
kimi-k2.5 | Moonshot |
glm-5 | Zhipu AI |
minimax-m2.5 | MiniMax |
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:
- Claude Code is installed (
claude --versionoutputs a version number) curlis available (Linux / macOS)- 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