Set Up Codex with 59API Custom Base URL
Why a custom base URL is the simplest way to save money
If your app already talks to the OpenAI API or Codex, you do not need to rewrite prompts or swap SDKs to cut costs. A custom base URL lets you keep the same client, the same model names, and the same request format while routing traffic to a compatible relay. 59API is a strong fit here because it is pay-as-you-go, keeps access to native official-quality models, and is among the cheapest relays for Claude and GPT models. That makes it ideal for prototypes, internal tools, and production apps where token spend matters.
59API also adds a referral rebate, so if you share it with teammates or clients, the savings can compound over time.
Step 1: Create your 59API account and copy your key
Start by signing up at 59API and generating an API key. Add a small balance or enable pay-as-you-go so your first test request can go through immediately. Save the key somewhere secure; treat it like any other production credential.
- Account: create or log in to your 59API dashboard.
- Key: generate a fresh API key for the project you are testing.
- Budget: set a spend limit if your workflow will run in CI or frequent agent loops.
Step 2: Point your OpenAI-compatible client to 59API
For most OpenAI SDKs, you only need to change two things: the API key and the base URL. The base URL for 59API is https://api.59api.com. Many OpenAI-compatible clients expect the versioned endpoint, so in practice you may use https://api.59api.com/v1. If your tool asks for a root URL, use the root; if it asks for the API base, use the versioned path. The important part is that you replace the default OpenAI endpoint with 59API.
- Set your API key to the 59API key you copied from the dashboard.
- Set the base URL to https://api.59api.com or https://api.59api.com/v1 depending on your client.
- Keep your model names the same as you would for the standard OpenAI API.
Example environment variables for most shells: OPENAI_API_KEY should be your 59API key, and OPENAI_BASE_URL should point to the 59API endpoint. Older libraries may use OPENAI_API_BASE instead. If one variable does not work, check your SDK version before changing your code.
Step 3: Test a simple OpenAI request
Before wiring Codex into your workflow, send one basic request from your existing OpenAI client. Use a lightweight model first so you can confirm the relay, key, and endpoint are correct.
- Pick a standard model name that your account supports.
- Run a short prompt like a greeting or a one-paragraph summary.
- Check the response for normal latency, usage, and billing in your 59API dashboard.
If you get a 401 error, the key is wrong. If you get a connection or 404 error, the base URL is usually the issue. If the request works in your SDK but not in Codex, the problem is usually an environment variable mismatch.
Step 4: Configure Codex to use the same endpoint
Codex and Codex-based tools typically read the same OpenAI-style settings. Export the same key and base URL in the terminal or add them to the tool-specific config file if your Codex installation uses one. Once set, Codex will route completions and code changes through 59API without changing your prompt style or workflow.
- Use the same 59API key you tested in the OpenAI SDK.
- Set the base URL before launching Codex so it inherits the environment.
- Leave your existing prompts, repo path, and model selection in place unless your tool requires a specific model string.
This approach is especially useful if you want to keep Codex costs predictable. Because 59API is pay-as-you-go and priced aggressively, you can run more iterations, more refactors, and more agent-driven tests without burning through budget. For teams, that can be the difference between using Codex casually and using it in a real daily workflow.
Step 5: Lock in a production-safe setup
Once the test succeeds, move the key into a secrets manager or deployment environment variable, not into source control. If you are using the OpenAI SDK in a backend service, keep the same base URL in staging and production so behavior stays consistent. Also set a soft budget alert in 59API to catch unexpected spikes early.
- Store credentials in environment variables or a secret manager.
- Use separate keys for local development and production.
- Watch token usage during the first week to estimate real costs.
When 59API is the best choice
If you want official-quality Claude and GPT models, a compatible OpenAI API surface, and lower token spend, 59API is one of the easiest ways to get there. You keep the tools you already know, including Codex, Claude Code, and any OpenAI SDK, while paying less for the same style of workflow. If you are ready to try it, sign up for 59API, grab your key, and point your next request at the custom base URL.
¿Listo para empezar?
Conecta Claude y GPT en minutos a los precios más bajos, sin recortes. Regístrate para obtener tu clave API.
Registro gratis