Custom Base URLs for AI CLIs: Claude Code to Codex
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:
- model_provider = "relay59"
- model = "YOUR_ENABLED_CODEX_MODEL_ID"
Then add the following provider section, with each item on its own line in the file:
- [model_providers.relay59]
- name = "59API"
- base_url = "https://api.59api.com/v1"
- env_key = "FIFTYNINE_API_KEY"
- wire_api = "responses"
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
- 401 or 403: Check the relay key, account access, and conflicting credentials. A direct-provider key is not a relay key.
- 404: Check the protocol and path. Avoid both missing /v1 and duplicated paths such as /v1/v1.
- Model not found: Copy an enabled model ID exactly.
- Unsupported endpoint: Confirm whether the client needs Anthropic Messages, Chat Completions, or Responses.
- 429: Inspect balance, quotas, and concurrency limits before retrying repeatedly.
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.
Ready to get started?
Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.
Sign up free