CLI Fails with 429 Error on Second Request (Even with a New API Key)
Describe the bug The Gemini CLI fails with an immediate 429 Resource has been exhausted error on the second prompt of any interactive session. The first prompt succeeds reliably, but all subsequent prompts in the same session fail with the 429 error.
This appears to be a state-management bug within the CLI's interactive session handler, as the API key used works perfectly in other applications.
Client information Platform: macOS (Darwin 24.0.0)
/about command output:
[PLEASE RUN /about IN THE GEMINI CLI AND PASTE THE OUTPUT HERE] Login information I am authenticating via an API key set using the GEMINI_API_KEY environment variable in my .zshrc file.
Additional context This bug is highly reproducible and appears to be independent of the specific API key.
New Key Confirmed: The issue persists even after I went into Google AI Studio, deleted my old key, and generated a brand-new one.
Key Works Elsewhere: The API key I am using is confirmed to work perfectly in other non-CLI Google AI applications. My account's quota is not actually exhausted.
Installation Issues: The initial installation via npm install -g @google/gemini-cli also failed to create the necessary gemini command symlink in the global bin directory. A full npm uninstall and npm install was required to fix the command not found error. This may indicate a broader issue with the package configuration.
Stack Trace: The failure on the second prompt produces the following stack trace, pointing to an error in useGeminiStream.js:
... at async file:///Users/heathen-admin/.npm-global/lib/node_modules/@google/gemini-cli/dist/src/ui/hooks/useGeminiStream.js:276:26 at async file:///Users/heathen-admin/.npm-global/lib/node_modules/@google/gemini-cli/dist/src/ui/hooks/useGeminiStream.js:343:38 { status: 429 }
Describe the bug When a prompt is submitted, the Gemini CLI fails its first few attempts with a 429 Resource Exhausted error, printing the full error and stack trace directly to the console. However, its internal retry mechanism eventually succeeds, and the correct response is printed after all the error messages.
This creates an extremely confusing and alarming user experience, making the tool appear broken even when it eventually works. The errors from failed intermediate retries should be suppressed from the final output.
Client information Platform: macOS
Login information Using a brand-new API key set via the GEMINI_API_KEY environment variable.
Additional context This happens even on the very first, non-interactive command (gemini --prompt "hello"). The underlying 429 errors on initial attempts seem to be a server-side issue, but the CLI's failure to handle these retry errors gracefully is a client-side usability bug. Here is an example of the broken output:
gemini --prompt "hello" Attempt 1 failed with status 429. Retrying with backoff... ApiError: ... [Full Stack Trace for Attempt 1] Attempt 2 failed with status 429. Retrying with backoff... ApiError: ... [Full Stack Trace for Attempt 2]
Hello! How can I help you today?
Body:
Describe the bug The Gemini CLI is currently unusable due to a cascade of contradictory errors on the first command. When a prompt is submitted (gemini --prompt "hello"), the CLI's internal retry logic fails with different error messages on each attempt.
Attempt 1: Fails with a 429 Resource has been exhausted error.
A subsequent retry: Fails with a 400 API key expired. Please renew the API key. error.
Client information Platform: macOS
Login information Using a brand-new API key, confirmed to be active in AI Studio and working in other apps, set via the GEMINI_API_KEY environment variable.
Additional context This demonstrates a severe instability in either the CLI's retry logic or the API backend. The server is returning different, incorrect error statuses for the same request during a single execution. This makes the tool completely unreliable. Here is an example of the log:
gemini --prompt "hello" Attempt 1 failed with status 429. Retrying with backoff... ApiError: {"error":... "status": "RESOURCE_EXHAUSTED"...} [API Error: {"error":... "code": 400, "message": "API key expired...", "reason": "API_KEY_INVALID"...}]
Please note, we are continuing to investigate this issue. We are discussing a very similar (possibly the same ) issue in #1502