Make Your Gemini CLI Buttery Smooth: Fix Network Issues with a Reverse Proxy


Hi everyone, this is Neo.

Lately, AI has been the hottest topic in our indie e-commerce circle. Google’s Gemini, with its impressive capabilities, has become a go-to assistant for a lot of us — especially the gemini CLI. A few keystrokes and you’ve got inspiration, scripts, whatever you need. It’s a genuine productivity beast.

But here’s the reality check: many of us running gemini CLI on servers or machines in China run into a headache: commands stall halfway through, or just time out with an error. It’s like your trusty Swiss Army knife suddenly going dull at the worst possible moment. Frustrating, right?

$ gemini generate "写一段关于独立站夏季促销的邮件标题"
Error: Unable to connect to the server. Please check your network connection.

I banged my head against this wall for a long time too. Today I’m sharing my go-to fix — a reverse proxy that solves gemini CLI access problems once and for all!

What’s a Reverse Proxy? Sounds Complicated?

Don’t let the name scare you. A reverse proxy is basically a “middleman” — a messenger.

Picture this: your computer (the client) wants to talk to Gemini’s servers (the target server), which live overseas. But the distance is huge, there’s a firewall in between, and your commands (API requests) struggle to get through directly and reliably.

So what do you do? You rent a server (VPS) overseas that can talk to Gemini without issues. Then you make that overseas server your messenger:

  1. You send your command through the messenger.
  2. The messenger relays your command to Gemini, verbatim.
  3. Gemini replies to the messenger.
  4. The messenger passes Gemini’s reply back to your terminal.

Reverse proxy diagram

Throughout this whole process, your gemini CLI only ever talks to your messenger, and that connection is smooth and unobstructed from China. That messenger is your reverse proxy server.

Why Bother?

For gemini CLI users, the benefits are pretty direct:

  1. Stable and reliable: This is the big one. Your terminal’s connection to your own overseas server is stable and under your control, and that server’s connection to Google is clean. Commands stop failing for no reason.
  2. Configure once, use forever: Set it up a single time and your gemini CLI learns to route through the proxy. Every command after that automatically uses the stable channel — no more worrying about network issues.
  3. Secure and controllable: Your API key stays local, requests route through your own server, and you can even log every CLI call on the server. Everything stays in your hands.

Let’s Get Practical: Easy Setup with the BT Panel

Enough theory — let’s get to the good stuff. If you’re not comfortable with the Linux command line, I strongly recommend the BT Panel, which gives you a graphical interface. A few clicks and you’re done.

Step 1: Get an overseas server and install BT Panel

This is the foundation: you need an overseas server with unrestricted access to Google. Vultr, DigitalOcean, Linode, or overseas nodes from Alibaba Cloud or Tencent Cloud all work. Then install the BT Panel — the official site has a one-click install script.

Step 2: Set up the reverse proxy in BT Panel

  1. Create a new site Log into BT Panel, click “Websites” on the left, then “Add Site”. Enter a domain you’ve prepared, like gemini-proxy.yourdomain.com. You don’t need a database or PHP — a pure static site is fine.

    BT Panel — adding a site

  2. Apply for an SSL certificate Once the site is created, click its “Settings”, find the “SSL” tab, choose “Let’s Encrypt”, tick your domain, and apply. BT Panel handles the certificate issuance and deployment automatically. Remember to enable “Force HTTPS”.

    BT Panel — applying for an SSL certificate

  3. Configure the reverse proxy This is the critical step. In the site’s “Settings”, find the “Reverse Proxy” tab and click “Add Reverse Proxy”.

    • Proxy name: Anything you’ll recognize, e.g. gemini-cli-proxy.
    • Target URL: Enter Gemini’s official API endpoint: https://generativelanguage.googleapis.com
    • Send host: Also enter generativelanguage.googleapis.com

    BT Panel — configuring the reverse proxy

    Save it, and your reverse proxy is live!

Final Step: Point Gemini CLI at Your Proxy

Now — no need to modify any code or the tool itself. You just set one environment variable on the machine where you use gemini CLI, and it will automatically read and use your proxy.

What’s an environment variable? Think of it as a global, system-level config item. When gemini CLI starts, it checks this variable; if it exists, it uses it as the API base URL.

How to set it:

  • On Linux or macOS: Open your terminal and run:

    export GOOGLE_GEMINI_BASE_URL="gemini-proxy.yourdomain.com"

    Note: export only lasts for the current terminal session. To make it permanent, add the line to your shell config file (like ~/.bashrc or ~/.zshrc), then run source ~/.bashrc or source ~/.zshrc.

  • On Windows: Open Command Prompt (CMD) and enter:

    set GOOGLE_GEMINI_BASE_URL="gemini-proxy.yourdomain.com"

    Again, this only applies to the current window. For a permanent setup, right-click “This PC” > “Properties” > “Advanced system settings” > “Environment Variables”, create a new one under “System variables” or “User variables” with the name GOOGLE_GEMINI_BASE_URL and the value gemini-proxy.yourdomain.com.

Moment of truth!

After setting it up, open a new terminal window and try that command from earlier:

$ gemini generate "写一段关于独立站夏季促销的邮件标题"

- "火热一夏,清凉折扣!全场商品低至5折!"
- "夏季狂欢,限时开抢!为你的夏日增添一抹亮色!"
- "别让夏天溜走!抓住季末大促的尾巴!"

See that? Results in a flash! Your gemini CLI is now talking to Google through your stable, reliable proxy server.

Wrapping Up

Here’s the dead-simple summary of today’s flow:

  1. Get an overseas server and install BT Panel.
  2. In BT Panel: create a site, get an SSL cert, configure the reverse proxy — all point-and-click.
  3. On the machine running gemini CLI, set the GOOGLE_API_ENDPOINT environment variable.

Three steps, done. No more network errors — your gemini CLI becomes the stable, efficient weapon it was meant to be.

Hope this lazy-friendly tutorial helps. Go try it out!