> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.fabricgateway.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.fabricgateway.ai/_mcp/server.

# Use Codex with Fabric AI Gateway

> Send Codex traffic through a Fabric AI Gateway route and confirm that requests arrive.

You can send OpenAI Codex traffic through Fabric AI Gateway by adding the gateway as a model provider in Codex's `config.toml` file and passing a gateway key as a custom header. The gateway then applies your plugins to Codex requests, and you can review them in the console. This topic shows you how to configure Codex and confirm that requests arrive.

## Prerequisites

Before you begin, make sure you have the following:

* Codex installed on your computer.
* A route for an OpenAI connection. For the steps, see [Connect an LLM provider](/fabric/gateways/llm-providers).
* A gateway key for the route. The gateway reads it from the `fg-api-key` header. For more information, see [Authenticate requests with Key Auth](/fabric/plugins/key-auth).

## Configure Codex to use the gateway

Codex reads its settings from `~/.codex/config.toml`. To configure Codex, do the following:

1. In the Fabric console, select **LLMs** > **Routes**, find your OpenAI route, and then select **Copy LLM base URL**.

2. Set your gateway key in an environment variable, for example in your shell profile:

   ```bash
   export FABRIC_GATEWAY_KEY="GATEWAY_KEY"
   ```

3. Open `~/.codex/config.toml`, and add the gateway as a model provider:

   ```toml
   model_provider = "fabric"

   [model_providers.fabric]
   name = "Fabric AI Gateway"
   base_url = "BASE_URL"
   wire_api = "responses"
   env_http_headers = { "fg-api-key" = "FABRIC_GATEWAY_KEY" }
   ```

4. Replace `GATEWAY_KEY` with your gateway key and `BASE_URL` with the URL that you copied, ending in `/v1`.

5. Restart Codex.

The settings do the following:

* `model_provider` makes Codex use the provider that you define.
* `base_url` sends requests to the gateway route instead of the OpenAI API.
* `wire_api = "responses"` makes Codex use the OpenAI Responses API format.
* `env_http_headers` adds the gateway key to each request, using the value of the `FABRIC_GATEWAY_KEY` environment variable. This keeps the key out of the file.

> **Warning**
>
> Treat the gateway key as a secret. Don't put it in a config file that you commit.

The gateway supplies the OpenAI credential. It adds the API key saved on the connection when it forwards requests to OpenAI, so Codex doesn't need an OpenAI key. Use a model that the connection allows.

## Confirm that requests pass through the gateway

To confirm that Codex uses the gateway, do the following:

1. In Codex, send a message, for example `Hello, is this working?`.
2. In the Fabric console, select **Admin**, and then select **Traces**.
3. Find the requests from your user on the route.

## Next steps

* Add a rate limit to the route. For the steps, see [Control traffic with plugins](/fabric/plugins).
* Add fallback routing, so Codex keeps working when a provider returns errors. For the steps, see [Adaptive Model Routing and Provider Failover](/fabric/plugins/routing).
* Review token usage and estimated cost by model on the **LLM** tab of [Review analytics](/fabric/observability/analytics).