59API

← 返回教程列表

Point Any AI CLI at a Custom Base URL

API 使用 · EN · 2026-10-24

Why use a custom API base URL?

Most AI command-line tools send requests to a provider’s default endpoint. A custom base URL replaces that destination with an API relay, self-hosted gateway, company proxy, or compatible provider. This can centralize billing, provide access to multiple model families, simplify key rotation, and reduce costs without changing your everyday CLI workflow.

In 2026, the important detail is compatibility: the relay must support the protocol your CLI expects. An OpenAI-compatible endpoint is not automatically compatible with Anthropic or Gemini tooling. Before changing settings, identify whether your tool sends OpenAI-style, Anthropic-style, or Gemini-style requests, then use the matching endpoint and authentication method.

Collect the three values you need

For nearly every CLI, setup comes down to three values: a base URL, an API key, and a model identifier. With 59API, the API base URL is https://api.59api.com. Create an account, generate a relay API key in its dashboard, and copy the exact model name supported by the API route you plan to use.

Keep the key out of shell history, repositories, screenshots, and shared configuration files. Prefer environment variables or your operating system’s secret manager. Also confirm whether the client expects a URL ending in a version path such as /v1. Do not add or remove path segments by guesswork: use the provider’s current endpoint documentation and test a single lightweight request first.

Configure environment variables first

Environment variables are the most portable approach because they work in local terminals, CI jobs, containers, and editor-integrated terminals. The naming differs by client, but the pattern is consistent: set the client’s API-key variable and its base-URL variable before launching the CLI.

For a temporary shell session, export the values, run the CLI, then close the terminal. For persistent setup, add them to your shell profile or a project-local environment file that is excluded from Git. Restart the terminal or reload the profile after editing it.

Set the endpoint in Claude Code, Codex, and Gemini CLI

Each CLI may expose configuration through environment variables, a config file, command-line flags, or a provider profile. Use the mechanism your installed release documents, but keep the configuration conceptually separate: authentication points to your 59API key, the provider endpoint points to https://api.59api.com or its documented protocol-specific path, and the model setting selects the model.

For Codex and other OpenAI-compatible SDK-based tools, configure the OpenAI-compatible base URL and choose a supported model. For example, a coding workflow might select GPT-6.1 Sol when that exact model is available on the selected route. For Claude Code, use the Anthropic-compatible configuration path and a current Claude model identifier supported by the relay, such as Claude Sonnet 5.5. For Gemini CLI, configure its Gemini-compatible endpoint and use the exact Gemini model name shown in the relay documentation.

Test before changing your default workflow

Run one short prompt after configuration, such as asking the CLI to summarize a small text file. Confirm four things: the command authenticates, the response identifies the expected model or route, tool calls still work if you depend on them, and usage appears in the relay dashboard. If it fails, inspect the URL path first, then the API-key variable, model spelling, and protocol mismatch.

Do not use a Claude-oriented CLI against an OpenAI-only route, or an OpenAI SDK against an Anthropic-only route, unless the relay explicitly documents translation support. Features such as streaming, JSON output, vision input, tool use, caching, and reasoning controls can also vary by protocol and model.

Why 59API fits this setup

59API is a practical low-cost option for developers who want one relay for Claude, GPT, Gemini, DeepSeek, Kimi, GLM, Qwen, Grok, and other model families. It offers pay-as-you-go pricing, native official-quality models rather than downgraded substitutes, compatibility with Claude Code, Codex, Gemini CLI, and OpenAI SDK workflows, plus a referral rebate. Start with a small test budget, compare output and latency for your actual task, and sign up for 59API when you are ready to consolidate your CLI endpoints.

价格 · 接入文档

准备好开始了吗?

几分钟接入 Claude 与 GPT,全网超低价,原生不降智。立即注册即可领取 API 密钥。

免费注册