GPT-5.3-Codex is now available! You can access GPT-5.3-Codex through TrueFoundry AI Gateway. Follow the setup steps below to get started.
What is Codex?
Codex is the official command-line interface (CLI) tool for OpenAI, providing a streamlined way to interact with OpenAI’s language models directly from your terminal. With TrueFoundry LLM Gateway integration, you can route your Codex requests via Gateway.Key Features of OpenAI Codex CLI
- Terminal-Native AI Interactions: Chat with AI models directly from your terminal without switching contexts
- Intelligent Code Generation: Generate code snippets, functions, and programs across multiple programming languages using natural language prompts
- Streaming and Interactive Sessions: Real-time streaming responses enable dynamic, conversation-like interactions for code development
Prerequisites
Before integrating Codex with TrueFoundry, ensure you have:- TrueFoundry Account: Create a TrueFoundry account with at least one model provider and generate a Personal Access Token by following the instructions in Generating Tokens. For a quick setup guide, see our Gateway Quick Start
- Codex Installation: Install the Codex CLI on your system
- Virtual Model: Create a Virtual Model for each Codex model you want to use (see Create a Virtual Model below)
Why You Need a Virtual Model
Codex has internal logic that sends thinking tokens to certain models during processing. This works correctly with standard OpenAI-style model names (likegpt-5), but causes compatibility issues with TrueFoundry’s fully qualified model names (like openai-main/gpt-5 or azure-openai/gpt-5). When Codex sees a fully qualified name directly, it can send thinking tokens incorrectly, which leads to unexpected behavior.
Virtual Models fix this by letting you:
- Use a slug as the model name in Codex (e.g.
gpt-5orgpt-5.2-codex) so thinking tokens work as intended. - Have the TrueFoundry AI Gateway map that slug to the fully qualified target (e.g.
openai-main/gpt-5) and route requests there.
Setup Process
1. Configure Codex
TrueFoundry supports both ways of authenticating Codex to OpenAI: a usage-based API key and sign in with your ChatGPT account (Personal, Business, or Enterprise subscription).
~/.codex/config.toml. Create this file (and the ~/.codex directory if needed) if it does not exist. Choose the tab that matches how you authenticate to OpenAI:
- API key — Authenticate to the AI Gateway with a TrueFoundry API key (usage-based OpenAI access).
- ChatGPT Business/Enterprise — Sign in with your ChatGPT subscription. Codex sends its ChatGPT credentials, which the AI Gateway forwards to OpenAI, while TrueFoundry authenticates you separately with
x-tfy-api-key.
- API key
- ChatGPT Business/Personal
Configure Codex with the following Replace
~/.codex/config.toml:{GATEWAY_BASE_URL} with your TrueFoundry AI Gateway Base URL (how to find it) and TFY_API_KEY with your TrueFoundry API key from Generating Tokens.model— The Virtual Model slug you create in step 2 (for examplegpt-5.2-codex). It must match that slug.model_provider— Must match the[model_providers.<name>]section name (truefoundryin this example).wire_api = "responses"— Use this forgpt-5.x-codexmodels so Codex uses the Responses API and thinking tokens behave correctly. For other models, usewire_api = "chat"(Chat Completions).[model_providers.truefoundry.http_headers]— SendsAuthorization: Bearer ...on every request using your TrueFoundry API key.

Get Base URL and Model Name from Unified Code Snippet
2. Create a Virtual Model
Create a Virtual Model so Codex can use a simple model name that the AI Gateway maps to your provider. Follow these steps:- Open the Virtual Model / Routing page in the TrueFoundry AI Gateway dashboard
-
Create a new Virtual Model and add a Slug. This slug is the name you will use in Codex (e.g.
gpt-5.2-codexorgpt-5).Use a slug that matches the actual model ID (e.g.gpt-5.2-codexfor GPT-5.2-Codex). Codex recognizes these IDs and enables the right features (e.g. thinking tokens) -
Set the target to the fully qualified model name (e.g.
openai-main/gpt-5.2-codex). You can use one target at 100% weight or add multiple targets with weights for load balancing.


gpt-5.2-codex and the target is openai-main/gpt-5.2-codex at 100% weight, then when you run codex chat --model gpt-5.2-codex, the AI Gateway routes that request to openai-main/gpt-5.2-codex.
Use the slug as the model name in Codex (e.g.
--model gpt-5.2-codex). Do not use the fully qualified name (e.g. openai-main/gpt-5.2-codex) in Codex; that can break thinking tokens and other behavior.Usage Examples
Use the virtual model slug you created (e.g.gpt-5.2-codex or gpt-5) with the --model flag so requests go through the TrueFoundry AI Gateway.
Basic usage
With options
gpt-5.2-codex with whatever slug you set in your Virtual Model.
Web search
Codex’s built-in web search is an OpenAI Responses hosted tool — the retrieval runs on OpenAI’s backend, and Codex only attaches it to requests that go to the default OpenAI provider. When Codex is pointed at a custommodel_provider (the TrueFoundry AI Gateway), Codex does not add the hosted web-search tool to the request, so web_search / --search has nothing to execute against (openai/codex#3851). Setting wire_api = "responses" fixes the inference protocol but does not restore the hosted tool.
The way to give Codex web search through the gateway is a TrueFoundry-governed MCP server. MCP tools run client-side in the Codex process (Codex calls the server’s URL directly), so they work no matter which model the gateway routes to — and routing web search through the TrueFoundry MCP Gateway keeps the search key and tool access server-side and centrally governed (auth, allow-listing, audit) instead of putting a vendor key on every developer’s machine.
Run a web-search MCP server — for example Tavily or Exa — behind the TrueFoundry MCP Gateway, then add it to ~/.codex/config.toml as a streamable-HTTP MCP server:
<mcp-server-name> with the slug of the server you registered on the gateway (for example tavily or exa); the table name (web-search) is just the local alias Codex uses. Codex authenticates each MCP server independently of the model provider, but you can reuse the same TrueFoundry token you use for inference — pass it in http_headers exactly like the [model_providers.truefoundry.http_headers] block above. To keep the token out of the config file, use bearer_token_env_var = "TFY_API_KEY" instead, which reads it from that environment variable at runtime. See Connect an MCP server from your IDE / client for the gateway MCP URL format and auth.
Disabling web search
Codex’s native web search is off by default through the gateway (see above). To keep it explicitly disabled — or to turn it off if you previously enabled it with--search or web_search = "live" — set the following in ~/.codex/config.toml:
[mcp_servers.<name>] block.
Understanding Virtual Model Routing
When you use--model <your-slug>, the AI Gateway routes the request according to that Virtual Model’s targets. With a single target at 100% weight, all traffic goes to that model.
You can also add multiple targets with weights in the Virtual Model (e.g. 70% to one provider, 30% to another). Example:
