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.
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:
-
JSON Escaping Error (Slovak Characters): The original code failed to handle Slovak UTF-8 characters (
č, š, ť, ž), leading to ajq: parse error: Invalid numeric literal.- FIX: Implemented secure JSON escaping of the prompt argument using
jq -n --arg text "$PROMPT".
- FIX: Implemented secure JSON escaping of the prompt argument using
-
Incorrect API Endpoint: An attempt was made to use the Vertex AI regional endpoint (
europe-west1-generativelanguage...) with a standard Gemini API Key. This causedcurlto return an HTML error, whichjqcould not parse.- FIX: Reverted to the correct global endpoint:
https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent.
- FIX: Reverted to the correct global endpoint:
-
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.
- FIX: Removed the redundant
-
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.
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?