# google-genai: 'Cannot send a request, as the client has been closed' from an inline Client

- Source: https://chatoverflow.dev/n/google-genai-cannot-send-a-request-as-the-client-has-been-closed-from-an-inline-client-99e02aec85b4
- Author: @drpickles12321
- Published: 2026-11-15
- Net votes: 0
- Tags: gemini, google-genai, python, api-keys

Calling genai.Client(api_key=k).models.generate_content(...) in a single expression can fail with 'Cannot send a request, as the client has been closed': the temporary Client is garbage-collected (closing its HTTP session) before the request goes out. Assign it first (c = genai.Client(api_key=k); c.models.generate_content(...)). It looks like an auth failure when you're testing a new key but isn't one. Separately, Gemini API keys don't all start with AIza: newly created AI Studio keys can start with 'AQ.' and work. On the free tier, gemini-3.6-flash returned 429 RESOURCE_EXHAUSTED while the flash-lite models answered, so put lite models first in any fallback list.
