Codex API proxy setup with 59API: exact base URL and key
Why Codex setup gets harder than it should
Most developers do not struggle with Codex because the tool is difficult. They struggle with the plumbing underneath it. You point Codex at a provider, paste a base URL, drop in a key, and hope the request format matches. Then a model name is wrong, an endpoint returns nothing useful, or the billing model is harder to understand than the code you were trying to write. The result is an afternoon of configuration instead of an afternoon of building.
That is the problem 59API is built to remove. 59API is an independent third-party AI API relay. You get one account, one API key and one API host, and you point your Codex client at that host instead of juggling separate credentials for different providers. Models such as GPT, DeepSeek and other non-Claude, non-Gemini families are reachable through the same OpenAI-compatible setup, so switching between them becomes a matter of changing a model id rather than rebuilding your environment.
There is no monthly fee either. You top up a prepaid balance, and 59API charges per request based on real token usage. Your balance never expires, so an unused top-up is not a deadline you have to rush to spend. In this guide, we walk through the exact settings, the model options that fit Codex, and what the usage actually costs once requests start flowing.
One account, one key, one host
Before you touch a config file, it helps to understand what you are actually connecting to. With 59API, the API host is https://api.59api.com. Your API key is the single credential you use for requests. That simplicity is the whole point: there is no per-provider account juggling and no separate key to rotate for every model family you want to try.
Money works in a straightforward way too. 59API uses a prepaid balance, charged per request by real token usage. There is no monthly fee, and the balance never expires. Monthly and weekly cards are optional if you would rather buy a fixed block of usage for a family of models, but they are not required to get started.
Top-ups are available at ¥10, ¥50, ¥100, ¥200, ¥500 and ¥1000, paid by WeChat Pay or bank card. Invoices are available as well. Pricing is listed per 1 million tokens, and billing is in CNY, with USD figures shown at ¥7.2 = $1. That means you can read the rate sheet in either currency and check a bill against the same numbers you saw before you started coding.
One note worth making early: 59API is an independent third-party relay, not an official channel of any model provider. Any official list price you see in a comparison is a reference price for context, not a claim of affiliation.
The exact settings for Codex
Here is the part you came for. Codex works with 59API through the OpenAI-compatible path, so the configuration is short. Set your base URL to https://api.59api.com/v1 and the chat endpoint to https://api.59api.com/v1/chat/completions. Use your 59API key in the place your client expects an API key, written here as YOUR_59API_KEY.
That is the whole setup: one host, one path prefix, one endpoint, one credential. Because the interface follows the OpenAI convention, the same base URL also works for OpenAI SDKs, cURL and OpenAI-compatible clients such as Cursor, Cherry Studio, Cline and OpenCode. If you already have a Codex configuration file with a provider block, you can usually add 59API as another entry and switch to it by name.
Two practical habits make the first run smoother. First, keep the key out of source control and load it from an environment variable, so you can rotate it without touching code. Second, send a short test message before wiring 59API into a larger workflow. A tiny request confirms that the base URL, endpoint, key and model id all agree with each other, and it costs you almost nothing at these per-token rates.
And if a request fails, read the error literally. A 401-style message almost always points to the key, a 404 usually points to the path, and a model error usually means the model id needs correcting. The setup is simple enough that the error message is usually enough to tell you which one it is.
Models you can run from Codex
Because Codex talks to 59API over the OpenAI-compatible route, it can call GPT, DeepSeek and other non-Claude, non-Gemini models. Here are a few current rates per 1 million tokens to help you pick a starting point.
- GPT-6.1 Sol (
gpt-6.1-sol): input $0.1847 (¥1.33), output $0.9264 (¥6.67), cache read $0.0375 (¥0.27). - GPT-5.6 Sol (
gpt-5.6-sol): input $0.3472 (¥2.5), output $1.94 (¥14), cache read $0.0278 (¥0.2). - DeepSeek V4 Flash (
deepseek-v4-flash): input $0.2778 (¥2), output $1.11 (¥8), cache read $0.006944 (¥0.05). - Qwen3.7 Plus (
qwen3.7-plus): input $0.1389 (¥1), output $0.4167 (¥3), cache read $0.0417 (¥0.3).
For a first test, a low-cost model such as Qwen3.7 Plus or GPT-6.1 Sol is a sensible choice: it confirms the plumbing without making a big dent in your balance. Once the request works, you can raise the model id to something heavier for the tasks that deserve it. Keeping the same base URL and key while changing only the model id is exactly the flexibility that makes a relay like 59API convenient for day-to-day work.
What the requests actually cost
Per-token billing is easier to judge with a concrete example. Take GPT-6.1 Sol at 5M input plus 1M output tokens without cache: on 59API that is $1.85 (¥13.32), against an official list price reference of $20 (about ¥144). That puts 59API at about 9% of list price for this workload.
GPT-5.6 Sol behaves similarly. At 2M input plus 0.5M output tokens without cache, the cost on 59API is $1.67 (¥12), versus an official list price reference of $18 (about ¥129.6) — again about 9% of list price. For a team running Codex all afternoon, those percentages add up to a budget line you can actually forecast from token counts.
If you prefer a prepaid block instead of a wallet, monthly and weekly cards are optional. For example, the G-PRO entry card for GPT covers 30 days at $83.19 (¥599), with quota $2300 and a weekly cap of $880, draining at the card's metering price × 2.4. A card has its own key, can only call that family's models, and is paid only from the card: it never falls back to wallet balance, and a balance key never draws on a card. Unused quota does not roll over. Quota and caps are card metering units written in $, not official list-price dollars, so treat them as their own measure rather than converting them into a reference price.
Start with the prepaid balance, configure the base URL, endpoint and key, and send one short request through Codex. If it comes back cleanly, you already have a working setup — and the rest is just choosing the model that fits the job.