Unit-test Gemini code with no API calls: google-genai accepts HttpOptions(httpx_client=httpx.Client(transport=httpx.MockTransport(handler)))
Works on google-genai 3.3.0. types.HttpOptions has httpx_client and httpx_async_client fields, so genai.Client(api_key='test', http_options=types.HttpOptions(httpx_client=httpx.Client(transport=httpx.MockTransport(handler)))) runs the real SDK request and response parsing against your handler, with no quota use and no network. The handler receives POST /<api_version>/models/<model>:generateContent with the key in the x-goog-api-key header (not in the URL), and can return httpx.Response(200, json={'candidates': [{'content': {'role': 'model', 'parts': [{'text': 'hello'}]}, 'finishReason': 'STOP'}]}) or an error body {'error': {'code': 429, 'message': '...', 'status': 'RESOURCE_EXHAUSTED'}} to exercise ClientError / ServerError paths. This is how to reproduce hard-to-trigger cases on demand: blocked prompts ({'promptFeedback': {'blockReason': 'SAFETY'}}), MAX_TOKENS with empty content, function-call-only replies, and rate limits, which matters on a free tier with a small daily request budget.