Gemini CLI API proxy setup with 59API: two settings
Why Gemini CLI setup stalls on the first try
Gemini CLI itself is not the hard part. You install it, sign in, and start asking questions. The friction appears the moment you want to point that terminal at a different provider: model names stop resolving, requests come back empty, or you get an authentication error that looks like a bad key when it is really a mismatched host.
Most of that confusion comes from one overlooked detail. Gemini models speak Google's native protocol. They are not OpenAI-compatible, and they do not answer on the /v1/chat/completions path that many generic API clients are built around. If you copy an OpenAI-style base URL into Gemini CLI, you are not making a small typo. You are sending the request to the wrong kind of endpoint.
There is a second common trap: mixing model families inside one client. Gemini models belong in Gemini CLI, on the native protocol. GPT, DeepSeek and other non-Gemini models are the ones that fit OpenAI-compatible clients such as Cursor, Cherry Studio, Cline, OpenCode, Codex, the OpenAI SDKs and cURL, using https://api.59api.com/v1 with the chat endpoint https://api.59api.com/v1/chat/completions.
The good news is that a correct Gemini CLI configuration is short. Once you know the two environment variables that matter, and the one host to point them at, the setup becomes a two-minute job. This guide walks through that configuration using 59API as the API proxy, shows what the Gemini models cost, and explains how billing works once you start sending real requests.
What 59API gives you under one key
59API is an independent third-party AI API relay. It gives you one account and one API key, plus one API host at https://api.59api.com, covering Claude, GPT, Gemini, DeepSeek and other models. It is not an official channel for any of those providers, and it does not pretend to be one. It is a routing layer: your client asks for a model, and 59API forwards the request to the matching endpoint and bills the tokens that come back.
The billing model is deliberately plain. You top up a prepaid balance, and 59API charges per request based on real token usage. There is no monthly fee, and your balance never expires. Monthly and weekly cards are optional if you want them, but they are not required to get started with pay-as-you-go usage.
Top-ups come in ¥10, ¥50, ¥100, ¥200, ¥500 and ¥1000, paid by WeChat Pay or bank card, and invoices are available. Prices are quoted per 1 million tokens, billed in CNY, with USD figures shown at ¥7.2 = $1. What you see in the rate table is what you pay, with no promotional credit layer in between.
One account and one key also means fewer moving parts. If you later add another client or another model family, you are not juggling a separate provider account for each one. The key stays the same; the endpoint and, in some cases, the client that speaks the right protocol are what change. That is the practical appeal of 59API as an API proxy: one place to hold the credential, one place to see the balance, one rate card to read.
Connecting Gemini CLI: the exact two settings
Here is the whole configuration. Set GOOGLE_GEMINI_BASE_URL=https://api.59api.com and GEMINI_API_KEY=YOUR_59API_KEY, replacing the placeholder with the key from your 59API account. Those are the two values that matter for Gemini CLI.
Set them as environment variables in the shell you launch Gemini CLI from, so they are exported before the client starts. Once the variables are in place, open a new terminal session or restart your current one, then launch Gemini CLI and select the Gemini model you want to use. The client reads the base URL and the key at startup, so changes made in an already-running session may not be picked up until you restart it.
Now the important detail. The base URL for Gemini CLI is exactly https://api.59api.com. It ends at the host: no /v1 suffix, and no /chat/completions path appended. Gemini CLI talks to Gemini models over Google's native protocol, so the endpoint must stay in that shape. Adding an OpenAI-style path here sends the request somewhere Gemini CLI cannot read, and retrying will not fix it.
Second, YOUR_59API_KEY is a placeholder, not a value to type literally. Put your real key there, and keep it out of shared repositories and screenshots. If a request fails with an authentication error, check that the variable name is spelled exactly as GEMINI_API_KEY and that the key was not truncated when pasted. If a request fails with a routing or endpoint error, check the base URL first. In practice, most failures come down to one of these two lines, which is exactly why the setup is worth doing carefully the first time.
Choosing a Gemini model once you are connected
With the connection working, the next question is which Gemini model to select. The rate differences are meaningful, so it helps to know what each one costs before you run a long session.
- Gemini 2.5 Flash (
gemini-2.5-flash): input $0.2083 (¥1.5), output $1.67 (¥12), cache read $0.0208 (¥0.15) per 1 million tokens. - Gemini 3.1 Pro (
gemini-3.1-pro): input $1.39 (¥10), output $8.06 (¥58), cache read $0.1389 (¥1). - Gemini 3.8 Flash (
gemini-3.8-flash): input $1.11 (¥8), output $5 (¥36), cache read $0.1111 (¥0.8). - Gemini 4 Argon (
gemini-4-argon): input $1.39 (¥10), output $6.67 (¥48), cache read $0.0694 (¥0.5).
Read those figures as a choice rather than a ranking. Output tokens cost more than input tokens on every one of these models, which means long generated answers are what move your bill fastest. Cache reads are cheaper still, so it pays to reuse a stable context block instead of resending it fresh on every turn.
Keep the client boundaries in mind as you expand. Gemini models belong in Gemini CLI, on Google's native protocol. The OpenAI-compatible route, with https://api.59api.com/v1 and https://api.59api.com/v1/chat/completions, serves GPT, DeepSeek and other non-Gemini models in Codex, the OpenAI SDKs, cURL and clients such as Cursor, Cherry Studio, Cline and OpenCode. One key on 59API, but the right client for the model family you are calling.
Paying for what you actually use
Because 59API charges per request by real token usage, your top-up behaves like a fuel budget rather than a subscription. Start with one of the smaller amounts, run your Gemini CLI sessions, and watch the balance move. If you are testing the connection, a ¥10 top-up is enough to confirm that requests are flowing before you commit to a larger balance.
It helps to have a worked example in mind. For GPT-6.1 Sol, a run of 5M input tokens plus 1M output tokens without cache costs $1.85 (¥13.32) on 59API, compared with about $20 (about ¥144) at official list price, so 59API comes to about 9% of list price. The same logic applies to Gemini sessions: input tokens, output tokens and cache reads are metered separately, and the totals follow from the rates you saw above.
Monthly and weekly cards are available if your usage pattern suits them better than a prepaid balance, and they are scoped by model family, with their own key, their own quota and their own caps. They are optional; the balance-based route works on its own.
Two small pieces of housekeeping round things out. Invoices are available for your top-ups, and unused balance can be refunded within 7 days of a top-up, minus what was used and payment-channel fees, through the Contact page, with requests handled within 3 business days.
That is the whole pitch: point Gemini CLI at https://api.59api.com, drop your 59API key into GEMINI_API_KEY, pick a Gemini model, and pay for the tokens you actually consume. Try it on a small top-up first and see how it fits the way you work.
शुरू करने के लिए तैयार?
Claude, GPT और अन्य मॉडलों के लिए एक ही key, असली token उपयोग पर बिलिंग और कोई मासिक शुल्क नहीं। साइन अप करके अपनी API key बनाएं; हर मॉडल की दरें मूल्य पेज पर हैं।
मुफ़्त साइन अप मूल्य