Your developers use Claude Code. Some also use Codex. Each tool has its own account, its own billing and its own limits, so nobody can answer a simple question: what is our AI coding spend this month?
An AI gateway fixes that. Both agents send requests through one endpoint, and you get one place to manage keys, budgets and models. This guide shows how to connect Claude Code and Codex to one gateway, how to check it works, and what to watch for.
Why Use One AI Gateway for Coding Agents?
An LLM gateway is a proxy between your coding agent and the model provider. Claude Code’s documentation lists the benefits as centralized authentication and usage tracking across teams and projects.
For teams running more than one agent, a single gateway adds more:
| Direct to each provider | Through one gateway | |
|---|---|---|
| Keys | Separate accounts and keys per tool | One key per developer |
| Budgets | Provider-level limits only | Per-developer and per-team caps |
| Visibility | Two dashboards, two invoices | One view of spend by user, project and model |
| Model control | Each developer chooses | Set centrally |
| Key leakage risk | Provider keys on every laptop | Provider keys stay behind the gateway |
For the cost side of this, see our guide to controlling Claude Code costs across your team.
Before You Start
Check three things first:
- Format support. Each agent speaks one API format. Claude Code needs a gateway that exposes the Anthropic Messages format. Codex needs an OpenAI-compatible endpoint.
- Credentials. Get a base URL and an API key from your gateway. Create a separate key for each developer, so you can group usage by person and revoke one key without touching the rest. ngrok’s agent guide recommends the same.
- Current tools. Update Claude Code and Codex to recent versions before you begin.
Step 1: Connect Claude Code to the Gateway
Claude Code reads two environment variables. Replace the values with the ones from your gateway:
export ANTHROPIC_BASE_URL="https://YOUR-GATEWAY-URL"
export ANTHROPIC_AUTH_TOKEN="your-gateway-key"
If your gateway team doesn’t say which credential type to use, Claude Code’s gateway documentation points to ANTHROPIC_AUTH_TOKEN as the one to try.
To make the setting permanent, put the same two values in the env block of your Claude Code settings.json file. A project-level file affects only that project.
Step 2: Connect Codex to the Gateway
Codex supports custom model providers in its config.toml file, usually at ~/.codex/config.toml. Add the gateway as a provider:
model_provider = "gateway"
[model_providers.gateway]
name = "gateway"
base_url = "https://YOUR-GATEWAY-URL/v1"
env_key = "GATEWAY_API_KEY"
wire_api = "responses"
Then export your key and start Codex:
export GATEWAY_API_KEY="your-gateway-key"
codex
This follows the custom-provider pattern shown in this Codex gateway walkthrough. The wire_api = "responses" line appears in a gateway example from foojay. Use it only if your gateway supports the Responses API, and check your gateway’s docs if requests fail.
To test without changing your default, many gateways document a profile you opt into, for example codex --profile your-gateway-name. Merge’s coding-agent guide describes this approach.
Step 3: Verify Both Connections
Don’t roll out to a team until you’ve checked each agent:
- Start Claude Code and run
/status. Claude Code shows an “Anthropic base URL” line when a gateway is set, and no line means it is still going direct. - Start Codex and run
/statusto confirm the provider and model. - Run one small real task in each agent.
- Open your gateway dashboard and confirm both requests appear under the right developer key.
If the requests show up in your dashboard, you are connected.
Step 4: Add Budgets and Model Controls
A gateway is most useful once spend limits are in place. At minimum:
- Set a per-developer allowance, so one runaway session can’t drain the month.
- Add a shared team cap and alerts before the cap is hit.
- Control which models each key can use. Routine work rarely needs your most expensive model. See smart model routing for Claude Code.
- Plan for runaway agents. A forgotten loop or a leaked key can quietly drain a budget, as covered in how to stop runaway AI agent costs.
For setup patterns, see our guide to setting AI coding agent budgets by developer and team.
One Gateway Doesn’t Mean Any Model in Any Tool
A common surprise: each agent speaks one API format, and that limits which models it can reach. ngrok’s documentation notes that the Messages and Responses formats only reach providers that support them, so Claude Code works best with Claude models and Codex works best with OpenAI models.
Some gateways translate between formats to open this up. If you plan to run other models in either tool, test tool calling and file edits on a real task first. Our guide to running GLM 5.2 in Claude Code and Codex shows one working example.
Common Problems and Fixes
- Authentication errors in Claude Code. Try the other credential variable. Gateways differ on whether they expect a token or an API key.
- Models missing from the
/modelmenu. Claude Code can discover models from a gateway, but per its documentation it only lists IDs that start withclaudeoranthropic. Other names must be added manually through its model configuration settings. - Codex requests failing. Check that the base URL ends where your gateway expects (often
/v1) and thatwire_apimatches what the gateway supports. - No usage in the dashboard. The agent is probably still going direct. Run
/statusagain and check which environment is active in the terminal where you launched it.
Choosing a Gateway
You can run your own open-source gateway or use a managed one. See our comparison of Opviera vs LiteLLM for an honest look at the trade-offs, or the wider Claude Code cost management tools comparison.
Frequently asked questions
Can Claude Code and Codex use the same AI gateway?
Yes, if the gateway exposes the Anthropic Messages format for Claude Code and an OpenAI-compatible format for Codex. Many gateways support both.
How do I connect Claude Code to a gateway?
Set ANTHROPIC_BASE_URL to the gateway address and ANTHROPIC_AUTH_TOKEN to your gateway key, either in your shell or in the env block of settings.json.
How do I configure Codex to use a gateway?
Add a custom provider to config.toml with a base_url and an env_key, then set model_provider to that provider. Confirm the connection with /status.
Do I need a separate key for each developer?
It is strongly recommended. Separate keys let you track usage per person, set individual budgets, and revoke access without affecting anyone else.
Can I use any model in Claude Code or Codex through a gateway?
Not always. Each tool speaks one API format, which limits the models it can reach unless your gateway translates formats. Test tool calling before rolling out non-native models.
How do I know the gateway connection works?
Run /status in each tool, complete a small task, then confirm the request appears in your gateway dashboard under the right key.
Can a gateway set budgets for coding agents?
Yes. Most gateways support per-developer and team budgets, and some can hard-stop requests at the limit and alert you before you reach it.
Written by Chamod S.
One Gateway for Every Coding Agent
Connect Claude Code and Codex with one key. Set hard-stop budgets, track spend by developer and project, and control which models run. Start free with Opviera.
Keep reading
How to Set a Budget for Claude Code (Per User and Project)
Set daily or weekly caps in dollars, tokens, or sessions, per user and per project. Hard stops block spend before it goes over, and alerts warn you first.
Read article → How-to guideHow to Track Claude Code Usage by Developer and Project
See live cost per developer and per project by tagging every request to a user and a project. Stop guessing at one big bill, and charge costs back to the right team.
Read article → How-to guideHow to Run GLM 5.2 in Claude Code and Codex with Opviera AI
A step-by-step guide to running GLM 5.2 - an open-weight model near Opus benchmarks at a fraction of the cost - inside Claude Code and Codex, with one key, dashboard model control, and automatic usage tracking.
Read article →