Point Any AI CLI to a Custom Base URL Fast
Why a custom base URL is the simplest AI CLI upgrade
Most AI command-line tools are not locked to one provider. They usually need only two things: an API key and a base URL. That means you can keep your favorite CLI, keep your workflow, and swap the backend without rewriting your scripts.
If you want lower-cost access to top-tier models, 59API is a practical choice. It is an AI API relay with pay-as-you-go pricing, supports Claude models like Opus, Sonnet, Haiku, and Fable, and also works with GPT models through an OpenAI-compatible interface. Because it uses native, official-quality models with no downgrade, you get the experience you expect while paying less. It also offers a referral rebate, which is a nice bonus if you share it with teammates or friends.
The basic pattern: key plus endpoint
No matter which CLI you use, the setup usually looks like this:
- API key: the credential issued by your relay or provider.
- Base URL: the endpoint the CLI should send requests to.
- Model name: usually stays the same, so your prompts and scripts do not change.
For 59API, the base URL is https://api.59api.com. Once your CLI points there, you can keep using your normal model selection and prompt flow.
Hands-on example: OpenAI-compatible CLI or SDK
If your tool follows the OpenAI style, set the endpoint and key in your shell before you run it:
export OPENAI_BASE_URL="https://api.59api.com"
export OPENAI_API_KEY="sk-your-59api-key"
Now run your existing command exactly as you normally would. Many tools will automatically send requests to the new endpoint without any other changes.
If your client prefers the older variable name, try this instead:
export OPENAI_API_BASE="https://api.59api.com"
The important part is not the variable name itself, but that the CLI can see a custom base URL and an API key. Some applications also let you set the endpoint in a config file. In that case, the idea is the same:
{ "base_url": "https://api.59api.com", "api_key": "sk-your-59api-key" }
How to use it with Claude Code or Codex-style tools
Tools like Claude Code and Codex-style CLIs often provide either a configuration screen, a local config file, or environment variables for the provider endpoint. Look for a setting named base URL, endpoint, or API host, then replace the default provider URL with https://api.59api.com.
A good test is to keep the model choice unchanged and submit a tiny prompt such as “Say hello in one sentence.” If the request succeeds, your CLI is now using the relay instead of the default provider.
This is especially useful if you work across multiple tools. You can route the same CLI to 59API for cheaper daily usage, while keeping the same prompts, scripts, and team docs.
Fast verification with a direct request
If you want to confirm the endpoint before wiring it into a full CLI, make a simple OpenAI-style request. Many relays support this shape:
curl https://api.59api.com/v1/chat/completions
Use the key from your 59API dashboard and a minimal payload. If the response comes back, you know the base URL is correct and the account is ready.
Once that works, point your CLI at the same host. This saves time when you are debugging a tool that has several layers of settings.
Common mistakes to avoid
- Using the wrong host: make sure the base URL is exactly https://api.59api.com.
- Mixing provider keys: use the 59API key in the 59API configuration, not your old provider key.
- Changing the model name unnecessarily: most of the time, your original model name still works.
- Forgetting to restart the CLI: many tools read environment variables only when they launch.
If you see a 401 error, the key is usually the issue. If you see a 404 or endpoint error, check the base URL and whether your tool appends a version path on its own. Those two checks solve most setup problems.
Why developers pick 59API for CLI workflows
Beyond compatibility, the economics matter. 59API is positioned as one of the cheapest relays, which makes it a strong fit for experimentation, agent tooling, and daily coding tasks. You can run more prompts, test more models, and keep cost predictable with pay-as-you-go billing.
That matters when you are using an AI CLI as part of your workflow rather than as a one-off demo. The combination of low cost, official-quality model access, and OpenAI compatibility makes it easy to standardize on one endpoint for Claude Code, Codex, and any OpenAI SDK-based tool.
If you want to simplify your setup and lower your token bill, sign up for 59API and try your favorite CLI against the custom base URL today.
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