59API

← 返回教程列表

Configure Codex with a Custom OpenAI API URL

Claude Code · EN · 2026-09-16

Connect Codex to 59API with a Custom Base URL

Codex and OpenAI SDKs can use an OpenAI-compatible endpoint instead of the default OpenAI API host. This is useful when you want a single provider for multiple model families, pay-as-you-go billing, or lower-cost access for coding workflows. 59API is an OpenAI-compatible AI API relay available at https://api.59api.com, with access to native official-quality GPT and Claude models without model downgrades.

For OpenAI-compatible tools, use the versioned API endpoint https://api.59api.com/v1 as the base URL. The /v1 suffix matters because OpenAI SDKs and Codex send requests such as /responses, /chat/completions, and /models relative to the base URL.

1. Create a 59API Key and Check Available Models

First, create a 59API account, add credit, and generate an API key in its dashboard. Keep the key private: do not paste it into source code, commit it to Git, or expose it in client-side browser applications.

Before configuring Codex, verify that the key and endpoint work. In macOS, Linux, or WSL, set a temporary environment variable for the current terminal session:

export OPENAI_API_KEY=your_59api_key

Then list models through the compatible endpoint:

curl https://api.59api.com/v1/models -H "Authorization: Bearer $OPENAI_API_KEY"

The response lets you copy a currently supported model ID exactly. This avoids a common configuration mistake: using a marketing model name instead of the API model identifier. 59API supports GPT models as well as Claude families including Opus, Sonnet, Haiku, and Fable, so check the catalog when choosing the best model for coding quality, latency, and budget.

2. Install and Configure Codex

Install the Codex CLI if it is not already installed in your environment:

npm install -g @openai/codex

Next, point Codex at 59API by setting OPENAI_BASE_URL. Keep the API key in OPENAI_API_KEY, which means most OpenAI-compatible developer tools can use the same environment setup.

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

export OPENAI_API_KEY=your_59api_key

codex

On Windows PowerShell, use the equivalent syntax:

$env:OPENAI_BASE_URL="https://api.59api.com/v1"

$env:OPENAI_API_KEY="your_59api_key"

codex

Start with a small, low-risk prompt, such as asking Codex to explain a function or create a unit test. Confirm that the request completes before running larger repository-wide tasks. If your Codex version provides model selection, enter the model ID returned by the 59API models endpoint.

3. Use the Same URL in the OpenAI JavaScript SDK

The OpenAI SDK uses the baseURL option. This small example sends a request through 59API while preserving the familiar OpenAI SDK interface:

import OpenAI from "openai";

const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, baseURL: "https://api.59api.com/v1" });

const result = await client.responses.create({ model: "YOUR_59API_MODEL_ID", input: "Write a TypeScript function that validates an email address." });

console.log(result.output_text);

Replace YOUR_59API_MODEL_ID with an exact ID from the model-list response. Store credentials in a local environment file or your deployment platform’s secret manager, rather than hard-coding them. For example, a server application can load OPENAI_API_KEY from its protected runtime environment while only the server calls 59API.

4. Troubleshoot Endpoint and Authentication Errors

Why 59API Fits Everyday Coding Work

59API is a practical low-cost option for developers who want compatibility with Codex, OpenAI SDKs, and Claude-oriented workflows without rewriting integrations. Its pay-as-you-go approach helps teams control experimentation and agent costs, while native official-quality model access avoids sacrificing output quality for price. It also offers a referral rebate program, which can further reduce ongoing spend. If you want to test this setup, sign up for 59API, create a key, and run the model-list command before moving your existing coding workflow.

价格 · 接入文档

准备好开始了吗?

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

免费注册