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

# Codex

> Configure Codex to use AI Gateway with an OpenAI-compatible API endpoint.

<img src="https://mintcdn.com/gpuhub/GEB8Gf9uDczdNFr-/images/ide-agents-codex-icon.png?fit=max&auto=format&n=GEB8Gf9uDczdNFr-&q=85&s=e58c40da00bcc781ce797aeb90912b10" alt="" width="96" height="96" data-path="images/ide-agents-codex-icon.png" />

Codex is a command-line coding assistant. You can route Codex requests through AI Gateway by configuring the OpenAI-compatible base URL and providing your API key.

<Note>
  Create or copy your API key from the console before starting Codex.
</Note>

## Recommended: Manage Config with cc switch

<img src="https://mintcdn.com/gpuhub/szsKW_2Y2u2gI8Hg/images/ide-agents-cc-switch-icon.png?fit=max&auto=format&n=szsKW_2Y2u2gI8Hg&q=85&s=0d2c1cc15db4daf4a8aee487b7e87506" alt="" width="96" height="96" data-path="images/ide-agents-cc-switch-icon.png" />

If you use multiple coding agents, consider using [**cc switch**](https://github.com/farion1231/cc-switch) or a similar profile manager to maintain separate configurations for Codex, Claude Code, and other tools.

<img src="https://mintcdn.com/gpuhub/GEB8Gf9uDczdNFr-/images/ide-agents-codex-cc-switch-01.png?fit=max&auto=format&n=GEB8Gf9uDczdNFr-&q=85&s=30fc41ca12d79c15ae2f6c6f15bb3498" alt="" width="2000" height="1300" data-path="images/ide-agents-codex-cc-switch-01.png" />

<img src="https://mintcdn.com/gpuhub/okogEM35aUTWSg4p/images/ide-agents-codex-cc-switch-02.png?fit=max&auto=format&n=okogEM35aUTWSg4p&q=85&s=845c6c670f91063d20b87f2de13a537f" alt="" width="1000" height="650" data-path="images/ide-agents-codex-cc-switch-02.png" />

## Configure the API Base URL

Set the OpenAI-compatible base URL before starting Codex.

```bash theme={null}
export OPENAI_BASE_URL=https://llm.gpuhub.com/api/v1
```

To make this persistent, add it to your shell profile.

```bash theme={null}
echo 'export OPENAI_BASE_URL=https://llm.gpuhub.com/api/v1' >> ~/.zshrc
```

## Start Codex

```bash theme={null}
codex
```

## Provide Your API Key

When Codex opens the authentication menu, choose `Provide your own API key`.

<img src="https://mintcdn.com/gpuhub/GEB8Gf9uDczdNFr-/images/ide-agents-codex-login-method.png?fit=max&auto=format&n=GEB8Gf9uDczdNFr-&q=85&s=4a470c00b86a2a4b67d2c5d98586af57" alt="" width="1000" height="360" data-path="images/ide-agents-codex-login-method.png" />

Paste your API key into the prompt and press Enter to save it.

<img src="https://mintcdn.com/gpuhub/GEB8Gf9uDczdNFr-/images/ide-agents-codex-api-key.png?fit=max&auto=format&n=GEB8Gf9uDczdNFr-&q=85&s=a5a011de01e254df8c5ec22cfb7c1143" alt="" width="1000" height="360" data-path="images/ide-agents-codex-api-key.png" />

## Start Using Codex

After configuration is complete, you can use Codex from the terminal for code generation, explanation, debugging, and refactoring tasks.
