59API

← Retour aux guides

Custom AI CLI Base URLs: Claude Code and Codex Fixes

API · EN · 2026-10-14

What does changing an AI CLI base URL actually do?

A custom base URL sends your CLI’s model requests to another API server. You still need a compatible protocol, a valid API key, and a model identifier that the server accepts. There is no universal setting for every AI CLI: some support environment variables, others require provider configuration, and some cannot change endpoints.

59API’s API base is https://api.59api.com. It offers low-cost, pay-as-you-go access to native, official-quality Claude and GPT models without model downgrades, with compatibility for Claude Code, Codex, and OpenAI SDKs. The correct URL format depends on the client.

Before you start: match the client to the endpoint

Get your 59API key and an exact supported model ID from your account’s model list or documentation. Model display names and API identifiers can differ. A Claude model requires an endpoint that supports its request format; changing the hostname alone does not translate protocols.

How to point Claude Code at 59API

In a macOS or Linux terminal, run these commands before starting Claude Code:

Replace both placeholders. Start Claude Code from that same terminal so it inherits the variables. If ANTHROPIC_AUTH_TOKEN already contains credentials for another provider, remove it from the session with unset ANTHROPIC_AUTH_TOKEN to avoid conflicting authentication.

In PowerShell, environment assignments use this syntax: $env:ANTHROPIC_BASE_URL = 'https://api.59api.com'. Set ANTHROPIC_API_KEY the same way, then launch claude. Avoid adding /v1 to the Anthropic base unless the provider specifically instructs you to do so.

How to configure a custom provider in Codex

Set export API59_KEY='YOUR_59API_KEY', then edit ~/.codex/config.toml. Set the following top-level values before any TOML section headers:

Add this provider section, with each entry on its own line:

Launch codex from the terminal containing API59_KEY. Merge these settings into your existing configuration instead of creating duplicate keys. An active configuration profile can override top-level settings, so check it if Codex still selects another provider.

How to configure other OpenAI-compatible tools

For tools that explicitly support these environment variables, set OPENAI_BASE_URL=https://api.59api.com/v1 and OPENAI_API_KEY=YOUR_59API_KEY. Check the tool’s documentation: support for the OpenAI protocol does not guarantee it reads OPENAI_BASE_URL.

The official Python OpenAI SDK reads these variables when you create OpenAI(). For JavaScript SDK integrations, pass baseURL and apiKey explicitly to the OpenAI constructor. A CLI built around either SDK may expose different flags or settings.

FAQ: why is my custom endpoint failing?

Why do I get 401 or 403? Check the relay key, account access, and available balance. A key from another provider will not authenticate with 59API. Confirm the CLI inherited your variables, then restart it.

Why do I get 404? Check the final request path. A client may append /responses, /chat/completions, or /v1/messages. Missing or duplicated /v1 prefixes can produce invalid routes. Also verify that the relay supports the endpoint your client uses.

Why does it say “model not found”? Copy the exact supported model ID. Do not assume a familiar alias exists on every relay.

Why do streaming or tool calls fail? Basic text completion compatibility does not establish support for every feature. Check Responses API support, streaming events, and tool-call handling for your selected model and client version.

59API’s pay-as-you-go pricing makes it a practical choice for cost-conscious CLI workflows, and its referral rebate adds another saving opportunity. Sign up for 59API, choose a supported model, and test a small request before starting a longer coding session.

Tarifs · Docs

Prêt à commencer ?

Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.

Inscription gratuite