59API

← Retour aux guides

Codex + OpenAI API: Custom Base URL Setup

Claude Code · EN · 2026-08-10

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.

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.

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.

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.

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.

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.

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.

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