python-genai: ClientError 429 RESOURCE_EXHAUSTED on first use of `gemini-2.0-flash-exp` with Google Search tool after 2-day idle period
I am encountering a ClientError: 429 RESOURCE_EXHAUSTED error when attempting to use the gemini-2.0-flash-exp model with the Google Search tool. This error occurs immediately upon sending the first message in a chat session, even after a period of approximately 48 hours of inactivity, indicating that this is not a result of exceeding typical usage quotas.
Environment Details:
- Programming Language: Python
- Operating System: Windows 11
- Python Version: 3.12.5
- Package Versions: google-genai 0.2.2
Expected Behavior:
The gemini-2.0-flash-exp model should be able to generate responses using the Google Search tool without raising a RESOURCE_EXHAUSTED error, especially when the API has not been used for an extended period.
Actual Behavior:
A ClientError: 429 RESOURCE_EXHAUSTED error is raised immediately after sending the first message to the model.
Steps to Reproduce:
- Environment Setup:
- Install the required packages as listed in the “Environment Details” section below.
- Set the environment variable
API_KEYto a valid Google AI API key.
- Code:
from google import genai from google.genai import types import os MODEL_ID = "gemini-2.0-flash-exp" search_tool = {'google_search': {}} client = genai.Client(http_options={'api_version': 'v1alpha'}, api_key=os.environ["API_KEY"]) chat = client.chats.create( model=MODEL_ID, config=types.GenerateContentConfig( tools=[search_tool], ), ) def handle_response(response): """Handles the response from the model, including grounding metadata.""" for candidate in response.candidates: for part in candidate.content.parts: if part.text: print("Model:", part.text) if candidate.grounding_metadata and candidate.grounding_metadata.search_entry_point: print("Search Results:") print(candidate.grounding_metadata.search_entry_point.rendered_content) def main(): """Main function to run the chat loop.""" print("Start chatting with the model (type 'exit' to quit)") while True: user_input = input("You: ") if user_input.lower() == 'exit': print("Exiting chat.") break response = chat.send_message(user_input) handle_response(response) if __name__ == "__main__": main() - Run the Script: Execute the Python script.
- Send Message: Send any message (e.g., “hi”) to the model.
Error Output:
CMD> python genai_google_search.py
Start chatting with the model (type 'exit' to quit)
You: hi
Traceback (most recent call last):
File "C:\Users\Youssef\Desktop\Coding\AI Development\BatchBot\genai_google_search.py", line 45, in <module>
main()
File "C:\Users\Youssef\Desktop\Coding\AI Development\BatchBot\genai_google_search.py", line 41, in main
response = chat.send_message(user_input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Youssef\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\genai\chats.py", line 63, in send_message
response = self._modules.generate_content(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Youssef\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\genai\models.py", line 4393, in generate_content
response = self._generate_content(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Youssef\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\genai\models.py", line 3655, in _generate_content
response_dict = self.api_client.request(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Youssef\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\genai\_api_client.py", line 321, in request
response = self._request(http_request, stream=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Youssef\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\genai\_api_client.py", line 261, in _request
return self._request_unauthorized(http_request, stream)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Youssef\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\genai\_api_client.py", line 283, in _request_unauthorized
errors.APIError.raise_for_response(response)
File "C:\Users\Youssef\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\genai\errors.py", line 100, in raise_for_response
raise ClientError(status_code, response)
google.genai.errors.ClientError: 429 RESOURCE_EXHAUSTED. {'error': {'code': 429, 'message': 'Resource has been exhausted (e.g. check quota).', 'status': 'RESOURCE_EXHAUSTED'}}
CMD>
Additional Information:
- I have verified that my API key is valid.
- I am using the
v1alphaAPI version. - The
gemini-2.0-flash-expmodel is specified. - The Google Search tool is correctly configured in the
GenerateContentConfig. - Crucially, I have not used the Google Search tool (or any other Gemini API) for approximately 48 hours prior to encountering this error. This strongly suggests that the error is not due to exceeding normal API usage quotas.
- Could this be related to the
gemini-2.0-flash-expmodel being in an experimental stage and possibly having stricter quota limitations, unexpected quota reset behavior, or issues with tool integration? - Suggestion: It would be helpful if the documentation could clarify the quota limits and reset mechanisms for experimental models, especially when used with tools. It would also be helpful to confirm that quotas are properly reset after periods of inactivity.
- Have others experienced this
RESOURCE_EXHAUSTEDerror specifically when using tools withgemini-2.0-flash-exp, even on the first request after a period of inactivity? - Is there any account-specific information or quota dashboard that I can access to verify my API usage and quota status for experimental models?
Request:
Please investigate this issue and provide guidance on how to resolve the RESOURCE_EXHAUSTED error when using the gemini-2.0-flash-exp model with the Google Search tool, particularly in light of the fact that this is occurring on the very first request after an extended idle period.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 20 (3 by maintainers)
Is this issue resolved? I am still getting a lot of 429 errors when calling with a delay of even up to 20+ seconds after a dozen calls, not on experimental models but models like gemini-2.0-flash or flash-lite, the quota usage shown on the google console dashboard is also very low. I am not using Vertex AI
I have dealt with the issue by instantiating the GenAI SDK client using a Gemini API KEY instead of through Vertex AI.
Yes, I am observing the same issue here. API KEY not shared.
@Atlas3DSS
Hey, thanks for chiming in! I’m glad my code example (even though it’s highlighting an error for me) was helpful for you. It’s definitely concerning that the official docs aren’t reflecting the correct way to implement the search tool. Hopefully, this issue will help get that addressed. I appreciate you sharing your experience - it really validates that there’s something not quite right on the Google side.