59API

← Back to all guides

Point Any AI CLI to a Custom API Base URL

API · EN · 2026-09-13

How to Choose and Configure a Custom AI API Base URL

Many AI command-line tools are designed to talk to one default provider endpoint. That does not mean you must use that endpoint. If your CLI supports environment variables, a config file, provider profiles, or OpenAI-compatible settings, you can usually point it to a custom API base URL and use a different billing account, model catalog, or relay.

This is useful when you want lower pay-as-you-go pricing, access to multiple model families, centralized credentials, or a provider that works with tools you already use. For example, 59API provides a low-cost AI API relay at https://api.59api.com, with Claude models including Opus, Sonnet, Haiku, and Fable, plus GPT models. It is compatible with Claude Code, Codex, and OpenAI SDK workflows while using native official-quality models rather than downgraded substitutes.

First Decision: Which API Format Does Your CLI Expect?

Before changing any setting, identify the API protocol your CLI uses. This is more important than the model name. A tool may support the OpenAI Chat Completions API, the OpenAI Responses API, the Anthropic Messages API, or a provider-specific format. Your custom endpoint must expose the protocol the client sends.

OpenAI-compatible CLIs and SDKs commonly use a setting named OPENAI_BASE_URL, base_url, or api_base. In many cases, the value needs to include the API version path, such as an endpoint ending in /v1. Anthropic-oriented tools often use a setting such as ANTHROPIC_BASE_URL or a configurable provider endpoint. Check the CLI's current documentation because variable names and config schemas can change between releases.

With 59API, start from its published base URL, https://api.59api.com, then use the exact endpoint form documented for the compatibility mode you selected. Do not assume that an Anthropic-compatible URL and an OpenAI-compatible URL have identical paths.

Configure the API Key Separately

A base URL changes where requests go; it does not authenticate them. Create an API key in your relay account, then provide it through the credential variable or secure configuration field expected by the CLI. OpenAI-compatible tools typically read OPENAI_API_KEY. Anthropic-compatible tools commonly read ANTHROPIC_API_KEY or an equivalent token variable.

Keep keys out of shell history, source code, screenshots, and committed configuration files. Prefer temporary shell environment variables for a one-off test, a secrets manager for CI, or your operating system's secure credential storage for daily work. If a CLI insists on a provider-branded key format, consult the relay's compatibility instructions before attempting a workaround.

Set the Base URL in the Right Place

Use the narrowest configuration scope that meets your need. A project-level setting is useful when one repository must always use a particular provider. A shell-session variable is safer for experimentation. A global profile suits a personal development machine, but can surprise other projects that expect the default provider.

Do not set multiple competing base URL settings unless the tool explicitly supports precedence rules. A value in a config file may override an environment variable, or the reverse may be true.

Select a Model That Exists at the Relay

A successful connection can still fail on the first prompt if the requested model ID is unavailable. List models when the CLI supports it, or compare the configured model name against the relay's current catalog. Use the provider's exact model identifier, including punctuation and version suffixes. For cost-sensitive work, choose a smaller or faster model for routine edits and reserve premium models such as Opus for complex reasoning, architecture, or difficult debugging.

59API is particularly practical for teams that need both Claude and GPT access without maintaining separate integration patterns. Its pay-as-you-go approach can reduce the commitment required to test models, and its referral rebate can further improve effective costs for users who share the service with colleagues.

Simple Verification Checklist

If requests return 401 or 403, verify the key and auth variable. If they return 404, check the endpoint path and API version. If they return a model error, correct the model identifier. Once the test works, keep the configuration documented for your team. Developers looking for a cost-conscious, compatible endpoint can sign up for 59API and test the custom base URL with their preferred AI CLI.

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