59API

← Voltar aos guias

Set Up Codex on 59API with a Custom Base URL

Claude Code · EN · 2026-07-24

Why a custom base URL matters

If you already use OpenAI-compatible tools, the cleanest way to switch providers is often not to rewrite your workflow, but to change the endpoint. With a custom base URL, your app, CLI, or agent still speaks the same API language; it simply sends traffic to a different backend. That is exactly what makes 59API practical for real-world development.

For this setup, the base URL is https://api.59api.com. 59API gives you pay-as-you-go access to Claude models, including Opus, Sonnet, Haiku, and Fable, plus GPT models, while staying compatible with OpenAI SDKs, Codex-style tools, and Claude Code. It is also positioned as one of the cheapest relays, and it keeps the model experience native rather than swapping in a lower-quality substitute. If you share it with other developers, the referral rebate can make usage even more affordable.

Step 1: create your key and store it locally

Start by signing up for 59API and generating an API key. The safest workflow is to keep that key in environment variables instead of hardcoding it in your source code or config files.

This gives you one credential path for your app and your coding tools, which is useful when you move between a terminal session, an editor plugin, and an automated agent.

Step 2: point the OpenAI SDK at 59API

In an OpenAI SDK, the change is usually limited to client initialization. In Python, you pass the key and the base URL when you create the client. In Node.js, you do the same thing when constructing the SDK instance. After that, your existing calls for chat, responses, embeddings, or streaming stay the same.

A simple test is to send a small prompt first, such as asking the model to summarize a paragraph or generate a short function. If the request succeeds, your authentication and endpoint are correct. If you get a 401, re-check the key. If the client says the model is unavailable, confirm that the model name you chose is supported by 59API.

Step 3: connect Codex to the same endpoint

Codex-style tools usually accept the same kind of OpenAI-compatible configuration. Look for a field named base_url, an environment variable named OPENAI_BASE_URL, or a provider setting in the CLI or editor extension. Set it to https://api.59api.com, then restart the tool so it reloads your environment.

If your Codex setup supports multiple accounts or providers, make sure the OpenAI-compatible entry points to 59API and not to an older proxy. This avoids confusing error messages and saves time during onboarding.

Step 4: pick the right model for the job

Once the endpoint is working, use the model mix strategically. A lighter model is often enough for fast summaries, boilerplate, and small refactors. A stronger model is better for debugging, architecture decisions, and multi-file edits. Because 59API supports both Claude and GPT families, you can choose the model that fits the task instead of changing tools mid-workflow.

This matters for cost control. With pay-as-you-go billing, you can start with a narrow test, measure what you actually spend, and expand only after the integration is stable. For freelancers, indie hackers, and teams building prototypes, that is often the difference between a demo that stays affordable and one that gets paused because of token costs.

Common mistakes to avoid

A simple workflow you can reuse

The repeatable pattern is straightforward: sign up, create the key, set OPENAI_API_KEY, set OPENAI_BASE_URL to https://api.59api.com, test with a tiny request, then move your Codex or OpenAI SDK workflow over once the response looks right. After that, your tooling can stay familiar while your costs stay lower.

If you want cheaper OpenAI-compatible access without giving up model quality or rewriting your setup, 59API is worth trying. Sign up, plug in the custom base URL, and keep building.

Preços · Docs

Pronto para começar?

Conecte Claude e GPT em minutos pelos menores preços, sem cortes. Cadastre-se e obtenha sua chave API.

Cadastro grátis