How to use Codex with a cheaper API (OPENAI_BASE_URL guide)
Updated June 10, 2026
OpenAI’s Codex hit 3 million weekly active users in 2026 — and for heavy users, the API cost is the main friction. Because Codex speaks the standard OpenAI API, you can route it through a cheaper, OpenAI-compatible gateway by changing one environment variable.
This guide shows how to use Codex with a cheaper API while keeping the real GPT models.
How it works
Codex sends requests to whatever OPENAI_BASE_URL points to. Point it at a unified gateway like nexinfer and your requests go to the same models at a lower price — with published multipliers and zero request logging.
Setup (2 steps)
1. Set the base URL and key
export OPENAI_BASE_URL=https://api.nexinfer.com/v1
export OPENAI_API_KEY=sk-nexinfer-xxxx # your nexinfer key
Add them to your shell profile (~/.zshrc / ~/.bashrc) to persist.
2. Run Codex as usual
codex
Same workflow, lower cost. Streaming and tool calls are untouched.
Using the OpenAI SDK directly
If you call the API from code, only the base_url changes:
from openai import OpenAI
client = OpenAI(
base_url="https://api.nexinfer.com/v1",
api_key="sk-nexinfer-xxxx",
)
resp = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": "Hello"}],
)
What to check in a gateway
- Real models —
gpt-5meansgpt-5, not a cheaper stand-in. - Transparent billing — no hidden routing markup (some gateways quietly add 5%).
- No logging — your prompts and key stay yours.
Frequently asked questions
Will my existing OpenAI code work unchanged?
Yes — it’s the standard OpenAI API. Only base_url and the key change.
Does it support GPT-5 and the mini models? Yes, plus Claude, Gemini and more through the same endpoint.
How much can I save? Up to ~35% versus official list price on GPT models — check live rates on the pricing section.
Try it in 2 minutes
Point your tool at nexinfer and get $3 in free credits — real models, transparent billing, zero logging.
Start free →