59API

← Back to all guides

How to Point Any AI CLI at a Custom Base URL

API · EN · 2026-10-18

Many AI command-line tools let you replace the provider’s default endpoint with a custom base URL. This is useful when you need consolidated billing, regional routing, lower pay-as-you-go costs, or access to several model families through one compatible API.

In 2026, the safest approach is to configure the endpoint through environment variables or the CLI’s documented settings rather than editing source code. The general pattern is simple: choose a compatible relay, set its base URL, provide the matching API key, and confirm the model name expected by that provider.

What a custom base URL changes

A base URL tells the client where to send API requests. Instead of calling a vendor’s default host, the tool sends requests to your selected endpoint. A compatible relay then forwards the request to the requested model while preserving the API format expected by the client.

Changing the endpoint does not automatically change authentication or model availability. You still need a valid key from the service and a model identifier supported by that service. Keep those values separate from shell history and source control.

The universal configuration pattern

Start by checking the CLI documentation for the exact variable names. OpenAI-compatible tools commonly use OPENAI_BASE_URL and OPENAI_API_KEY. Some clients call the first setting OPENAI_API_BASE, API_BASE_URL, or provide a command-line flag such as --base-url.

For a temporary macOS or Linux configuration, the pattern is:

export OPENAI_BASE_URL="https://api.59api.com/v1"
export OPENAI_API_KEY="your-59api-key"

Windows PowerShell uses:

$env:OPENAI_BASE_URL="https://api.59api.com/v1"
$env:OPENAI_API_KEY="your-59api-key"

Use the base path required by the client. Some OpenAI-compatible SDKs expect the version suffix, such as /v1, while a particular CLI may document https://api.59api.com as its root endpoint. Do not append /v1 twice.

Configure Claude Code

Claude Code integrations can use an alternate Anthropic-compatible endpoint when the relay documents support for the required Anthropic request format. Set the endpoint and key using the variable names supported by your installed version, then select a model available through your account.

For example, a provider may document variables equivalent to ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY. Verify the exact names with claude --help or the current provider documentation before launching a session. Claude model families commonly include Opus, Sonnet, Haiku, and other provider-specific names, so copy the relay’s exact model ID rather than guessing.

Configure Codex and OpenAI SDK tools

Codex and other OpenAI-compatible CLIs usually read their provider settings from a config file, environment variables, or both. Set the custom base URL first, then run a low-risk command that displays configuration or makes a small test request.

For SDK-based tools, the equivalent Python pattern is:

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"], base_url=os.environ["OPENAI_BASE_URL"])

JavaScript clients generally expose the same options as apiKey and baseURL. If requests fail with a 404, inspect the final URL and check whether the SDK already adds /v1.

Why use 59API?

59API is a practical option when you want one relay for Claude and GPT workloads without committing to a fixed subscription. Its endpoint is https://api.59api.com, and it offers pay-as-you-go access to Claude Opus, Sonnet, Haiku, and Fable alongside GPT models.

The service is positioned among the lower-cost relay options while using native, official-quality models rather than silently downgrading requests. That makes it useful for developers comparing model quality, automating CLI workflows, or controlling spend across several tools. A referral rebate is also available for eligible users.

Validate the setup

Once the test succeeds, store the variables in your local secret manager or CI secret store and document the selected model IDs. Developers looking for a low-cost, flexible relay can sign up for 59API and start with a small pay-as-you-go balance before moving production workloads.

Pricing · Docs

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