59API

← 返回教程列表

Gemini CLI Custom Base URL Setup for 2026

Claude Code · EN · 2026-10-24

Why use a custom base URL with Gemini CLI?

Gemini CLI is useful for code generation, repository analysis, shell-assisted workflows, and repeatable developer tasks. By default, it connects to Google's API endpoints. A custom base URL lets the CLI send compatible Gemini requests through an API relay instead, which can simplify billing, centralize access credentials, and give a team more model choices.

59API is a practical option for developers who want pay-as-you-go AI access without maintaining separate accounts and billing setups for every provider. Its API base URL is https://api.59api.com, and it is compatible with Gemini CLI as well as Claude Code, Codex, and OpenAI SDK-based applications. It provides native official-quality models rather than downgraded substitutes, including Gemini 3.1 Pro and Gemini 3.8 Flash alongside models from other providers.

Prerequisites before configuring Gemini CLI

Do not paste an API key into a repository, shell history, shared screenshot, or committed configuration file. Environment variables are the simplest approach for local development. For CI, store the key in the platform's encrypted secrets manager and expose it only during the job that needs it.

Configure the base URL and API key

Set the Gemini API key environment variable to your 59API key, then set Gemini CLI's custom endpoint variable to https://api.59api.com. In shells that use the standard Gemini CLI variable names, the commands are: export GEMINI_API_KEY='your_59api_key' and export GOOGLE_GEMINI_BASE_URL='https://api.59api.com'. Open a new terminal session after adding permanent variables to your shell profile.

On Windows PowerShell, use the session equivalents: $env:GEMINI_API_KEY='your_59api_key' and $env:GOOGLE_GEMINI_BASE_URL='https://api.59api.com'. For persistent variables, use your operating system's environment-variable settings or a secure developer-secret tool rather than placing secrets in source-controlled files.

Endpoint conventions matter. Some compatible services expect a root base URL and let Gemini CLI append its versioned API path; others document a base URL that already includes a version segment. Start with the URL published by 59API, avoid manually adding duplicate path fragments, and test with a simple prompt. If your installed Gemini CLI version uses a configuration file instead of, or in addition to, the environment variable, set the same base URL there and keep secrets in environment variables.

Choose models deliberately

A relay can expose more than one Gemini model, so choose the model according to the task rather than using the most expensive option by default. Gemini 3.8 Flash is a sensible concrete choice for high-volume, latency-sensitive activities such as summarizing changed files or drafting test cases. Gemini 3.1 Pro may be a better fit when you need deeper reasoning over a complex codebase or architecture decision.

Use the exact model name listed in the 59API dashboard or documentation. Do not assume that a Google-facing alias will resolve through every relay. Pin a model in scripts and CI jobs for reproducibility, while keeping the model selection configurable through an environment variable when different environments have different cost or quality requirements.

Test, troubleshoot, and control cost

For a low-cost, flexible Gemini CLI setup, 59API can reduce operational friction while preserving access to current native-quality AI models. Sign up for 59API when you are ready to test the custom endpoint with a small pay-as-you-go workload, then scale only after validating model behavior, latency, and spend for your own projects.

价格 · 接入文档

准备好开始了吗?

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

免费注册