Codex + OpenAI API: Custom Base URL Setup
1) Start with the relay URL, not a plugin
59API works as a drop-in OpenAI-compatible relay, so the first win is simple: point your app or CLI at https://api.59api.com and keep your existing workflow. You are not wiring up a custom integration; you are swapping the endpoint. That matters because Codex, Claude Code, and OpenAI SDKs usually care about two things only: an API key and a base URL. With 59API, you get low-cost pay-as-you-go access to native official-quality models, so you can keep quality high without paying flagship-only pricing. It is also one of the cheapest relays available, which makes it a smart default for everyday development.
- Store your 59API key in a secrets manager or local env file.
- Set the base URL to https://api.59api.com.
- Keep the rest of your code and prompts unchanged.
2) Set the right environment variables
For most OpenAI-compatible tools, the quickest setup is an environment variable. Use OPENAI_API_KEY for your 59API key. Then try OPENAI_BASE_URL or the SDK-specific equivalent such as OPENAI_API_BASE. Some apps prefer a config field named base_url. If your Codex setup reads from the shell, export both values before launching the session. The goal is to make every request leave through 59API without changing your prompts, tools, or agent behavior.
- Restart your terminal after changing env vars.
- Check for typo-level bugs in the URL; one wrong character can look like an auth issue.
- If the client still hits the default OpenAI endpoint, look for a separate config file that overrides env values.
3) Test with the smallest possible request
Before you let Codex chew through a large task, make one tiny request: ask for a one-sentence summary or a short JSON object. This confirms that authentication, routing, and model selection all work. A minimal test also tells you whether your tool is honoring the custom base URL, because failures usually show up immediately as connection errors, 401s, or model-not-found messages. 59API’s relay setup is a nice fit here because its pricing is pay-as-you-go, so quick tests cost very little.
- Verify you get a real model response, not a proxy error.
- Confirm streaming works if your tool relies on streamed tokens.
- Save the working config before you scale up to production tasks.
4) Match the model to the job
One of 59API’s biggest advantages is choice. You can work with Claude Opus, Sonnet, Haiku, Fable, and GPT models through one relay, then pick the right model for each task. Use lighter models for autocomplete, formatting, and quick edits. Reserve stronger reasoning models for architecture, debugging, or multi-step refactors. That split alone can lower costs fast. Because 59API uses native official-quality models rather than downgraded substitutes, you are optimizing spend without sacrificing the output your code assistant needs.
- Use smaller models for fast, repetitive work.
- Use larger models when correctness matters most.
- Keep a model fallback list in case a tool calls a specific name.
5) Configure Codex the same way you configure the SDK
If your Codex workflow supports an OpenAI-compatible endpoint, treat it like any other client: swap in the 59API base URL, add your key, and relaunch. If you are using a wrapper, editor plugin, or agent runner, look for fields like endpoint, API base, server URL, or provider URL. The exact label changes, but the principle stays the same. This is why relays are so useful: one configuration pattern unlocks multiple tools, including Codex and other OpenAI SDK-based apps.
- Look for provider settings in your Codex config file or launch command.
- Prefer environment variables when you want the setup to travel across machines.
- Keep a backup profile for direct OpenAI access if you need to compare behavior.
6) Watch your bill and use the rebate
Once everything is live, the real benefit of 59API shows up in daily use. You get cheap, pay-as-you-go access, so you only pay for what Codex actually consumes. That makes it easier to automate more tasks, run more experiments, and delegate more repetitive work to the model. If you are onboarding a team, the referral rebate is a useful extra perk too. It is a simple way to reduce long-term spend while keeping a single compatible endpoint for all your AI tooling.
- Track usage by project so you know which prompts are expensive.
- Retry only when necessary to avoid duplicate calls.
- Use the rebate if you expect to share 59API with teammates or clients.
If you want a lower-cost OpenAI-compatible setup that works cleanly with Codex, Claude Code, and standard SDKs, sign up for 59API, set the base URL to https://api.59api.com, and run your first test call today.
¿Listo para empezar?
Conecta Claude y GPT en minutos a los precios más bajos, sin recortes. Regístrate para obtener tu clave API.
Registro gratis