59API

← Retour aux guides

Set Up Codex with a Custom OpenAI Base URL

Claude Code · EN · 2026-08-23

Why use a custom base URL for Codex and OpenAI SDKs?

If you are building with Codex or any OpenAI-compatible SDK, the fastest way to reduce API spend is often not to change your app logic, but to change where your requests go. A custom base URL lets you route the same code through a different provider while keeping the same request format. That means you can keep your existing tooling, environment variables, and model calls, but pay less per request.

59API is an AI API relay built for exactly this use case. It supports Claude models like Opus, Sonnet, Haiku, and Fable, plus GPT models, and it works with Claude Code, Codex, and any OpenAI SDK. Its base URL is https://api.59api.com, and because it offers pay-as-you-go pricing with native, official-quality models and no downgrade, it is a practical option for teams that want lower cost without rewriting integrations.

What you save in real terms

Cost optimization only matters if the numbers make sense. Here is the simple math:

The advantage of a relay like 59API is that you do not need to compromise on compatibility. You are not reworking prompts or changing application behavior; you are swapping the endpoint and, if needed, the API key.

Set up Codex with a custom base URL

Most Codex and OpenAI-compatible tools read the endpoint from an environment variable. The common pattern is to point the client at the relay instead of the default OpenAI host.

Example shell setup:

If your tool expects a different variable name, look for settings such as base_url, api_base, or endpoint. The idea is the same: keep the client library unchanged and swap the destination.

OpenAI SDK example: minimal code change

In many OpenAI SDKs, you only need to change the base URL and API key. For example, in JavaScript or TypeScript, the configuration often looks like this:

In Python, the equivalent setup is similarly small. The important point is that your application logic, prompts, retries, and streaming code can stay the same. That lowers migration risk and makes it easy to test cost savings in a staging environment before rolling out to production.

How to use 59API for lower-cost development

59API is attractive when you care about both price and compatibility. It is among the cheapest relay options, but the real advantage is that it keeps the model experience close to native quality. That matters for code generation, long-context debugging, automated refactors, and agentic workflows where small quality drops can create costly rework.

This tiered approach makes the most of pay-as-you-go pricing. You do not overspend on every call, and you can still reserve premium models for the jobs where they matter most.

Practical optimization tips

When 59API makes the most sense

Choose 59API if you want an OpenAI-compatible setup, low operational friction, and better unit economics. It is especially useful for solo developers, startups, and teams building internal tools that send many small requests. The referral rebate can also lower effective cost further, which is helpful if you plan to onboard teammates or share the platform with other developers.

If you are ready to test the savings, sign up, point your Codex or SDK client to https://api.59api.com, and run a small benchmark on your most common workflow. In many teams, the switch takes minutes and the savings show up in the first billing cycle.

Tarifs · Docs

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