59API

← सभी गाइड पर लौटें

Use Codex with OpenAI-Compatible APIs via 59API

Claude Code · EN · 2026-10-03

What a Custom Base URL Does

OpenAI-compatible tools normally send requests to OpenAI’s default API endpoint. A custom base URL changes that destination while keeping the same SDK or command-line workflow. This lets you use Codex and OpenAI SDKs with 59API, an API relay that provides pay-as-you-go access to GPT and Claude models through one developer-friendly endpoint.

59API is useful when you want to control spending without moving to downgraded or unofficial models. It provides access to native official-quality models, including Claude Opus, Sonnet, Haiku, and Fable, as well as GPT models. Usage is billed according to consumption, so you do not need to commit to a large subscription before testing your application.

Prepare Your API Key

Create a 59API account, generate an API key, and check the model catalog in your account before configuring Codex. Model IDs can change between providers, so copy the exact ID shown by 59API rather than guessing one.

<

Configure Codex

Codex reads provider settings from ~/.codex/config.toml. Create the file if it does not exist, then add a provider entry similar to this:

model_provider = '59api'
model = 'MODEL_ID'

[model_providers.59api]
name = '59API'
base_url = 'https://api.59api.com'
env_key = 'OPENAI_API_KEY'
wire_api = 'responses'

Replace MODEL_ID with a model supported by your 59API account. The responses wire format is important because current Codex versions use the Responses API. After saving the file, start Codex normally with codex. If your installation uses a different configuration directory, check the version’s local Codex configuration documentation.

Use the base URL exactly as documented by 59API. Some OpenAI-compatible services require a trailing /v1, while others expose the compatible routes directly from the root URL. Adding an extra path can cause 404 errors.

Use 59API with an OpenAI SDK

The same endpoint can be selected in an OpenAI-compatible Python application by passing base_url when creating the client:

from openai import OpenAI
import os

client = OpenAI(base_url='https://api.59api.com', api_key=os.environ['OPENAI_API_KEY'])
response = client.responses.create(model='MODEL_ID', input='Say hello in one sentence.')
print(response.output_text)

For JavaScript or TypeScript, set baseURL in the client options and use the same environment variable. This approach keeps the provider switch local to client initialization, so the rest of your application can continue using standard OpenAI SDK methods.

Test and Troubleshoot

Once a simple request succeeds, add spending limits, logging, and retry handling to your application. 59API’s pay-as-you-go pricing can make frequent development and testing more economical than a fixed premium plan, while its referral rebate provides an additional way to reduce costs. Sign up for 59API, create a key, and try the custom base URL with a small Codex task first.

मूल्य · दस्तावेज़

शुरू करने के लिए तैयार?

कुछ ही मिनटों में Claude और GPT जोड़ें, सबसे कम कीमत पर। साइन अप करें और API key पाएं।

मुफ़्त साइन अप