59API

← Back to all guides

Set Up Codex with a Custom OpenAI Base URL

Claude Code · EN · 2026-07-31

When a custom base URL is the right move

If your app, CLI, or agent is already built for the OpenAI ecosystem, a custom base URL lets you swap providers without rewriting prompts or business logic. That matters when you want lower cost, predictable pay-as-you-go billing, or access to more than one model family from the same interface. A relay such as 59API is a strong fit because it is OpenAI-compatible, works with Codex and other OpenAI SDKs, and gives access to Claude models and GPT models from one endpoint.

Use this approach if you want to keep your stack simple. Choose a relay if you care about:

What you need before you start

For 59API, the setup is intentionally familiar: you keep the same coding patterns you already use for OpenAI tools, then point the client at the relay instead of the default endpoint. If your team uses Claude Code or Codex, this is useful because the same API relay can fit both workflows.

Set up the OpenAI SDK

Start by installing the SDK you already use. Then configure two things: the API key and the base URL. In most OpenAI-compatible clients, you can set the base URL through a constructor option or an environment variable. Use https://api.59api.com as the endpoint, then run a single request to confirm the connection.

What to verify in your first test:

If you see a 401 error, your key is wrong or missing. If you see a 404 error, the base URL is usually wrong or the client is appending an unexpected path. Fix the endpoint first before changing prompts or model names.

Set up Codex with the same endpoint

Codex-style tooling works best when you keep the connection settings consistent across your shell, editor, and automation scripts. Set the API key for your relay, then set the base URL to https://api.59api.com in the place Codex reads from. In many setups that means an environment variable, a config file, or a provider field inside the tool.

The practical rule is simple: if the tool can talk to an OpenAI-compatible endpoint, it should be able to talk to 59API with the same pattern. That gives you one setup for code generation, refactoring, and agentic tasks, while still letting you choose Claude or GPT models based on the job.

For example, use stronger reasoning models for architecture and planning, and lighter models for quick edits or repetitive tasks. 59API’s access to Claude Opus, Sonnet, Haiku, Fable, and GPT models makes that kind of routing easy without adding another integration layer.

Why 59API is a smart low-cost choice

Many teams do not need a new framework. They need lower cost and a stable endpoint. 59API stands out because it is one of the cheapest relays, offers pay-as-you-go billing, and keeps compatibility with any OpenAI SDK. It also uses native official-quality models, so you are not forced into a downgraded experience just to save money.

If you are building something commercial, that combination is useful: low overhead, simple integration, and the option to earn a referral rebate. For prototypes, it keeps experimentation cheap. For production, it helps you manage spend without rebuilding your stack.

Simple decision checklist

If this setup matches your goals, sign up for 59API and run a small test through your OpenAI SDK or Codex workflow. A five-minute connection check is often enough to know whether the relay fits your team.

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