59API

← Voltar aos guias

Custom Base URLs for AI CLIs: Claude Code to Codex

API · EN · 2026-10-20

The quick-start rule: change the endpoint, key, and model

Pointing an AI CLI at a custom base URL usually requires three changes: the API endpoint, the authentication key, and a model ID accepted by that endpoint. The catch is protocol compatibility: an OpenAI-compatible URL cannot automatically replace an Anthropic-compatible URL.

59API provides low-cost, pay-as-you-go access to native, official-quality Claude and GPT models without downgrading, with compatibility for Claude Code, Codex, and OpenAI SDKs. Its API base URL is https://api.59api.com. Here is how to connect without confusing hostnames, API paths, or credentials.

1. Prepare your key and exact model ID

Create a 59API API key in your account, then copy an available model ID from its dashboard or documentation. Use the exact identifier, not a guessed marketing name: model availability and aliases can differ between providers.

In a macOS, Linux, or WSL terminal, store the key for your current shell:

export FIFTYNINE_API_KEY='YOUR_59API_KEY'

Replace the placeholder locally. Avoid committing keys to configuration files or pasting them into issue reports. Environment variables are convenient, but keep them out of shared logs and screenshots too.

2. Point Claude Code at the relay

Claude Code uses Anthropic-style requests. Set its base URL and API key when launching it:

ANTHROPIC_BASE_URL=https://api.59api.com ANTHROPIC_API_KEY="$FIFTYNINE_API_KEY" claude --model YOUR_ENABLED_CLAUDE_MODEL_ID

Replace the model placeholder with an enabled Claude model ID. Use the root URL here: Claude Code adds the Anthropic API path, so appending /v1/messages yourself would produce an incorrect request URL.

If you previously configured another gateway, check for a conflicting ANTHROPIC_AUTH_TOKEN. Remove stale credentials from the current shell and inspect existing Claude Code settings rather than assuming the new API key overrides everything. Start a fresh session and request a short response before running a large coding task.

3. Configure Codex as a custom provider

For Codex CLI, use an explicit provider configuration. In ~/.codex/config.toml, merge these top-level settings before any section header, replacing the model placeholder:

Then add the following provider section, with each item on its own line in the file:

Launch codex from the shell containing your exported key. This configuration selects the relay and its API-key environment variable rather than relying on an existing ChatGPT login. Codex uses the Responses API, so choose a model supported by the relay's Codex integration; Chat Completions compatibility alone is insufficient.

4. Apply the pattern to other AI CLIs

For an OpenAI-compatible CLI, look for a base-url flag, provider configuration, or documented environment variables. Many tools built around OpenAI SDKs accept OPENAI_BASE_URL=https://api.59api.com/v1 and OPENAI_API_KEY, but a CLI can override or ignore those defaults.

Set OPENAI_API_KEY to your 59API key and select an enabled model. Verify the tool's documentation before exporting variables globally. There is no universal override for every AI CLI: tools with hard-coded endpoints may require a plugin or may not support relays.

5. Fix the common failures quickly

59API's inexpensive usage-based billing makes it a practical option for experimenting across coding tools, and its referral rebate offers another potential saving. Sign up when you are ready, check current rates and rebate terms, and validate one small request before scaling up.

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