59API

← Back to all guides

Gemini CLI API proxy setup with 59API: exact settings

Claude Code · EN · 2026-11-29

Why Gemini CLI connections usually stall

Most Gemini CLI connection problems are not really credential problems. They are protocol problems. Gemini CLI speaks to Gemini models through Google's native protocol, so a configuration copied from an OpenAI-style client tends to fail even when the API key is perfectly valid. Pointing the client at an OpenAI-compatible chat endpoint is the most common mistake, and it usually returns a confusing error instead of a clear explanation.

That is why a good API proxy setup starts with one simple rule: match the client to the model family. Gemini models use Google's native protocol only, and they run in Gemini CLI. They are not OpenAI-compatible, so they do not belong on the OpenAI-style base URL and chat endpoint that 59API provides for other families. If you keep that distinction in mind, the rest of the configuration becomes short and predictable.

This guide walks through connecting Gemini CLI to 59API, an independent third-party AI API relay, using the exact settings the client expects. You will also see current per-token rates for several Gemini models, so you can decide what to run before spending anything. The goal is a working connection in a few minutes, with no guesswork about URLs, headers, or endpoints.

What 59API gives you before you connect anything

59API is an independent third-party AI API relay. One account and one API key give you one API host, https://api.59api.com, for Claude, GPT, Gemini, DeepSeek and other models. You are not juggling separate providers, separate dashboards, or separate billing systems for every family you want to experiment with.

The billing model is straightforward. You top up a prepaid balance, and each request is charged by real token usage. There is no monthly fee, and your balance never expires. Top-ups are available at ¥10, ¥50, ¥100, ¥200, ¥500 and ¥1000, paid by WeChat Pay or bank card, and invoices are available. Billing is in CNY, with USD figures shown at ¥7.2 = $1, which makes the rates below easy to compare with your own budget.

One important detail: client rules differ by model family, and 59API does not blur them. Gemini models run through Gemini CLI using Google's native protocol. Claude models work only through the genuine Claude Code or Claude Desktop client (Claude Code 2.1.285 or newer), never through the OpenAI SDK, cURL or other clients. Codex, OpenAI SDKs, cURL and OpenAI-compatible clients such as Cursor, Cherry Studio, Cline and OpenCode work with GPT, DeepSeek and other non-Claude, non-Gemini models only.

For a Gemini CLI user, your job is narrow and clean: one base URL, one key, and the correct model id.

Connect Gemini CLI to 59API step by step

Setting up Gemini CLI through 59API takes two environment variables and a working key. Here is the exact configuration, in the order I would do it myself.

Two details cause most of the friction here. First, the value for GOOGLE_GEMINI_BASE_URL is the 59API host itself, exactly https://api.59api.com. Second, the key goes in GEMINI_API_KEY, not in a variable named for an OpenAI client. If your shell profile still contains an older configuration pointing somewhere else, remove it so it cannot override what you just set.

One more point worth repeating: the OpenAI-style base URL and chat endpoint on 59API are for GPT, DeepSeek and other non-Claude, non-Gemini models. Gemini CLI does not use that route. It uses the native Gemini path, which is why the two environment variables above are all you need.

Choosing a Gemini model and what it costs

Once the client is connected, pick the model that matches the task. 59API lists Gemini pricing per 1 million tokens, with input, output and cache read shown separately. Here are four current Gemini rates to start from.

The pattern is easy to read. Flash-class models keep both input and output costs low, which suits everyday prompts, quick iterations and exploratory work. Pro-class models cost more per million tokens, and output is priced well above input across the range, so long generations are where the difference shows up.

Cache read pricing matters too if you reuse a large fixed context. On 59API, cache reads are billed at their own rate, which is lower than the input rate for every Gemini model listed above. If your workflow sends the same material repeatedly, that is worth keeping in mind.

Because billing is based on actual token usage rather than a subscription, the practical way to control spend is simple: pick the model that fits the job, keep the context lean, and watch the balance in your 59API account.

Verify the connection and fix what usually breaks

Send one short prompt first. A small test tells you far more than a long task, and it keeps the cost of debugging low. If the request succeeds, you can move straight to real work. If it fails, work through this short list in order.

Once a test request returns, check your 59API balance. The deduction should reflect the real token usage of that request. Since there is no monthly fee and the balance never expires, you can top up when it suits you instead of keeping a subscription alive.

That is the whole setup: one account, one key, one host, two environment variables, and a Gemini model id. Once it works, you can focus on the prompt instead of the plumbing.

Docs

Ready to get started?

One key for Claude, GPT and more, billed by real token usage with no monthly fee. Sign up to create your API key; rates for every model are on the pricing page.

Sign up free Pricing