-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClientError 429 RESOURCE_EXHAUSTED on first use of gemini-2.0-flash-exp
with Google Search tool after 2-day idle period
#17
Comments
thank you for posting this - cause it does not look at all like any of the actual code examples google gives in their documentation for how to use grounding search - and for me this actually worked - after 3 hours now of banging my head against their out of date docs - i was about to give up and came here to the issues tab and found your code which finally got me grounding results. it looks nothing like what they show in documentation. |
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. |
after having a lot of head banging with the docs, to the point went in the entire actual downloaded packages code base to figure out whats going on and what i actually need to implement to fix issue since i gotten that docs are wrong. i got to so many times exhausted usage and was confused alot, it seems it might be their side issue since i can use it on ai studio from google import genai
from google.genai.types import Tool, GenerateContentConfig, GoogleSearch
model_id = "gemini-2.0-flash-exp"
client = genai.Client(api_key="YOUR_API_KEY", http_options={'api_version': 'v1alpha'},)
search_tool = {'google_search': {}}
response = client.models.generate_content(
model=model_id,
contents="time in india",
config= GenerateContentConfig(
tools=[search_tool],
)
)
print(response.text) |
I tried so many things, but it's still not working. Have you gotten it to work? from google import genai
from google.genai.types import (
GenerateContentConfig,
Tool,
GoogleSearch,
GoogleSearchRetrieval,
)
client = genai.Client(
api_key="YOUR_API_KEY",
http_options={"api_version": "v1alpha"},
)
mytools = [
Tool(
google_search=GoogleSearch(),
google_search_retrieval=GoogleSearchRetrieval(),
),
]
response = client.models.generate_content(
model="gemini-2.0-flash-exp",
contents="time now in UK",
config=GenerateContentConfig(
tools=mytools,
),
)
print(response.text) |
ai studio is still working with search grounding, i tried even with cURL and getting the same error 429. I'm not sure what to do at this point since if it's not even working with a simple POST request. |
Hi, I just tried @YoussefElsafi code and it works for me without issue. Does folks here still observe 429 when trying the gemini-2.0-flash-exp with Google Search tool? Think 429 should be related to quota issue. Is the API KEY shared with anyone? Thanks, |
Yes, I am observing the same issue here. API KEY not shared. |
The free tier should offer about 1000 grounding searches per day. Are you trying to use it more than that or is it blocking from the first try? |
I have been getting a similar error for a similar circumstance (first try even after a day of inactivity) for every experimental model available: |
@andre-motorway, the error message you shared seems return by Vertex AI backend. Can you double confirm which backend you are using? If possible, can please share the script that you used for the testing? |
Yes, indeed is a Vertex AI backend. import vertexai
from google import genai
from google.genai.types import (
GenerateContentConfig,
Tool,
GoogleSearch,
GoogleSearchRetrieval,
SafetySetting,
)
from google.api_core.exceptions import GoogleAPIError
from tenacity import (
retry,
stop_after_attempt,
wait_exponential,
retry_if_exception_type,
)
from .models import FollowUpQuestions
from config.config import Config # Use absolute import
# Initialize Vertex AI
vertexai.init(project=Config.PROJECT_ID, location=Config.LOCATION)
client = genai.Client(
vertexai=True, project=Config.PROJECT_ID, location=Config.LOCATION
)
google_search_tool = Tool(google_search=GoogleSearch())
google_search_retrieval_tool = Tool(google_search_retrieval=GoogleSearchRetrieval())
.
.
.
try:
.
.
.
response = client.models.generate_content(
model=model,
contents=prompt,
config=GenerateContentConfig(
system_instruction=system_instructions,
temperature=0,
tools=tools,
response_modalities=["TEXT"],
safety_settings=[
SafetySetting(
category="HARM_CATEGORY_HATE_SPEECH",
threshold="BLOCK_MEDIUM_AND_ABOVE",
),
SafetySetting(
category="HARM_CATEGORY_DANGEROUS_CONTENT",
threshold="BLOCK_MEDIUM_AND_ABOVE",
),
SafetySetting(
category="HARM_CATEGORY_HARASSMENT",
threshold="BLOCK_LOW_AND_ABOVE",
),
SafetySetting(
category="HARM_CATEGORY_SEXUALLY_EXPLICIT",
threshold="BLOCK_ONLY_HIGH",
),
],
),
)
return response
except Exception as e: # Catch a broader range of exceptions
print(f"An ground_data error occurred: {str(e)}")
raise # Re-raise for tenacity to handle |
For Vertex AI, you need to contact Vertex AI support when encountering prediction request quota issues for Gemini: https://cloud.google.com/vertex-ai/docs/general/troubleshooting?authuser=8&component=any#error_code_429 |
Thanks, @sasha-gitg. Since the question should be asked in vertex-ai, I'm closing the issue now. |
After the latest update today, the issue has been resolved, and it is now functioning as expected. import os
from typing import List
from google.genai import Client
from google.genai.types import GenerateContentConfig, Content, Tool, GoogleSearch
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
client = Client(api_key=GEMINI_API_KEY)
messages: List[Content] = [
Content(
role="user",
parts=[{"text": "do search online about: Salford City vs. Bromley and find the match report"}],
),
]
config = GenerateContentConfig(
system_instruction="""You are a helpful assistant.
You have to do deep research and provide a detailed answer
""",
tools=[Tool(google_search=GoogleSearch())],
)
response = client.models.generate_content(
model="gemini-2.0-flash",
contents=messages,
config=config,
)
print(response)
print(response.text) |
The issue has not been resolved, it was just that Gemini 2.0 Flash that the above code uses is not experimental, but generally available. If you try with experimental models, you will notice the issues remains. |
I have dealt with the issue by instantiating the GenAI SDK client using a Gemini API KEY instead of through Vertex AI. |
This is a Vertex AI issue; Gemini AI Studio is not subject to this quota limit. Why does Google impose limitations on production users instead of free users? |
@andre-motorway Hey! You should migrate off the experimental models and use the production ready / GA version. The experimental models typically get shut down soon after the GA models comes out. |
Hey @homjay, not sure I follow "Why does Google impose limitations on production users instead of free users?", you can take the Google AI Studio version to production today, pls let me know if you run into any issues doing so. |
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 am encountering a
ClientError: 429 RESOURCE_EXHAUSTED
error when attempting to use thegemini-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:
Expected Behavior:
The
gemini-2.0-flash-exp
model should be able to generate responses using the Google Search tool without raising aRESOURCE_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:
API_KEY
to a valid Google AI API key.Error Output:
Additional Information:
v1alpha
API version.gemini-2.0-flash-exp
model is specified.GenerateContentConfig
.gemini-2.0-flash-exp
model being in an experimental stage and possibly having stricter quota limitations, unexpected quota reset behavior, or issues with tool integration?RESOURCE_EXHAUSTED
error specifically when using tools withgemini-2.0-flash-exp
, even on the first request after a period of inactivity?Request:
Please investigate this issue and provide guidance on how to resolve the
RESOURCE_EXHAUSTED
error when using thegemini-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.The text was updated successfully, but these errors were encountered: