Gemini CLI Wrapper – Detailed Summary of Issues and Final Fix (For Posting)

Hello everyone,

I’ve gone through an extensive process of debugging and fixing a bash script (gemini-cli.sh) used as a Docker wrapper for calling the Google Gemini API. I encountered several interesting bugs and have finally achieved 100% functional code.

Unfortunately, even with the corrected code, a frustrating external rate limit issue persists. Here is a detailed summary for the community.


I. :gear: Overview of Fixed Internal Bugs (The Code is Now Clean)

The original configuration and subsequent debugging revealed and resolved the following critical issues in the bash script:

  1. JSON Escaping Error (Slovak Characters): The original code failed to handle Slovak UTF-8 characters (č, š, ť, ž), leading to a jq: parse error: Invalid numeric literal.

    • FIX: Implemented secure JSON escaping of the prompt argument using jq -n --arg text "$PROMPT".
  2. Incorrect API Endpoint: An attempt was made to use the Vertex AI regional endpoint (europe-west1-generativelanguage...) with a standard Gemini API Key. This caused curl to return an HTML error, which jq could not parse.

    • FIX: Reverted to the correct global endpoint: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent.
  3. Duplicate Code/Parsing: The script contained two identical lines for processing the API response at the end, leading to error messages being printed twice.

    • FIX: Removed the redundant echo "$RESPONSE" | jq -r ... code.
  4. Authorization Error (403): The initial key generation process in the Google Cloud Console mistakenly led to the creation of a Service Account instead of a simple API Key.

    • FIX: The key was correctly generated by directly selecting the API key option in the Google Cloud Console.

II. :stop_sign: Persistent External Issue (Seeking Advice!)

Despite the code being fully fixed, the script consistently returns an error instead of a model response:

Error: You exceeded your current quota, please check your plan and billing details. (429 RESOURCE_EXHAUSTED)

Critical Details of this Issue:

  • New Quota: The problem persists even after using a brand new API key.

  • Minimal Usage: Google Cloud Console shows the project has logged only 4 total requests, with 75% failure rate, confirming the quota is NOT exhausted.

  • Tailscale Exclusion: The setup was tested with Tailscale/VPN disabled, but the 429 error remained.

  • No Code Issue: The script correctly parses the JSON error response.

My Hypothesis: The issue is likely a permanent throttle applied either to my project ID or my public IP address by Google’s backend, which is not reflected in the standard quota panel.

Question for the Community:

Has anyone experienced a scenario where a new project with near-zero usage receives a persistent 429 error? Is there a hidden limit in the Google Cloud Console I should check, beyond the standard Quotas panel, or is this a platform-side throttling issue?

1 Like

Hi @andrej
Welcome to the AI Forum! Thank you so much for bringing this to our attention.

We’re sorry to hear you’re encountering 429 Resource_Exhausted Error. To help us look into this more closely and find a solution for you, would you mind providing a few additional details?

  • Complete Error Message
  • Billing Tier
  • Model Name
  • Region
  • Platform (e.g., AI Studio or Gemini API SDK)