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

# CodeX/ChatGPT

> Connect the Codex desktop app to HaiToken through CC Switch

You can use CC Switch to configure a HaiToken provider for the Codex desktop app. CC Switch generates the model configuration required by Codex and forwards requests through a local routing service.

<Info>
  The demo in this guide uses CC Switch **V3.19.2**. If the configuration in your version differs from this guide, check which version you are using.
</Info>

<Info>
  Connecting to HaiToken does not require phone-number verification or other additional verification methods. You only need a HaiToken API key to complete the setup in this guide.
</Info>

## Prerequisites

* The Codex desktop app and CC Switch installed
* A HaiToken API key
* At least one available GPT model provided by HaiToken

## Setup steps

### Step 1: Open the Codex provider page

Open CC Switch, select the **Codex** icon in the top application bar, and click **+** in the top-right corner.

<img src="https://mintcdn.com/hai-token/Irv8Su8BDgYyiSBJ/images/codex/PixPin_2026-08-07_11-51-13.png?fit=max&auto=format&n=Irv8Su8BDgYyiSBJ&q=85&s=05cf5b79286502cb002a7176f532435d" alt="Select Codex in CC Switch and add a provider" width="1032" height="697" data-path="images/codex/PixPin_2026-08-07_11-51-13.png" />

### Step 2: Create a custom provider

Select **Custom configuration** on the **Add new provider** page, then complete these fields:

| Field           | Value                                                         |
| --------------- | ------------------------------------------------------------- |
| Provider name   | `HaiToken` or another recognizable name                       |
| API Key         | Your HaiToken API key                                         |
| API request URL | Leave **Full URL** off and enter `https://api.haitoken.ai/v1` |
| Default model   | Select an available GPT model provided by HaiToken            |
| Upstream format | **Responses(native)**                                         |

<img src="https://mintcdn.com/hai-token/iNall6Q5q6MqRig5/images/codex/step-2-en.png?fit=max&auto=format&n=iNall6Q5q6MqRig5&q=85&s=daf521247974f3e64e883b44a8d4f5c3" alt="Configure a custom HaiToken provider" width="2466" height="1358" data-path="images/codex/step-2-en.png" />

### Step 3: Fetch and configure models

Expand **Advanced options** and click **Fetch model list**. After CC Switch reports that it found models, click **Add model** and select the GPT model you want to use in Codex. To use more than one model, click **Add model** again and add each model separately.

After making your selections, confirm the default model and model mappings, then click **Add** in the bottom-right corner to save the provider.

<img src="https://mintcdn.com/hai-token/iNall6Q5q6MqRig5/images/codex/step-3-en.png?fit=max&auto=format&n=iNall6Q5q6MqRig5&q=85&s=3fe9f3d9b1bf2318c233a3bc82820a02" alt="Fetch models and add the provider" width="2467" height="947" data-path="images/codex/step-3-en.png" />

<Info>
  CC Switch uses the GPT models added here to generate the Codex model catalog. Codex displays the model name or its mapped name, which does not have to match the provider name.
</Info>

### Step 4: Select the model in Codex

If Codex is already open, restart the Codex desktop app so it loads the new provider and model catalog. Start a new conversation, open the model selector at the bottom of the input area, and select the model you configured.

<img src="https://mintcdn.com/hai-token/iNall6Q5q6MqRig5/images/codex/step-4-en.png?fit=max&auto=format&n=iNall6Q5q6MqRig5&q=85&s=ae95241eca15c6472e1d0f7b4bf1bc40" alt="Select the configured model in the Codex desktop app" width="1196" height="574" data-path="images/codex/step-4-en.png" />

The `gpt-5.4-h` label in the screenshot is an example. The options you see depend on the default model and model mappings configured in CC Switch.

<Info>
  The session history will be switched if you switch between different providers. You can enable the **Unified Codex session history** option in CC Switch to preserve the session history.
</Info>

<img src="https://mintcdn.com/hai-token/tnMO8ccDo_KmNCrV/images/codex/attention-en.png?fit=max&auto=format&n=tnMO8ccDo_KmNCrV&q=85&s=3e1af7fad39d82e5fb2f5e3ca22bdb9c" alt="Unified Codex session history" width="1593" height="1107" data-path="images/codex/attention-en.png" />

## Verify the connection

1. Select the HaiToken model in the Codex desktop app.
2. Send a test message.
3. If Codex returns a response, the connection is working.

## Troubleshooting

| Problem                                                | Resolution                                                                                                                        |
| ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
| The model list cannot be fetched                       | Confirm that the API request URL is `https://api.haitoken.ai/v1`, then check that the API key is valid.                           |
| `401` or authentication failed                         | Enter the HaiToken API key again, save the provider, and restart Codex.                                                           |
| `model not found`                                      | Make sure you added a GPT model provided by HaiToken, then check the model IDs in the default model and model mappings.           |
| The new model does not appear in Codex                 | Confirm that you saved the provider and enabled Codex routing, then fully quit and reopen Codex.                                  |
| Codex requests do not go through HaiToken              | Confirm that the upstream format is **Chat Completions**, then check both the **Master routing switch** and the **Codex** switch. |
| A changed service address or port does not take effect | Restart the CC Switch routing service, then restart Codex.                                                                        |

## Next steps

* See [Get an API key](/docs/en/quickstart/get-api-key)
* See [OpenAI format API](/docs/en/api-reference/chat/openai-format)
* See [List models](/docs/en/api-reference/models/list-models)
