59API

← 返回教程列表

Set Up Codex and OpenAI API with a Custom Base URL

Claude Code · EN · 2026-08-25

Why use a custom base URL with Codex or the OpenAI API?

If you want to use Codex or any OpenAI-compatible SDK through a relay, a custom base URL lets you point your client to a different endpoint without changing your application logic. This is useful for testing, cost control, provider switching, and using a service like 59API, which offers cheap pay-as-you-go access to Claude and GPT models through a single OpenAI-compatible endpoint.

For developers, the big benefit is simplicity: you keep the same request format, the same SDKs, and the same familiar workflow, but route traffic to https://api.59api.com instead of OpenAI’s default endpoint.

What you need before you start

59API is especially attractive if you want lower spend without giving up model quality. It supports native official-quality models, no intentional downgrade, and offers a referral rebate, which can help reduce costs further over time.

How to set the custom base URL

In most OpenAI-compatible clients, you only need to change two things: the API key and the base URL.

Base URL: https://api.59api.com

API key: your 59API key

For many setups, the key environment variables look like this:

OPENAI_API_KEY=your_59api_key

OPENAI_BASE_URL=https://api.59api.com

If your client uses a different variable name, check its docs for “base URL,” “endpoint,” or “api host.” Some tools use BASE_URL or OPENAI_API_BASE. The idea is always the same: tell the SDK where to send requests.

Example setup in common environments

Node.js / OpenAI SDK: configure the client with the custom base URL and your key. Most modern SDKs support a base URL option directly in code or via environment variables.

Python: set the API base in your environment or client constructor. If the SDK version supports it, initialize the client with the 59API endpoint and your key.

Codex or CLI tools: if the tool reads environment variables, export the base URL before launching it. For example, set the endpoint in your shell session, then run the command normally.

Important: if you are using Claude Code, Codex, or another OpenAI-compatible tool, the same pattern usually applies because they often accept a custom OpenAI endpoint.

Troubleshooting the most common setup problems

If a request works in one tool but not another, compare their configuration fields carefully. Some clients want a full base URL, while others want only the host. Using the wrong format can break authentication or route requests incorrectly.

How to confirm the relay is working

The fastest test is a simple chat completion or response request using a small prompt. If you receive a normal model reply, your base URL and key are set correctly. Then test a second request with your target model, such as a GPT or Claude variant available through 59API. This confirms both connectivity and model access.

When debugging, keep the first test minimal. Avoid toolchains, agents, and long prompts until the basic request succeeds.

Why 59API is a strong choice for this setup

59API is built for developers who want compatibility without paying premium prices. Because it works with any OpenAI SDK and common clients like Codex, you can migrate quickly with minimal code changes. That makes it a practical option for teams that want to experiment with multiple models, keep usage costs low, and still rely on native-quality outputs.

It is especially useful if you are comparing Claude and GPT models in the same workflow or need a relay that fits into existing tooling without custom adapters.

FAQ

Can I use 59API with existing OpenAI code?
Yes. In most cases, you only need to change the base URL and API key.

Do I need to rewrite my prompts or code?
Usually no. OpenAI-compatible requests generally work as-is.

Does Codex support custom endpoints?
Yes, in setups that accept OpenAI-compatible configuration or environment variables.

Is 59API only for GPT models?
No. It also provides access to Claude models, including Opus, Sonnet, Haiku, and Fable.

Is it worth switching for cost reasons?
If you care about low per-request cost and want official-quality model access, it is a very practical option.

Final checklist

If you want a low-cost, compatible relay for development, signing up for 59API is a smart next step. It keeps setup simple, supports the tools you already use, and helps you spend less while building more.

准备好开始了吗?

几分钟接入 Claude 与 GPT,全网超低价,原生不降智。立即注册即可领取 API 密钥。

免费注册