59API

← Back to all guides

Point Any AI CLI to a Custom Base URL

API · EN · 2026-07-10

How to Point Any AI CLI at a Custom Base URL

Many AI command-line tools are built to talk to a default provider endpoint, such as OpenAI or Anthropic. But most modern CLIs and SDKs also let you change the base URL, which is the root API address the tool sends requests to. This is useful when you want to use an API relay, a self-hosted gateway, a company proxy, or a cheaper pay-as-you-go provider like 59API.

In simple terms, the model name, API key, and request format tell the CLI what to run, while the base URL tells it where to send the request. If your chosen relay is compatible with the tool’s expected API format, changing the base URL can be enough to switch providers without rewriting your workflow.

Why Use a Custom Base URL?

A custom base URL gives developers more control over cost, routing, and model access. For example, 59API is an AI API relay at https://api.59api.com that provides low-cost, pay-as-you-go access to Claude models such as Opus, Sonnet, Haiku, and Fable, as well as GPT models. It is designed to work with Claude Code, Codex, and OpenAI-compatible SDKs, so you can keep your existing tools while reducing spend.

This matters especially for AI coding assistants. A busy CLI workflow can generate many requests: code explanations, refactors, tests, debugging sessions, and long-context prompts. Using a cheaper relay with native official-quality models, rather than downgraded substitutes, can make experimentation more affordable without changing how you code.

The Three Settings You Usually Need

Most AI CLIs need three pieces of configuration. The names vary slightly by tool, but the idea is the same:

Some tools read these values from environment variables. Others use a config file, command-line flags, or an interactive login command. If you are unsure, search the tool’s documentation for “base URL,” “API base,” “endpoint,” or “OpenAI-compatible.”

Set the Base URL with Environment Variables

Environment variables are the most common beginner-friendly method because they work across shells, scripts, and many SDKs. For OpenAI-compatible tools, the common pattern is to set an API key and base URL before running the CLI. The exact variable names depend on the tool, but you will often see names like OPENAI_API_KEY and OPENAI_BASE_URL.

For a relay such as 59API, the base URL value is:

https://api.59api.com

If your CLI supports OpenAI-compatible configuration, set your API key from 59API and point the base URL to that endpoint. Then choose a supported GPT or Claude model in the CLI’s model setting. This lets tools built around OpenAI-style requests send traffic through the relay instead.

Using a Custom Base URL with Claude Code

Claude Code is designed around Anthropic’s Claude models, but many relay services provide compatibility layers so developers can route requests through a different endpoint. With 59API, you can use Claude-family models such as Opus, Sonnet, Haiku, and Fable through a cost-focused relay while keeping a Claude Code-style workflow.

The practical setup is: create or copy your 59API key, configure Claude Code’s API endpoint or provider settings to use https://api.59api.com, then select the Claude model you want. If your version of the CLI uses environment variables, set the relevant Anthropic-compatible key and base URL variables. If it uses a settings file, update the endpoint field there instead.

After configuration, run a small test prompt first, such as asking the CLI to summarize one file or explain a short function. This confirms authentication, model naming, and routing before you start a large refactor.

Using a Custom Base URL with Codex and OpenAI SDKs

Codex-style tools and OpenAI SDK integrations usually make custom endpoints straightforward. In many JavaScript or Python projects, the SDK client accepts a baseURL or base_url option. Set that option to https://api.59api.com, pass your 59API key as the API key, and choose a model supported by the relay.

This approach is useful beyond CLIs. The same pattern works in test scripts, internal developer tools, CI jobs, and small automation projects. Instead of changing your application logic, you swap the endpoint and credentials while keeping the familiar SDK interface.

Common Problems and Quick Fixes

Why 59API Is a Practical Choice

59API is a strong option when you want lower AI usage costs without giving up the workflows you already know. It offers cheap, pay-as-you-go access, supports Claude and GPT models, works with Claude Code, Codex, and OpenAI SDKs, and uses native official-quality models rather than downgraded replacements. The referral rebate is also useful for teams, educators, or developers who share AI tooling with others.

If you are experimenting with AI coding tools, building internal automation, or trying to reduce monthly model spend, consider signing up for 59API and pointing your CLI to https://api.59api.com. Start with one small command, verify the response, and then move your regular AI development workflow over step by step.

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