Connect B.AI with CC Switch
Use your B.AI API Key in Claude Code or Codex through CC Switch. CC Switch manages provider configuration; send your requests from the coding client after setup.
Before You Begin
- Install CC Switch from its official releases page, and install the client you want to use: Claude Code or Codex.
- Obtain a B.AI API Key from the API Key page.
- Confirm that the account has sufficient balance and access to a model compatible with the client's API and tool use.
Treat the API Key as a password. Do not include it in screenshots, shared configuration, or source control. The generated configuration preview in CC Switch may contain the full Key even when the API Key field is masked.
1. Choose the Client and Add a Provider
Open CC Switch, select Claude Code or Codex, click Add Provider, and choose Custom Configuration. Name the provider B.AI and enter your B.AI API Key.
The two clients need different URLs and protocols:
| Setting | Claude Code | Codex |
|---|---|---|
| Provider name | B.AI | B.AI |
| Website, optional | https://b.ai/ | https://b.ai/ |
| API Key | Your B.AI API Key | Your B.AI API Key |
| API Request URL | https://api.b.ai | https://api.b.ai/v1 |
| Upstream Format | Anthropic Messages (native) | Responses (native) |
| Full URL | Off | Off |
| Request endpoint | /v1/messages | /v1/responses |
Expand Advanced Options to check the upstream format. These native protocols do not require local routing for protocol conversion. For a first connection, use a direct provider configuration rather than Chat Completions conversion or aggregation.
Do not enter the complete /v1/messages or /v1/responses endpoint in the API Request URL field. For Claude Code, leave the authentication field at ANTHROPIC_AUTH_TOKEN when that option is available.
2. Obtain the Model ID
After entering the URL and Key, click Fetch Models. You can also copy a model ID using the button next to the model on the API Key page.
Use the exact model ID, not its display name. This guide does not maintain a fixed model list. A model appearing in the catalog does not establish that it supports the selected client's API and tools.
Claude Code: Configure Model Mapping
In the provider's Model Mapping section, set the Actual Request Model for the roles you will use, such as Sonnet, Opus, and Haiku. If your version includes Fable, Subagent, or a default/fallback model, configure those entries as needed too.
For the first test, map these roles and the default/fallback model to the same compatible B.AI model ID. After the connection works, assign different models to individual roles if needed.
Role names such as Sonnet and Opus are client roles; they do not mean the actual request must use a Claude model. Display Name changes the menu label, while Actual Request Model determines the model requested from B.AI.
Configuring only the visible main model can leave background or subagent requests using a different model. Do not enable a 1M context declaration unless it matches the selected model's supported context window.
Codex: Set the Default Model
Set Default Model to a compatible B.AI model ID. If your version provides a model mapping table, add the model there too so it can appear in Codex's model menu.
For your first connection, use a GPT model available to your API Key. For DeepSeek, follow the Codex integration guide, including disabling unsupported built-in web search.
3. Save, Enable, and Restart
Save the provider, return to the provider list for the same client, and click Enable on the B.AI card. Confirm that it is marked In Use.
Saving a provider is not the same as enabling it. Claude Code and Codex have separate provider configurations; enabling B.AI for one does not configure the other.
Start a new Claude Code session. For Codex, fully quit and reopen the application, or start a new CLI session, so it reloads the provider and model catalog.
To retain the official Codex sign-in while switching providers, follow the optional sign-in preservation steps in the Codex integration guide. Do not copy or share auth.json.
4. Verify an Actual Request
Send this prompt in the configured client:
Reply with exactly: B.AI connection successful
Next, create a local text file containing a short test phrase and ask the client to read that file using its file-reading tool or terminal, then return the contents. This checks tool use as well as basic text generation.
Check the related request, model, and usage on the B.AI Usage page. Do not rely solely on a successful model-list fetch or the model's self-description to establish that the integration works. Verification requests incur normal usage charges.
Troubleshooting
| Issue | What to Check |
|---|---|
| Models cannot be fetched | API URL, Key validity, connectivity, and account/model access. Confirm you are using the production URL and a production Key. |
| Models are listed, but requests fail | Verify the selected model supports Messages or Responses as required, plus client tool use; inspect the returned error. |
401 | Confirm the Key is valid and is entered in the intended client's provider. |
404 | Check the URL and upstream format; avoid duplicating /v1 or using a full request endpoint as the base address. |
| Model not found | Use an exact model ID available to your Key and check all model mappings, including background roles. |
| The previous provider is still used | Confirm B.AI is enabled for the correct client, restart it, and check for conflicting terminal environment variables or project settings. |
| An unexpected model appears in usage | Check Claude Code's role, subagent, and fallback mappings, as well as other sessions using the same Key. |