Skip to Content

AI Gateway

Coding Agents


OpenAI Codex with AI Gateway

Run the Vercel CLI setup command for Codex:

Codex

  • 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

Copy page

OpenAI Codex is OpenAI's agentic coding tool. You can configure it to use Vercel AI Gateway, enabling you to:

npx vercelai-gatewaysetup--agentcodex


The command configures everything Codex needs to route through the gateway:

  • Provisions an AI Gateway API key, or reuses one you pass with --key
  • Writes ~/.codex/config.toml with a vercel model provider pointed at the Codex compatibility endpoint ( wire_api = "responses")
  • Exports AI_GATEWAY_API_KEY from a managed block in your shell startup file, backed by the macOS Keychain when available so the key stays out of plaintext config
  • Copies your existing Codex Desktop sessions across (see session migration)

Every file the command changes is backed up alongside as a .bak file. Pass --dry-run to preview the changes without writing them. For the full command reference, see vercel ai-gateway setup.

To configure every installed supported agent at once, run the command without --agent. It detects and configures each supported agent it finds:

Manual setup


codex

To verify the setup, run Codex:

Only needed on machines where you can't use the Vercel CLI. When you use the CLI, it handles key storage for you, exporting AI_GATEWAY_API_KEY from a managed block in your shell startup file that is backed by the macOS Keychain when available. The steps below do the same configuration by hand.

vercel ai-gatewaysetup

The gateway routes your requests. Confirm they appear in your AI Gateway Overview in the Vercel dashboard.

  1. Install OpenAI Codex CLIFollow the installation instructions on the OpenAI Codex repository to install the Codex CLI tool.
  2. Configure environment variablesSet your AI Gateway API key in your shell configuration file, for example in ~/.zshrc or ~/.bashrc: export AI_GATEWAY_API_KEY="your-ai-gateway-api-key"After adding this, reload your shell configuration:

    source~/.zshrc# or source ~/.bashrc

  3. Set up the Codex config fileOpen ~/.codex/config.toml and add the following:

    model_provider ="vercel"

    model ="openai/gpt-6-astra"

    [model_providers.vercel]

    name ="Vercel AI Gateway"

    base_url ="https://ai-gateway.vercel.sh/codex/v1"

    env_key ="AI_GATEWAY_API_KEY"

    wire_api ="responses"

    The configuration above:
    • Sets up a model provider named vercel that points to the Codex compatibility endpoint
    • References your AI_GATEWAY_API_KEY environment variable
    • Sets the vercel provider as the default for all sessions
    • Uses the Responses API, which is the only wire protocol current Codex versions support
    • Specifies openai/gpt-6-astra as the default model
  4. Run CodexStart Codex: codexVercel AI Gateway routes your requests. To confirm, check your AI Gateway Overview in the Vercel dashboard.

Enable WebSocket streaming

Codex can stream Responses API traffic over a persistent WebSocket connection, reducing per-turn latency. This uses AI Gateway's Responses API WebSocket mode. Enable it in your config:

[features]

responses_websockets_v2 =true

[model_providers.vercel]

name ="Vercel AI Gateway"

base_url ="https://ai-gateway.vercel.sh/codex/v1"

env_key ="AI_GATEWAY_API_KEY"

wire_api ="responses"

supports_websockets =true

Choose a different model

To start a session on a specific model, pass --model (or -m):

Run /model inside Codex to switch models without leaving your session. The picker lists the full gateway catalog and sets reasoning effort at the same time, because the Codex compatibility endpoint serves /codex/v1/models when the CLI starts.

You can reach our customer support team by emailing info@yourcompany.example.com, calling +1 555-555-5556, or using the live chat on our website. Our dedicated team is available 24/7 to assist with any inquiries or issues.

We’re committed to providing prompt and effective solutions to ensure your satisfaction.

We offer a 30-day return policy for all products. Items must be in their original condition, unused, and include the receipt or proof of purchase. Refunds are processed within 5-7 business days of receiving the returned item.

model ="openai/gpt-5.5-pro"

# Or try other models:

# model = "openai/gpt-5.4-mini"

