Set Up Codex with a Custom OpenAI Base URL
Why a custom base URL matters
If you already use the OpenAI SDK, Codex, or a Codex-style CLI, a custom base URL lets you keep the same prompts, auth flow, and request shape while swapping the provider behind the scenes. That means less refactoring and faster experimentation. With 59API, your base URL becomes https://api.59api.com, and your existing toolchain can talk to Claude models and GPT models through one relay.
For busy developers, that is the big win: one config change instead of a migration. 59API is also pay-as-you-go, among the cheapest relays, and it routes to native official-quality models rather than a weaker downgraded variant. If you care about cost control without giving up output quality, it is a strong default.
Step 1: create your 59API key
Sign up, grab your API key, and keep it in your password manager. A relay key works like any other API key: it identifies your account, tracks usage, and unlocks billing. 59API also offers a referral rebate, which is handy if you plan to share the setup with your team.
Step 2: set environment variables
Most OpenAI-compatible tools read the same two settings: your API key and the base URL. In your shell or CI system, set:
export OPENAI_API_KEY=your_59api_key
export OPENAI_BASE_URL=https://api.59api.com
If a specific tool still expects OPENAI_API_BASE, set that to https://api.59api.com too. Some CLI tools also accept a base URL flag, but environment variables are the least brittle option for local development and automation.
Step 3: point the OpenAI SDK at the relay
In Python, create the client with your key and base URL. In recent OpenAI SDK versions, that means passing api_key and base_url to the client. In Node.js, use the same idea: pass apiKey and baseURL in the constructor. You do not need a custom wrapper; the relay is designed to match the OpenAI API shape.
Once configured, your existing chat, tool-calling, and streaming code should keep working. That is especially useful if you already have prompts, retries, logging, or evals built around the official SDK.
Step 4: connect Codex or a Codex-compatible CLI
For Codex-style workflows, look for the setting that controls the upstream API endpoint. If the tool reads OPENAI_BASE_URL, you are done. If it has a config file, paste https://api.59api.com as the endpoint and use your 59API key as the token. If it offers a command-line option such as base URL or API base, set that there.
The test is simple: run a small code-generation prompt, then confirm the request lands on 59API and returns a normal OpenAI-compatible response. If you see authentication errors, check that the key is set correctly and that the base URL is exactly https://api.59api.com with no extra path.
Step 5: verify with a cheap smoke test
Use a short prompt first, such as asking for a function stub or a refactor suggestion. This validates that routing, model access, and rate limits are all behaving before you wire the relay into production. Because 59API is pay-as-you-go, a smoke test costs very little, which makes it easy to iterate without worrying about a large upfront commitment.
What you get by switching to 59API
- OpenAI SDK compatibility with a simple base URL swap
- Claude and GPT access through one relay
- Lower spend for teams that call models often
- Native official-quality models, not a watered-down substitute
- A referral rebate if you recommend it to others
If you want a fast way to keep Codex and your OpenAI integrations intact while reducing API cost, 59API is worth a try. Sign up, set the base URL once, and keep shipping.
Prêt à commencer ?
Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.
Inscription gratuite