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

# Connect Codex through LiteLLM

> Use OpenAI Codex CLI with the Fortytwo API: Codex needs the Responses API, so run a local LiteLLM proxy that translates it to Chat Completions.

[Codex CLI ](https://github.com/openai/codex) speaks only the OpenAI Responses API. The Fortytwo API serves Chat Completions, so Codex connects through a local [LiteLLM ](https://docs.litellm.ai/) proxy that translates between the two. This setup needs Python and a terminal.

> [!NOTE]
>
> **Before you start:** create a Fortytwo API key and buy credits — see [Quickstart, step 1](https://docs.fortytwo.network/docs/quickstart.md#1-create-an-api-key). Give each agent its own key with a **Spend limit**.
>
> | Setting | Value |
> | - | - |
> | Base URL | `https://api.fortytwo.network/v1` |
> | Model ID | `qwen/qwen3.8-27b` |

**1. Install LiteLLM and Codex**

```bash theme={null}
pip install "litellm[proxy]"
npm install -g @openai/codex
```

**2. Configure LiteLLM**

Create `litellm.yaml`:

```yaml litellm.yaml theme={null}
model_list:
  - model_name: qwen/qwen3.8-27b
    litellm_params:
      model: custom_openai/qwen/qwen3.8-27b
      api_base: https://api.fortytwo.network/v1
      api_key: os.environ/FORTYTWO_API_KEY

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
```

Use the `custom_openai/` prefix: it makes LiteLLM translate Responses requests to Chat Completions.

**The master key** is a password for your local LiteLLM proxy; LiteLLM does not start without it. You do not get it anywhere: **make up any string that starts with `sk-`, or let the command in the next step create a random one**. Codex sends it to LiteLLM; LiteLLM sends your Fortytwo key to Fortytwo.

**3. Start LiteLLM**

```bash theme={null}
export FORTYTWO_API_KEY="<your Fortytwo key>"
export LITELLM_MASTER_KEY="sk-$(openssl rand -hex 24)"
echo $LITELLM_MASTER_KEY
litellm --config litellm.yaml --port 4000
```

The `echo` line prints the master key: copy it for the last step. Keep this terminal open while you use Codex.

**4. Configure Codex**

Add this to `~/.codex/config.toml`. The first three lines go at the top of the file, before any `[section]`; replace any `model` or `model_provider` lines already there.

> [!NOTE]
>
> `~` is your home folder. Folders that start with a dot, such as `.pi`, `.config` or `.codex`, are hidden. To show them: **Cmd+Shift+.** in Finder on macOS, **View** → **Show** → **Hidden items** in File Explorer on Windows, **Ctrl+H** in most Linux file managers.

```toml ~/.codex/config.toml theme={null}
model = "qwen/qwen3.8-27b"
model_provider = "fortytwo"
model_context_window = 262144

[model_providers.fortytwo]
name = "Fortytwo via LiteLLM"
base_url = "http://localhost:4000/v1"
env_key = "LITELLM_MASTER_KEY"
wire_api = "responses"
```

**5. Start Codex**

In a second terminal, set the same master key and start Codex in your project folder:

```bash theme={null}
export LITELLM_MASTER_KEY="<the master key from step 3>"
codex
```

Codex warns `Model metadata for qwen/qwen3.8-27b not found`. The warning does not affect requests.

More options: [Codex custom model providers ](https://learn.chatgpt.com/docs/config-file/config-advanced#custom-model-providers), [LiteLLM OpenAI-compatible endpoints ](https://docs.litellm.ai/docs/providers/openai_compatible).

***

Something not working with your agent, or using one we have not listed? Tell us in the platform: [Feedback](https://docs.fortytwo.network/docs/support.md#ideas-feedback-and-small-bugs) for ideas and small bugs, [Contact support](https://docs.fortytwo.network/docs/support.md#support-account-api-billing-credits-errors) if it blocks your work, or [Report a security issue](https://docs.fortytwo.network/docs/support.md#security-issue).


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