---
title: "Codex via Gateway"
description: "Configure Codex to use Vercel AI Gateway as a custom model provider, select a Gateway model, and keep the credential value out of the Codex configuration file."
canonical_url: "https://vercel.com/academy/ai-gateway/codex-with-gateway"
md_url: "https://vercel.com/academy/ai-gateway/codex-with-gateway.md"
docset_id: "vercel-academy"
doc_version: "1.0"
last_updated: "2026-10-16T22:23:25.033Z"
content_type: "lesson"
course: "ai-gateway"
course_title: "Using AI Gateway in Production"
prerequisites:  []
---

<agent-instructions>
Vercel Academy — structured learning, not reference docs.
Lessons are sequenced.
Adapt commands to the human's actual environment (OS, package manager, shell, editor) — detect from project context or ask, don't assume.
The lesson shows one path; if the human's project diverges, adapt concepts to their setup.
Preserve the learning goal over literal steps.
Quizzes are pedagogical — engage, don't spoil.
Quiz answers are included for your reference.
</agent-instructions>

# Codex via Gateway

# How Do I Run Codex Through the Gateway?

Codex supports custom model providers. A small configuration block gives it the Gateway endpoint and the name of the environment variable that holds your key.

\*\*Note: Quick Answer\*\*

Add a Vercel provider to the Codex configuration with the Codex endpoint `https://ai-gateway.vercel.sh/codex/v1`, `AI_GATEWAY_API_KEY` as its `env_key`, and `wire_api = "responses"`. Select that provider and a current Gateway model, then start Codex normally.

## Outcome

Run one read-only Codex task through a custom AI Gateway provider without storing the key in `config.toml`.

## Fast Track

1. Put the Gateway key in `AI_GATEWAY_API_KEY`
2. Add the provider block below to the Codex configuration
3. Start Codex in a throwaway repository and run a small task

## Hands-on exercise

Add a Vercel provider to `~/.codex/config.toml` for a personal default, or to `.codex/config.toml` in a trusted repository for a project-specific setting. Check the current Gateway catalog before choosing a model because model IDs change over time.

```toml filename="config.toml"
model_provider = "vercel"
model = "openai/gpt-5.6-sol"

[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 `/codex/v1` endpoint also serves the model list Codex reads at startup, so the full Gateway catalog shows up in the CLI. Current Codex versions only speak the Responses API, which is why `wire_api` is set to `responses`.

The file contains the environment variable's name, not its value. Set the real key in the shell or secret manager that starts Codex.

## Try It

Open Codex in a throwaway repository containing `demo.ts`, then ask:

```text
Explain demo.ts in three bullets. Do not modify anything.
```

Codex should complete the task with the configured provider. If startup fails, verify the TOML structure, confirm that `AI_GATEWAY_API_KEY` exists in the launching environment, and check that the selected model is still in the Gateway catalog.

## Done-When

- [ ] Codex starts with the Vercel provider selected
- [ ] The selected model exists in the current Gateway catalog
- [ ] Codex completes the read-only task
- [ ] The key value does not appear in `config.toml`, source control, or terminal output

## Solution

The provider block above is the complete Codex configuration. The file identifies the Gateway endpoint and credential variable while the launching environment supplies the secret.

## Related Questions

- [How do I run OpenCode through the Gateway?](/ai-gateway/stay-aware/opencode-with-gateway)
- [How do I run Claude Code through the Gateway?](/ai-gateway/stay-aware/claude-code-with-gateway)
- [How do I see where my money is going?](/ai-gateway/stay-aware/see-your-spend)


---

[Full course index](/academy/llms.txt) · [Sitemap](/academy/sitemap.md)