# model = "openai/gpt-5.4-nano"


Every model in the gateway catalog works here, not only OpenAI ones. The examples stay on OpenAI models because Codex reads their metadata natively.


Define multiple profiles

Profiles let you switch models from the CLI. Create a file named ~/.codex/.config.toml for each profile, using top-level keys for the values that differ from your base config:

model ="openai/gpt-5.5-pro"

model ="openai/gpt-5.4-nano"

codex --profilepro

codex --profilefast

Switch between profiles using the --profile flag:

Codex loads ~/.codex/config.toml first, then overlays the profile file, so model_provider = "vercel" is inherited from your base config.

[profiles.] tables or the profile selector from config.toml. If you have legacy profile tables, move each one into its own ~/.codex/.config.toml file.


Keeping your Codex Desktop sessions

Codex records each session against the provider that served it, so switching to the gateway hides the sessions you created before the switch. To bring them across, re-run the Vercel CLI setup command:

vercel ai-gatewaysetup--agentcodex


The command copies each rollout file under sessions and archived_sessions to a new deterministic session ID with model_provider set to vercel. Originals are never moved, edited, or deleted, and re-running never duplicates a session it already copied. Pass --no-session-migration to skip the step, and decompress any .jsonl.zst sessions first, since compressed rollouts can't be rewritten. See session migration for details.

Point Codex at its own compatibility endpoint:

base_url ="https://ai-gateway.vercel.sh/codex/v1"


[model_providers.vercel]

Last updated September 13, 2026


Cross-link map: OpenAI Codex with AI Gateway (/docs/ai-gateway/coding-agents/openai-codex)From the Vercel docs graph (built 2026-09-21T05:26:59.511Z), spanning vercel.com docs + KB, nextjs.org, ai-sdk.dev, and other Vercel documentation sites. Full graph as JSON: https://vercel.com/docs/graph.jsonSemantically closest pagesCoding Agents and Chat Platforms with AI Gateway — Connect coding agents and chat platforms to AI Gateway. Configure Claude Code, Codex, Chatbox, Open WebUI, and more.OpenCode with AI Gateway — Connect OpenCode to AI Gateway with one CLI command, or configure it in-app.vercel ai-gateway — Manage AI Gateway resources from the Vercel CLI: API keys, budgets, routing rules, virtual models, models, leaderboards,GPT 5.2 Codex now available on Vercel AI GatewayClaude Code and Claude Agent SDK with AI Gateway — Connect Claude Code to AI Gateway with one CLI command, or configure it manually.This page links to (4)AI Gateway Authentication and BYOK — Authenticate AI Gateway requests with API keys or OIDC tokens, and configure bring your own key \(BYOK\) credentials forOpenAI Responses API with AI Gateway — Use the OpenAI Responses API with AI Gateway to generate text, call tools, stream tokens, and more across any supportedOpenAI Responses API WebSocket Mode with AI Gateway — Keep a persistent connection open across turns with the OpenAI Responses API over WebSocket through AI Gateway.vercel ai-gateway — Manage AI Gateway resources from the Vercel CLI: API keys, budgets, routing rules, virtual models, models, leaderboards,Pages that link here (5)By site: vercel-changelog (1) · vercel-docs (4)From vercel-changelogGPT 6 Astra now available on Vercel AI GatewayFrom vercel-docsCoding Agents and Chat Platforms with AI Gateway — Connect coding agents and chat platforms to AI Gateway. Configure Claude Code, Codex, Chatbox, Open WebUI, and more.Harbor with AI Gateway — Evaluate coding-agent harnesses with Harbor and AI Gateway. Choose a harness, configure its connection, and pass separatOpenAI Responses Compaction with AI Gateway — Compress long conversations into a single compaction item with the OpenAI Responses API through AI Gateway.vercel ai-gateway — Manage AI Gateway resources from the Vercel CLI: API keys, budgets, routing rules, virtual models, models, leaderboards,


Was this helpful?

wire_api must be responses. Codex removed Chat Completions support, and the gateway serves the Responses API at /v1/responses.