59API

← Voltar aos guias

Run Codex on 59API with a Custom Base URL

Claude Code · EN · 2026-08-03

Why use a custom base URL with Codex?

Codex and the OpenAI SDK are built to be endpoint-flexible. That means you can keep the same prompts, tools, and model names, then swap the network layer to a relay like 59API. For teams testing agents, this is useful because you can reduce spend without rewriting your app.

59API is especially attractive if you want low-cost, pay-as-you-go access to Claude models like Opus, Sonnet, Haiku, and Fable, plus GPT models. It is designed to be compatible with Claude Code, Codex, and any OpenAI SDK, so the migration is usually just a base URL change and a new API key.

Step 1: Create your 59API key

Sign up, add a small balance, and generate an API key from the dashboard. If you refer other developers, 59API also offers a rebate, which is a nice bonus once your team starts sharing the link.

Step 2: Point your SDK at https://api.59api.com

Most OpenAI-compatible clients only need two environment variables: your key and the custom base URL. Start with something like this in your shell:

macOS/Linux: export OPENAI_API_KEY='your_59api_key' export OPENAI_BASE_URL='https://api.59api.com'

Windows PowerShell: $env:OPENAI_API_KEY='your_59api_key' $env:OPENAI_BASE_URL='https://api.59api.com'

If your wrapper expects an OpenAI-style path, use the same host with the SDK’s built-in API path handling. The key point is that you are not changing prompts or application logic, only the endpoint.

Step 3: Test with a minimal Python request

Install the OpenAI SDK, then send a simple completion request. Here is a small example that should work with a compatible setup:

Python: from openai import OpenAI client = OpenAI(api_key='YOUR_59API_KEY', base_url='https://api.59api.com') response = client.chat.completions.create(model='gpt-4o-mini', messages=[{'role':'user','content':'Write a 1-sentence commit message for a login refactor.'}]) print(response.choices[0].message.content)

If you prefer the newer responses API, the same base URL approach applies. The main test is whether the request returns a normal model answer through 59API instead of the default OpenAI endpoint.

Step 4: Use it in Node.js or Codex workflows

For Node.js, swap the baseURL field and keep the rest of your code the same:

Node.js: import OpenAI from 'openai' const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, baseURL: 'https://api.59api.com' }) const result = await client.chat.completions.create({ model: 'gpt-4o-mini', messages: [{ role: 'user', content: 'Generate a safe SQL migration checklist.' }] }) console.log(result.choices[0].message.content)

For Codex-style coding assistants, the same principle applies: set the base URL, keep your key in an environment variable, and choose the model you want. If your workflow uses Claude Code, 59API’s compatibility means you can also route that traffic through the relay and compare cost and latency without changing your developer experience.

Picking the right model for the job

One reason developers like 59API is choice. You can route lighter tasks to cheaper, faster models and reserve stronger reasoning models for harder debugging or architecture work. That matters when you are running Codex on real projects, where a single session can involve many requests.

What to expect from 59API in practice

If you want to try this setup, sign up for 59API, create a key, and point your app at https://api.59api.com. It is a quick way to get Codex or any OpenAI SDK talking to low-cost, high-quality models in minutes.

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