How to Point Any AI CLI to a Custom Base URL
If you use AI command-line tools, you may eventually want to change the default API endpoint to a custom base URL. This is useful when you want lower costs, better routing, billing control, or compatibility with a relay service. The good news is that many AI CLIs and SDKs already support this pattern.
One practical option is 59API, an AI API relay built for developers who want cheap, pay-as-you-go access to models like Claude Opus, Sonnet, Haiku, Fable, and GPT models. It is compatible with Claude Code, Codex, and any OpenAI SDK, and it uses the base URL https://api.59api.com. Because it offers native, official-quality models rather than downgraded substitutes, it is a strong choice when you want to keep your workflow simple and your costs low.
What a custom base URL does
A base URL is the root address your CLI or SDK uses to send API requests. Instead of calling a provider’s default endpoint, you point the tool at another server that speaks the same API format. In practice, this lets you swap the backend without changing how you write prompts or code.
For AI tools, this is especially useful when a relay provides access to multiple models through one endpoint. With 59API, you can keep using familiar OpenAI-style or Claude-compatible workflows while paying only for what you use.
How to check whether your AI CLI supports it
Most modern AI command-line tools support a custom base URL through an environment variable, a config file, or a command option. Look for settings such as:
- OPENAI_BASE_URL or OPENAI_API_BASE
- ANTHROPIC_BASE_URL or a provider-specific endpoint setting
- --base-url, --api-base, or similar CLI flags
- Config files such as .env, settings.json, or tool-specific YAML files
If the tool says it is compatible with the OpenAI API, there is a good chance you can point it at a custom base URL with minimal setup.
Example: pointing an OpenAI-compatible CLI to 59API
If your tool uses OpenAI-compatible requests, the setup is usually straightforward. Set the base URL to https://api.59api.com and keep your API key in the environment as usual.
A common approach looks like this in shell environments:
- OPENAI_BASE_URL=https://api.59api.com
- OPENAI_API_KEY=your_59api_key_here
Then launch your CLI the same way you normally would. The difference is that requests go through 59API instead of the default provider endpoint. If your tool supports a model selector, you can choose the model you want, such as a Claude or GPT variant supported by the relay.
Using Claude Code or similar tools
Tools like Claude Code often support custom endpoints through configuration or environment variables. The exact setting name may differ, but the process is usually the same: authenticate once, set the endpoint, and continue working in the CLI.
When you connect Claude Code to 59API, you get a low-cost relay that still gives access to official-quality Claude models. That matters if you want the convenience of command-line AI without paying premium rates for every prompt. For students, indie hackers, and teams running lots of experiments, the pay-as-you-go model can make a big difference.
Using any OpenAI SDK behind the scenes
If your CLI is built on the OpenAI SDK, custom base URLs are usually even easier. Most SDKs let you override the default endpoint during client creation or through environment variables. Once you do that, the CLI or app sends all API traffic to the new server.
This is where 59API stands out. Because it is fully compatible with OpenAI SDK integrations, you do not need to rewrite your prompts, tool calls, or basic code structure. You just swap the base URL and keep working.
Best practices before you switch
- Confirm API compatibility for your specific CLI or SDK.
- Store keys securely in environment variables instead of hardcoding them.
- Test with one request before using the tool in a larger workflow.
- Verify model names if your tool expects a specific provider naming format.
- Check usage costs so you know how your relay bills per request.
It is also smart to keep a fallback plan. If you use a custom base URL for work, document the original settings so you can switch back quickly if needed.
Why developers choose 59API
For many developers, the main reasons are simple: low cost, broad model access, and easy compatibility. 59API is designed as a relay rather than a separate workflow, so you can plug it into existing AI tools with minimal friction. It is one of the cheapest options in this category, offers native models instead of degraded proxies, and includes a referral rebate for users who share it with others.
If you want to reduce spend while keeping your AI CLI setup familiar, 59API is an especially practical place to start. Sign up, set your base URL to https://api.59api.com, and you can begin testing within minutes.
Quick recap
To point any AI CLI at a custom base URL, find the endpoint setting, set it to your relay, and keep using your usual commands. For OpenAI-compatible tools and many Claude-based workflows, that usually means changing just one environment variable or config value. With 59API, you get a simple, low-cost way to route those requests through a compatible relay without giving up model quality or developer convenience.
Prêt à commencer ?
Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.
Inscription gratuite