> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laozhang.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# CC Switch setup with LaoZhang API

> Add LaoZhang API to CC Switch and switch Claude Code, Codex, and Gemini CLI to it, with the model fields to change so every request goes through.

CC Switch is a desktop app that writes provider settings into the config files of Claude Code, Codex, Gemini CLI, and other coding tools, so you switch providers with one click instead of editing each file by hand.

| Item | Details |
| - | - |
| Where | Claude Code: Add Provider (+) → Custom Configuration. Codex and Gemini CLI: Add Provider (+) → Across apps → Universal providers → 自定义网关 |
| API URL | `https://api.laozhang.ai` |
| Tokens | `Claude Code` group for Claude Code, `default` group for Codex and Gemini CLI, both with the Usage first billing mode |
| Recommended models | Claude Code `glm-5.2` or `claude-sonnet-5-5`, Codex `gpt-6.1-sol`, Gemini CLI `gemini-3.8-flash` |
| Last verified | November 4, 2026, CC Switch v4.0.25 |

## Install CC Switch

CC Switch is open source under the MIT license and runs on macOS 12 or later, Windows, and Linux.

* **macOS**: run `brew install --cask cc-switch`, or download the `.dmg` from the GitHub releases page.
* **Windows**: download the MSI installer or the portable build.
* **Linux**: download the `.deb`, `.rpm`, or AppImage package. It needs glibc 2.35+ and WebKitGTK 4.1.

On first launch, CC Switch imports your current Claude Code, Codex, and Gemini CLI settings as a provider named `default`, so nothing you set up before is lost.

## Add LaoZhang API to all three tools

Claude Code needs a key in the `Claude Code` token group, while Codex and Gemini CLI need a key in the `default` group. A universal provider holds only one key, so add Claude Code as its own provider and let a universal provider cover Codex and Gemini CLI.

**1. Create two tokens**

