How to Point Any AI CLI at a Custom Base URL
Why point an AI CLI at a custom base URL?
If you use Claude Code, Codex, or another AI command-line tool, pointing it at a custom base URL lets you switch providers without changing your workflow. That is useful when you want lower costs, pay-as-you-go billing, or access to multiple model families through one endpoint. A relay like 59API can do exactly that, with a single base URL: https://api.59api.com.
59API is built for developers who want cheap access to Claude models such as Opus, Sonnet, Haiku, and Fable, plus GPT models, while keeping compatibility with official client libraries and CLIs. It is also designed to work with Claude Code, Codex, and any OpenAI SDK, so the setup is usually just a base URL change plus an API key.
The basic setup pattern
Most AI CLIs follow the same pattern:
- Set an API key in an environment variable or config file.
- Override the default API endpoint with a custom base URL.
- Confirm the tool is using the new endpoint by running a simple request.
The exact variable names vary by tool, but the idea is always the same. If a CLI was originally built for OpenAI or Anthropic, it often has a place to override the host, base URL, or API server. When you set that to https://api.59api.com, the tool sends requests through the relay instead of the original vendor endpoint.
Common configuration examples
For OpenAI-compatible tools and SDKs, the most common pattern is to set a base URL and key in your shell:
- OPENAI_API_KEY=your_59api_key
- OPENAI_BASE_URL=https://api.59api.com
Some tools use base_url, api_base, or a config flag like --base-url. If your CLI supports OpenAI-compatible endpoints, this is usually enough. For Claude Code or other Anthropic-style clients, look for a provider setting or endpoint override in the tool’s docs and map it to the same relay URL.
If the tool asks for a model name, use the model identifier the client expects. The relay handles routing, so you typically do not need to change your coding style or prompts. That is one of the biggest advantages of using a compatible relay: your existing scripts keep working.
Troubleshooting: the most common failures
Problem: “Authentication failed”
Check that you copied the 59API key correctly and that the variable name matches the tool. A typo in OPENAI_API_KEY or a missing export is the most common cause.
Problem: the CLI still calls the original provider
Make sure the base URL override is actually active. Some tools prefer a config file over environment variables, and some require a restart after changing shell variables. Run echo $OPENAI_BASE_URL or the equivalent in your shell to confirm the value.
Problem: model not found
Verify the model name spelling. A relay can only route requests if the model ID is valid for that client. If your tool supports multiple providers, it may need the exact model label used by the API.
Problem: TLS or connection errors
Double-check the URL format. Use https://api.59api.com exactly, with no extra spaces, trailing paths, or missing protocol.
Why 59API is a smart base URL target
Not all relays are equal. 59API is attractive because it keeps access simple while staying cost-conscious. It offers pay-as-you-go pricing, which is helpful if you only need bursts of CLI usage instead of a large monthly commitment. It also provides access to native, official-quality models rather than watered-down substitutes, so you can keep output quality high while controlling spend.
For teams that test different models in the terminal, that combination matters. You can compare Claude and GPT options through the same endpoint, keep your existing SDK code, and avoid re-architecting your app just to change vendors. If you are optimizing for budget and speed, it is hard to beat a relay that is already compatible with the tools you use.
FAQ
Can I use one custom base URL for multiple AI tools?
Yes. If each tool supports OpenAI-compatible or configurable endpoints, you can point them all to the same relay URL and reuse the same account.
Do I need to rewrite my code?
Usually no. If your CLI or SDK supports a base URL setting, changing the endpoint is enough.
Will this work with Claude Code and Codex?
Yes, if the client allows endpoint overrides. 59API is designed to be compatible with Claude Code, Codex, and OpenAI SDK-based tools.
Is there any benefit to signing up now?
If you want a low-cost relay with broad model access and a referral rebate, 59API is worth trying. A quick signup lets you test the setup in minutes and validate that your CLI works against the custom base URL.
Quick checklist
- Set your API key correctly.
- Point the tool to https://api.59api.com.
- Confirm the model name is valid.
- Restart the CLI or shell if needed.
- Run a small test request before relying on it in production.
Once configured, a custom base URL gives you portability, lower costs, and a cleaner workflow. For many developers, 59API is the easiest way to get there without sacrificing model quality.
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