59API

← Back to all guides

Set Up Codex with a Custom OpenAI Base URL

Claude Code · EN · 2026-07-19

Why a custom base URL matters in 2026

If you are building with Codex or any OpenAI-compatible SDK, a custom base URL is one of the simplest ways to control cost, improve routing flexibility, and keep your stack portable. Instead of hard-coding direct provider endpoints, you point your client to an OpenAI-compatible relay and keep the rest of your code unchanged.

That is exactly why 59API is attractive for developers today. It is an AI API relay at https://api.59api.com that works with Codex, Claude Code, and any OpenAI SDK. You get pay-as-you-go access to official-quality models, including Claude and GPT families, without paying premium direct-provider pricing. For teams watching burn, that can make a real difference.

The basic setup pattern

The setup is the same whether you are using a terminal-based Codex workflow, a local dev tool, or the OpenAI Python or JavaScript SDK. You need two things:

For 59API, the base URL is https://api.59api.com. In most OpenAI-compatible clients, the field may be called base_url, api_base, or OPENAI_BASE_URL.

Step 1: create your relay account and get credentials

Sign up for 59API, generate your API key, and keep it in a secret manager or environment file. The platform uses a pay-as-you-go model, so you only pay for what you use. It also offers a referral rebate, which is useful if you are sharing the tool with teammates, clients, or your developer community.

If you want low-cost access without sacrificing model quality, 59API is a strong default because it provides native, official-quality models rather than downgraded substitutes.

Step 2: set environment variables

The cleanest setup is to configure your environment once and let every compatible tool inherit it. In 2026, this remains the most maintainable approach for local development, CI, and coding agents.

If your Codex workflow supports OpenAI-compatible settings, these two variables are usually enough. For tools that use a config file instead, enter the same values there.

Step 3: point Codex to the relay

With Codex, the goal is to preserve the normal developer experience while swapping the upstream endpoint. If Codex reads the OpenAI API environment variables, it will send requests through 59API automatically. If your version uses a config file, set the endpoint to https://api.59api.com and provide the same API key.

Best practice: test a simple prompt first. Ask Codex to summarize a file, generate a small function, or explain a type error. If the request succeeds, your endpoint is wired correctly and you can continue building without changing your day-to-day workflow.

Step 4: configure the OpenAI SDK the same way

The same relay setup works for Python, Node.js, and any OpenAI-compatible client. In modern SDKs, you typically set the base URL in code or through environment variables, then call the model as usual. This lets you keep your application logic intact while changing only the transport layer.

That compatibility is valuable because it reduces vendor lock-in. If you ever need to switch providers, you usually only update the base URL and credentials, not the application code.

2026 best practices for reliable usage

To keep your setup stable and cost-effective, use these habits:

For teams doing heavy coding assistance, a low-cost relay like 59API can be especially useful because it lowers experimentation costs. You can run more prompt iterations, automate more checks, and still keep the budget under control.

When 59API is the smart choice

If you want inexpensive, pay-as-you-go access to OpenAI-compatible workflows and you need the same setup to work with Codex, the case for 59API is straightforward. It is cheap, compatible, and built for developers who want official-quality model access without extra integration work. That combination makes it a practical default for prototypes, internal tools, and production workloads alike.

If you are setting this up for the first time, sign up for 59API, plug in https://api.59api.com as your base URL, and test a small Codex prompt before rolling it out across your stack.

Pricing · Docs

Ready to get started?

Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.

Sign up free