In the [LaoZhang API console](https://api.laozhang.ai/token), create two tokens with the **Usage first** billing mode and copy both keys:

* One in the `Claude Code` group, for Claude Code.
* One in the `default` group, for Codex and Gemini CLI.

**2. Add a provider for Claude Code**

Select **Claude Code** in CC Switch's sidebar, click **Add Provider** (+) at the top right, and choose **Custom Configuration**. Enter a name such as "LaoZhang API", the endpoint `https://api.laozhang.ai`, and your `Claude Code`-group key, then fill in Model Mapping with IDs from [Choose models](#choose-models). The full field list is under [Claude Code](#claude-code) below. Click **Add**.

> [!WARNING]
>
> **Fill the Haiku row with a model LaoZhang API serves, such as `claude-haiku-5-5`.** Claude Code runs background tasks on the Haiku model, and `claude-haiku-4-5-20251001` or an empty row makes those requests fail with a 503. If you don't use Claude, enter `deepseek-v4-flash` or the same model as the other rows.

**3. Open the universal provider presets**

Select Codex or Gemini CLI in the sidebar and click **Add Provider** at the top right. In the category list on the left, under **Across apps**, open **Universal providers** and choose **自定义网关** (Custom gateway). This preset name appears in Chinese even when the interface is in English.

**4. Enter the address and key**

* **Name**: anything you like, such as "LaoZhang API"
* **API URL**: `https://api.laozhang.ai`
* **API Key**: your `default`-group key
* **Enabled Apps**: turn off Claude Code and leave Codex and Gemini CLI on

Enter the bare address once. CC Switch adds `/v1` for Codex on its own, as shown in the table below this procedure.

**5. Set the Codex and Gemini models**

Under **Model Configuration**, the form has one group per tool. Set the Codex model (and reasoning effort, if you like) and the Gemini model to models LaoZhang API serves; the values in [Choose models](#choose-models) work as they are. Claude Code is off in this provider, so its fields aren't used.

**6. Add and switch**

Click **Add**. CC Switch saves the provider and syncs it to Codex and Gemini CLI. Then, for each of the three tools, find the new LaoZhang API card in its provider list and click **Switch**. The card shows **In Use** when it's active.

Until you switch, each tool's card for `default` is marked **In Use**. That provider holds the settings CC Switch imported from your machine on first launch.

* Clicking **Switch** rewrites that tool's config file.
* Before the first rewrite, CC Switch backs up the original file to `~/.cc-switch/backups/live-first-write/`.
* Switching back to `default` restores your original setup.

**7. Restart and test**

Claude Code picks up the change right away. Codex and Gemini CLI read their config only at startup, so quit any running session and start a new one. Then send a test request from a terminal:

```bash theme={null}
claude -p "Reply with exactly one word: connected"
codex exec --skip-git-repo-check "Reply with exactly one word: connected"
gemini -p "Reply with exactly one word: connected"
```

Each tool should print `connected`. Gemini CLI runs non-interactive prompts only in a trusted directory, so trust the directory in interactive mode first if it asks.

From one API URL, CC Switch writes these addresses:

| Tool | Address written | After switching |
| - | - | - |
| Claude Code | `https://api.laozhang.ai` | Takes effect immediately |
| Codex | `https://api.laozhang.ai/v1` | Restart Codex |
| Gemini CLI | `https://api.laozhang.ai` | Restart Gemini CLI |

All three tools call LaoZhang API directly in their native protocols: Anthropic Messages, the OpenAI Responses API, and native Gemini. You don't need CC Switch's local routing.

## Add a provider for one tool

Claude Code always uses this path. Use it for Codex or Gemini CLI too when you set up a single tool or need more fields than a universal provider shows: select the tool at the top of CC Switch, click **Add Provider** (+), and choose **Custom Configuration**. Fill in the fields below, click **Add**, then click **Switch** on the new card.

### Claude Code

* **API Endpoint**: `https://api.laozhang.ai`, with no trailing slash. CC Switch writes it to `ANTHROPIC_BASE_URL`.
* **API Key**: your `Claude Code`-group key.
* **Auth Field**: keep the default, `ANTHROPIC_AUTH_TOKEN`.
* **Upstream Format**: keep **Anthropic Messages (Native)**. The other formats need local routing, which LaoZhang API doesn't require.
* **Model Mapping**: fill in the requested model for the Sonnet, Opus, Fable, and Haiku rows, plus Subagent if you use it. Each tier row becomes an `ANTHROPIC_DEFAULT_*_MODEL` variable, such as `ANTHROPIC_DEFAULT_FABLE_MODEL`, and Subagent becomes `CLAUDE_CODE_SUBAGENT_MODEL`.
* **Default fallback model**: the model Claude Code starts with, written to `ANTHROPIC_MODEL`.

Don't leave the Haiku row empty. An empty row makes Claude Code send its original Claude model name, which LaoZhang API may not offer. Use `claude-haiku-5-5`, or `deepseek-v4-flash` if you don't use Claude. To pick IDs from a list instead of typing them, click **Fetch Models** after entering the endpoint and key.

### Codex

* **API Request URL**: `https://api.laozhang.ai/v1`. CC Switch writes it to `base_url` under `[model_providers.custom]` in `~/.codex/config.toml`.
* **API Key**: your `default`-group key. CC Switch stores it in `config.toml` as `experimental_bearer_token`, not in `auth.json`.
* **Upstream Format**: keep **OpenAI Responses API (Native)**, which sets `wire_api = "responses"`.
* **Default Model**: `gpt-6.1-sol`, or another model from the table in [Choose models](#choose-models).

Restart Codex after switching.

### Gemini CLI

Enter `https://api.laozhang.ai` as the address, your `default`-group key, and a model such as `gemini-3.8-flash`. When you switch, CC Switch writes:

* `GOOGLE_GEMINI_BASE_URL`, `GEMINI_API_KEY`, and `GEMINI_MODEL` to `~/.gemini/.env`
* the Gemini API key sign-in method and the model name to `~/.gemini/settings.json`

Restart Gemini CLI after switching.

### Check the endpoint

Click **Manage & Test** next to the request address to measure response times. **Connectivity check** only confirms that the address returns an HTTP response; it doesn't check your key. Use the test commands above to confirm the key works.

## Choose models

Enter the Claude Code IDs in Claude Code's custom configuration, and the Codex and Gemini CLI IDs in the universal provider's **Model Configuration** or in each tool's custom configuration. Use the Claude column or the GLM-5.2 column for Claude Code, not a mix.

| Field | Claude models | GLM-5.2 |
| - | - | - |
| Claude Code main model | `claude-sonnet-5-5` | `glm-5.2` |
| Claude Code Sonnet | `claude-sonnet-5-5` | `glm-5.2` |
| Claude Code Opus | `claude-opus-5-5` | `glm-5.2` |
| Claude Code Fable | `claude-fable-5-1` | `glm-5.2` |
| Claude Code Haiku | `claude-haiku-5-5` | `glm-5.2` |
| Codex model | `gpt-6.1-sol` | `gpt-6.1-sol` |
| Gemini CLI model | `gemini-3.8-flash` | `gemini-3.8-flash` |

* Fill the Fable row in Claude Code's Model Mapping as well.
* For lower-cost coding in Claude Code, `deepseek-v4-pro` works in place of `glm-5.2`, with `deepseek-v4-flash` on the Haiku row.
* Claude models return at most 32,768 output tokens per response. Other Claude Code notes are in the [Claude Code guide](https://docs.laozhang.ai/en/scenarios/programming/claude-code.md#use-claude-models).
* Prices are in the [model catalog](https://docs.laozhang.ai/en/models.md).

## Other tools CC Switch manages

CC Switch also manages Claude Desktop and Grok Build, which use one provider at a time like the three tools above. OpenCode, OpenClaw, Hermes, Pi, MiniMax Code, Kimi Code, and Oh My Pi can keep several providers side by side. For these tools, add LaoZhang API with **Custom Configuration** under that tool. A universal provider syncs only to Claude Code, Codex, and Gemini CLI.

Use a `Claude Code`-group key for providers that send Anthropic Messages requests and a `default`-group key for OpenAI-compatible ones.

## FAQ

### CC Switch shows "Environment Variable Conflicts Detected"

CC Switch shows this banner when your shell exports variables whose names start with `ANTHROPIC`, `OPENAI`, `GEMINI`, or `GOOGLE_GEMINI`. Whether they cause a problem depends on the tool.

**Claude Code**: values CC Switch writes to `settings.json` take precedence over shell variables with the same name, so those are usually harmless. These still send requests elsewhere:

* `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX`, or `CLAUDE_CODE_USE_FOUNDRY` set in your shell. Unset them and remove them from your shell profile.
* A base URL or token in the project's `.claude/settings.json` or `.claude/settings.local.json`. Project settings take precedence, so remove those keys.

**Gemini CLI**: when it loads `~/.gemini/.env`, Gemini CLI keeps variables that already exist in the shell. An exported `GOOGLE_GEMINI_BASE_URL` or `GEMINI_API_KEY` therefore overrides what CC Switch writes. If you followed the [Gemini CLI guide](https://docs.laozhang.ai/en/scenarios/programming/gemini-cli.md), your shell profile exports both.

To fix it, remove those lines from `~/.zshrc`, `~/.bashrc`, or your Windows environment variables, then open a new terminal.

### Claude Code returns a 503 "no available channels"

Check the Haiku model first. If it's still `claude-haiku-4-5-20251001` or empty, Claude Code's background tasks request a model LaoZhang API doesn't offer. Set it to a model from [Choose models](#choose-models). If the error persists, check that Claude Code's token is in the `Claude Code` group; see [model availability](https://docs.laozhang.ai/en/faq/model-availability.md).

### Codex config differs from the Codex CLI guide. Does it matter?

No, both work.

* The [Codex CLI guide](https://docs.laozhang.ai/en/scenarios/programming/codex-cli.md) adds a provider named `laozhang` and reads the key from an environment variable through `env_key`.
* CC Switch sets `model_provider = "custom"` and stores the key in `config.toml` itself.

Switching to the `default` provider in CC Switch restores the config you had before.

### Connectivity check passes, but requests return a 401

Connectivity check doesn't validate the key. Copy the full key again from the [console](https://api.laozhang.ai/token), save the provider, and switch to it again. Also check for conflicting shell variables as described above. See [Invalid API key or 404](https://docs.laozhang.ai/en/faq/invalid-api-key.md).

### I changed the model with /model, but CC Switch still shows the old one

Changes made inside Claude Code, Codex, or Gemini CLI with `/model` aren't written back to CC Switch. To change the default model for good, edit the provider in CC Switch and switch to it again.

## Related pages

* [Integrations overview](https://docs.laozhang.ai/en/scenarios.md)
* [Claude Code setup with LaoZhang API](https://docs.laozhang.ai/en/scenarios/programming/claude-code.md)
* [Codex CLI setup with LaoZhang API](https://docs.laozhang.ai/en/scenarios/programming/codex-cli.md)
* [Gemini CLI setup with LaoZhang API](https://docs.laozhang.ai/en/scenarios/programming/gemini-cli.md)
* [Call logs](https://api.laozhang.ai/log)
* [CC Switch on GitHub](https://github.com/farion1231/cc-switch)
* [CC Switch website](https://ccswitch.io)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.