OpenAI Codex
OpenAI Codex is OpenAI's agentic coding tool. You can configure it to use Vercel AI Gateway, enabling you to:
- Route requests through multiple AI providers
- Monitor traffic and spend in your AI Gateway Overview
- View detailed traces in Vercel Observability under AI
- Use any model available through the gateway
Configure Codex to use AI Gateway through its configuration file for persistent settings.
Follow the installation instructions on the OpenAI Codex repository to install the Codex CLI tool.
Set your AI Gateway API key in your shell configuration file, for example in
~/.zshrcor~/.bashrc:export AI_GATEWAY_API_KEY="your-ai-gateway-api-key"After adding this, reload your shell configuration:
source ~/.zshrc # or source ~/.bashrcOpen
~/.codex/config.tomland add the following:~/.codex/config.tomlmodel_provider = "vercel" model = "openai/gpt-5.5" [model_providers.vercel] name = "Vercel AI Gateway" base_url = "https://ai-gateway.vercel.sh/v1" env_key = "AI_GATEWAY_API_KEY"The configuration above:
- Sets up a model provider named
vercelthat points to the AI Gateway - References your
AI_GATEWAY_API_KEYenvironment variable - Sets the
vercelprovider as the default for all sessions - Specifies
openai/gpt-5.5as the default model
- Sets up a model provider named
Start Codex:
codexVercel AI Gateway routes your requests. To confirm, check your AI Gateway Overview in the Vercel dashboard.
Codex can stream Responses API traffic over a persistent WebSocket connection, reducing per-turn latency. Enable it in your config:
~/.codex/config.toml[features] responses_websockets_v2 = true [model_providers.vercel] name = "Vercel AI Gateway" base_url = "https://ai-gateway.vercel.sh/v1" env_key = "AI_GATEWAY_API_KEY" supports_websockets = trueTo use a different model, update the
modelfield in your config:~/.codex/config.tomlmodel = "anthropic/claude-sonnet-4.6" # Or try other models: # model = "google/gemini-3.1-flash-lite-preview" # model = "openai/gpt-5.5"Profiles let you switch models from the CLI. Create a file named
~/.codex/<profile-name>.config.tomlfor each profile, using top-level keys for the values that differ from your base config:~/.codex/fast.config.tomlmodel = "openai/gpt-5.4-nano"~/.codex/claude.config.tomlmodel = "anthropic/claude-sonnet-4.6"Codex loads
~/.codex/config.tomlfirst, then overlays the profile file, somodel_provider = "vercel"is inherited from your base config.Switch between profiles using the
--profileflag:codex --profile fast codex --profile claude
Was this helpful?