Connect Claude Code and Codex
Route Claude Code and Codex model calls through the gateway, where your model access rules decide each one.
When you finish this page, Claude Code or Codex sends its model calls through the gateway, where your model access rules decide each one and Agent Trail records it.
Which clients can use which gateway
Anthropic's and OpenAI's own clients differ in what they let you route. Tool calls go through the MCP gateway, and model calls go through the AI gateway.
| Client | Tool calls | Model calls | Keeps your Claude or ChatGPT subscription |
|---|---|---|---|
| Claude Code, in the terminal, VS Code or JetBrains | Yes | Yes | Yes |
| Claude desktop app and claude.ai | Yes, as a connector | No | Not applicable |
| Claude desktop app, third-party inference mode | Yes | Yes | No |
| ChatGPT, in its chats | Yes, as a plugin | No | Not applicable |
| ChatGPT desktop app, Codex mode | Yes | Yes | Yes |
| Codex CLI | Yes | Yes | Yes |
The Claude desktop app sends its model calls to Anthropic while it's signed in to claude.ai. In third-party inference mode it doesn't sign in to claude.ai, so it can't keep your Claude subscription. ChatGPT's chats have no setting for where model calls go, but the desktop app's Codex mode does.
Create a key
The AI gateway authenticates an agent by a key you create for it, not by a provider API key. Open Agents › Add agent and select your agent. Answer What should Claude Code send through SecureAuth? with Tools and models or Models only, then select Create key on Create a key for Claude Code. Set up fills the key into the config that sends it and shows it only once, so copy it before you leave the page.

Set up Claude Code then shows the agent's config with the key and the gateway's base URL.
With an API key, Model in the line above the steps opens the model picker, which writes the model you pick into the config, and nothing is picked for you.
Where the agent can switch models itself, such as Claude Code with /model, the picker is optional and starts on the agent's own default.
Where the agent needs a model listed or set to start, the picker starts empty and the config shows <model> until you pick one.
For Claude Code and Codex, that's the config below.
When your organization has set up both a sign-in connection and an API-key provider, Use your subscription or an API key? picks between your own Claude subscription or ChatGPT subscription and an API key.

The MCP gateway refuses a key made for models only. The agent's MCP connection needs no key, because you sign in from the agent.
If your organization has no model provider that can serve the agent, admins see the two cards with models disabled, with a link to add one, and members see no question.
For an agent the catalog doesn't list, create the key on Custom agent. That key also works for the agent's MCP connection.
Point the agent at the gateway
To write the config by hand, copy the base URL from Enforcement Points › LLM Gateway in the console: the Anthropic-compatible base URL for Claude Code, the OpenAI-compatible base URL for Codex. The page's Connect tab is shown to people who can view agents and model providers.
-
Claude Code – add this to your user settings,
~/.claude/settings.json, not to a project's.claude/settings.json. If the file already has anenvblock, add the three lines to it.CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERYadds the models the gateway lets you call to/model.{ "env": { "ANTHROPIC_BASE_URL": "<Anthropic-compatible base URL>", "ANTHROPIC_AUTH_TOKEN": "<key>", "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1" } } -
Codex – merge this into
~/.codex/config.toml. Codex CLI and the ChatGPT desktop app's Codex mode both read it. Keepmodel_providerat the top of the file, above the first[table].model_provider = "secureauth" [model_providers.secureauth] name = "SecureAuth" base_url = "<OpenAI-compatible base URL>" wire_api = "responses" http_headers = { "X-SecureAuth-Token" = "<key>" }Pick a model that the connection serving the call offers.
New organizations start with an active Allow all models rule, and your model access rules decide each call. The gateway refuses a provider API key, with an error that says to use the key instead.
Autonomous agents
An autonomous agent, the one an admin sets up with Acts on its own, uses an API key. It can't use a personal Claude or ChatGPT sign-in: the gateway refuses a call that sends one beside the agent key, so send the key alone.
Keep a Claude or ChatGPT sign-in
With a sign-in connection, the agent keeps its own claude.ai or ChatGPT sign-in and sends the key in the X-SecureAuth-Token header.
Only Claude Code and Codex can do this.
The Claude desktop app can't, because its third-party inference mode has no claude.ai sign-in.
Anthropic refuses a Claude sign-in from any other agent, and a ChatGPT sign-in reaches only the Codex backend.
Every other agent needs an API key connection, and its What should … send through SecureAuth? question says so when your organization has only sign-in connections.
Unset ANTHROPIC_API_KEY or OPENAI_API_KEY, because the gateway doesn't pass provider API keys through.
-
Claude Code – replace the
ANTHROPIC_AUTH_TOKENandCLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERYlines withANTHROPIC_CUSTOM_HEADERS.{ "env": { "ANTHROPIC_BASE_URL": "<Anthropic-compatible base URL>", "ANTHROPIC_CUSTOM_HEADERS": "X-SecureAuth-Token: <key>" } } -
Codex – add
requires_openai_auth = trueto the same entry.model_provider = "secureauth" [model_providers.secureauth] name = "SecureAuth" base_url = "<OpenAI-compatible base URL>" wire_api = "responses" http_headers = { "X-SecureAuth-Token" = "<key>" } requires_openai_auth = trueWithout
requires_openai_auth = true, Codex drops the ChatGPT sign-in, and the call runs on your organization's API key connection.
Next steps
Your agent's model calls now go through the gateway, and each one appears in Agent Trail as a Model Call. Decide which models it can call in Model access rules.

