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

# Codex Integration

> Connect Codex to AiToEarn through cc-switch

This guide shows how to use cc-switch to connect Codex to AiToEarn's OpenAI Chat Completions compatible endpoint. It is useful when Codex expects a Responses API style flow, while you want to use AiToEarn language model access.

<Info>
  If you do not have an API Key yet, read [Get API Key](/en/use/api-key) first.
</Info>

<Warning>
  Your API Key is a private credential. Do not expose the full key in configuration screenshots, support messages, or shared logs.
</Warning>

## Before You Start

Prepare the following:

1. [AiToEarn API Key](/en/use/api-key).
2. A working Codex installation.
3. cc-switch. Download the version for your operating system from [cc-switch releases](https://github.com/farion1231/cc-switch/releases).

AiToEarn API Keys are bound to the site where they were created. Use the matching endpoint:

| Site               | OpenAI Chat Completions endpoint              |
| ------------------ | --------------------------------------------- |
| China site         | `https://aitoearn.cn/api/ai/chat/completions` |
| International site | `https://aitoearn.ai/api/ai/chat/completions` |

To confirm available model names, check [Chat models](/api-reference/get-api-ai-models-chat).

## Configure cc-switch

Open cc-switch and switch the top mode to `codex`.

<img src="https://mintcdn.com/aitoearn/pY62Y-DX5g2UwMNe/assets/use/codex/01.png?fit=max&auto=format&n=pY62Y-DX5g2UwMNe&q=85&s=ffd1cc9a79780acf770b4d779144fd45" alt="Switch cc-switch to codex" width="1353" height="935" data-path="assets/use/codex/01.png" />

Click the create button to add a new provider.

<img src="https://mintcdn.com/aitoearn/pY62Y-DX5g2UwMNe/assets/use/codex/02.png?fit=max&auto=format&n=pY62Y-DX5g2UwMNe&q=85&s=fc340140e22a3591a8aadd6e7effec13" alt="Create a provider configuration" width="1350" height="925" data-path="assets/use/codex/02.png" />

Keep the default custom configuration type. Scroll down and fill in:

* Provider name: use `aitoearn` so it is easy to recognize.
* API Key: paste the API Key created in AiToEarn.
* API request URL: enter the OpenAI Chat Completions endpoint that matches your API Key site.

Then open the advanced options and enable local route mapping.

<img src="https://mintcdn.com/aitoearn/pY62Y-DX5g2UwMNe/assets/use/codex/03.png?fit=max&auto=format&n=pY62Y-DX5g2UwMNe&q=85&s=703bc60c8ea87ea242c1d8b99a3cb853" alt="Fill AiToEarn provider settings and enable local routing" width="1858" height="819" data-path="assets/use/codex/03.png" />

Save the configuration.

## Enable the Provider

Return to the provider list and enable the AiToEarn configuration you just created.

<img src="https://mintcdn.com/aitoearn/pY62Y-DX5g2UwMNe/assets/use/codex/04.png?fit=max&auto=format&n=pY62Y-DX5g2UwMNe&q=85&s=c663b9020d3af250e66cfd98559e1813" alt="Enable the AiToEarn provider" width="1343" height="944" data-path="assets/use/codex/04.png" />

Open settings.

<img src="https://mintcdn.com/aitoearn/pY62Y-DX5g2UwMNe/assets/use/codex/05.png?fit=max&auto=format&n=pY62Y-DX5g2UwMNe&q=85&s=676cb0812eacfa0d3898a156a9591614" alt="Open cc-switch settings" width="1349" height="969" data-path="assets/use/codex/05.png" />

Go to routing settings.

<img src="https://mintcdn.com/aitoearn/pY62Y-DX5g2UwMNe/assets/use/codex/06.png?fit=max&auto=format&n=pY62Y-DX5g2UwMNe&q=85&s=764182b313b792dfeb55cdd3c88e9873" alt="Open routing settings" width="1337" height="918" data-path="assets/use/codex/06.png" />

Enable routing. After this, cc-switch handles Codex requests locally and forwards them to the AiToEarn endpoint you configured.

<img src="https://mintcdn.com/aitoearn/pY62Y-DX5g2UwMNe/assets/use/codex/07.png?fit=max&auto=format&n=pY62Y-DX5g2UwMNe&q=85&s=d17faabf3edbf8edc47f4ec10ed4a93e" alt="Enable Codex routing" width="1332" height="948" data-path="assets/use/codex/07.png" />

## Verify the Setup

Keep cc-switch running, then open Codex and send a simple message. If Codex returns a normal response, it is using AiToEarn through cc-switch.

If the request fails, check:

* Whether the API Key belongs to the site used in the request URL.
* Whether the API request URL matches the API Key site.
* Whether the AiToEarn provider is enabled.
* Whether cc-switch Codex routing is enabled.
* Whether the Codex model name comes from [Chat models](/api-reference/get-api-ai-models-chat).
