Skip to main content

How to Connect B.AI to Codex with CC Switch: Step-by-Step Visual Guide

This guide explains how to use a B.AI API key in Codex through CC Switch. After setup, Codex sends model requests to the B.AI Responses API.

  • Production API URL: https://api.b.ai/v1
  • Upstream format: Responses (native)
  • Recommended first model: gpt-5-mini
  • Screenshots: CC Switch 3.20.0 on macOS

Menu names may differ slightly in later CC Switch releases. The required B.AI endpoint and Responses protocol remain the same.

Before you begin

Make sure that you have:

  1. Installed Codex and completed the initial sign-in;
  2. Installed CC Switch from its trusted release channel;
  3. Created a valid B.AI production API key;
  4. Confirmed that your B.AI account has access to the model you want to use and has sufficient balance.

Treat your API key as a password. Never include it in screenshots, chat messages, support tickets, source code, or public repositories.

1. Use the English interface

In CC Switch, open Settings > General and select English under Language.

Select English as the CC Switch interface language

2. Keep the official Codex login

If you want to switch between B.AI and OpenAI Official, open Settings > General and enable Keep official login for direct switches under Codex App Enhancements.

Enable Keep official login for direct switches

When this option is enabled, Codex may continue to show your signed-in OpenAI account while B.AI is active. This is expected. The provider marked In Use in CC Switch determines where model requests are sent.

3. Add a Codex provider

Return to the CC Switch home page, select Codex in the application bar, and click the orange + button.

Under Codex Provider, select Custom Configuration.

Add a custom Codex provider

4. Enter the B.AI production settings

Complete the provider form with the following values:

FieldValue
Provider NameB.AI Production
Website URLhttps://b.ai/
API KeyYour B.AI production API key
API Request URLhttps://api.b.ai/v1
Full URLOff
Default Modelgpt-5-mini

Enter the B.AI production provider settings

The API key is masked after entry. Do not select the eye icon before taking a screenshot or sharing your screen. CC Switch may also show the key in the generated auth.json preview farther down the editor, so keep that section out of screenshots.

5. Select the native Responses protocol

Expand Advanced Options and set Upstream Format to Responses (native).

Select Responses native as the upstream format

B.AI supports the Responses API natively. Local routing or protocol conversion is not required for this provider.

Click Fetch Models to check the production URL, API key, and account access. A successful result confirms that CC Switch can reach B.AI. The number of returned models may change as the platform is updated.

6. Save and enable B.AI

Click Save. Back on the Codex provider page, locate B.AI Production and click Enable.

Enable the saved B.AI Production provider

The B.AI Production card becomes highlighted and displays In Use when the switch succeeds.

B.AI Production is active

CC Switch generates the Codex configuration automatically. The effective configuration is equivalent to:

model_provider = "custom"
model = "gpt-5-mini"

[model_providers.custom]
name = "custom"
wire_api = "responses"
requires_openai_auth = true
base_url = "https://api.b.ai/v1"

CC Switch manages the API key separately. Do not place a real key in documentation, project source code, or a committed config.toml file.

7. Restart and verify Codex

Completely quit and reopen Codex, or start a new Codex CLI session. This ensures that the provider configuration and model catalog are reloaded.

Send the following test prompt:

Reply with exactly: B.AI Codex connection successful

If Codex returns the requested text, the connection is working. You can also check the B.AI usage page to confirm that the request was processed by B.AI.

The production environment was validated with gpt-5-mini using model discovery, non-streaming Responses, SSE streaming Responses, and an end-to-end Codex request.

8. Change the model

Use gpt-5-mini for the first connection. After it works, edit the provider and select another model returned by Fetch Models.

The initial B.AI Responses model set includes:

  • gpt-5-mini
  • gpt-5-nano
  • gpt-5.2
  • gpt-5.4
  • gpt-5.4-mini
  • gpt-5.4-nano
  • gpt-5.4-pro
  • gpt-5.5
  • gpt-5.5-instant
  • gpt-5.6-luna
  • gpt-5.6-sol
  • gpt-5.6-terra

Model availability depends on your B.AI account, balance, and Codex version. B.AI Responses API support does not guarantee compatibility with every Codex release. For example, gpt-5.4-nano and gpt-5.5-instant were not compatible with Codex CLI v0.149.1. If a model fails in Codex, use another model returned by Fetch Models and verify it with your installed Codex version.

9. Switch back to OpenAI Official

To restore the official Codex provider, locate OpenAI Official and click Enable.

Enable OpenAI Official

The OpenAI Official card becomes highlighted after the switch.

OpenAI Official is active again

For Codex CLI, you can check the login state with:

codex login status

A signed-in official account normally returns:

Logged in using ChatGPT

Troubleshooting

IssueWhat to check
Models cannot be fetchedConfirm that the URL is https://api.b.ai/v1, the production key is valid, and the account has available balance.
401 UnauthorizedThe API key is missing, invalid, or belongs to a different environment. Make sure you are not using a staging key.
403 ForbiddenCheck the account status, balance, and model access.
Model not foundUse the exact model ID returned by Fetch Models and confirm that the model supports Responses.
Codex still uses the previous providerConfirm that the intended provider is highlighted in CC Switch, then fully restart Codex.
Codex still shows the official accountThis is expected when Keep official login for direct switches is enabled. Check the active provider in CC Switch.

Security recommendations

  • Download CC Switch only from a trusted release source;
  • Use separate API keys for different projects or environments;
  • Rotate keys regularly and revoke a key immediately if it may have been exposed;
  • Never copy, share, or manually edit ~/.codex/auth.json;
  • Keep API keys out of screenshots, logs, public repositories, and client installers.