← Back to Blog

How to Connect Codex to an OpenAI-Compatible Gateway

Zivv7 min read
CodexOpenAI-compatiblesetup

Codex uses the OpenAI-compatible protocol, so connecting it to Zivv is simple: replace the OpenAI base URL with Zivv and use a Zivv API key. The details that matter are key distribution, model choice, and troubleshooting.

Who This Is For

This guide is for:

  • Codex users who want lower API costs
  • Teams using both Claude Code and Codex
  • Tools that only support the OpenAI protocol but need access to more models

Zivv acts as a unified gateway. You can call through OpenAI-compatible endpoints, Anthropic-compatible endpoints, and manage the same keys in one place.

Basic Setup

Set two environment variables:

export OPENAI_BASE_URL=https://zivv.pro/v1
export OPENAI_API_KEY=sk-your-key-here
codex

Windows PowerShell:

$env:OPENAI_BASE_URL="https://zivv.pro/v1"
$env:OPENAI_API_KEY="sk-your-key-here"
codex

Note the /v1 path. OpenAI-compatible clients usually require it, while Claude Code's Anthropic endpoint uses the root domain. For complete examples, see the Codex CLI docs and OpenAI SDK guide.

Model Selection

Route by task:

TaskStrategy
Small edits, code explanationUse a low-cost general model
Multi-file refactorsUse a stronger reasoning/code model
Tests and documentationMid-tier models are usually enough
Architecture decisionsTemporarily upgrade to a top model

Do not default every task to the most expensive model. Use a general model first, then upgrade only when needed.

Team Key Distribution

The worst setup is one shared key copied everywhere. A better pattern:

  1. Create a team
  2. Give each member a separate key
  3. Create separate keys for automation
  4. Set daily or monthly budgets
  5. Review usage weekly

This separates Codex, Claude Code, CI jobs, and server-side API calls instead of mixing them into one bill.

Troubleshooting

401 or unauthorized The key is wrong, has extra whitespace, or has been disabled. Match the response against the error reference.

404 or model not found Check whether the model name is available for the key's group. Compare it with the model reference.

Requests still go to OpenAI OPENAI_BASE_URL is not active in the terminal that launches Codex.

Encoding issues in output Usually a terminal or log viewer issue, not an API issue. Test with a simple English prompt first.

Using Codex with Claude Code

Many developers use both:

  • Claude Code for long-context coding sessions
  • Codex for OpenAI-compatible tooling and automation
  • Zivv for unified keys, billing, and model access

This is cleaner than binding every tool to separate official accounts.

Conclusion

Codex integration comes down to two settings: OPENAI_BASE_URL=https://zivv.pro/v1 and a Zivv API key. Individuals can use it directly; teams should split keys by member and project from the start.