generative-ai-docs
generative-ai-docs copied to clipboard
429 StatusCode "Resource has been exhausted" , Check Quota
Description of the bug:
Hello Dears, I implement a question generator agent with Gemini (model= gemini-pro) and it was working properly till last week and from then I am receiving this confusing error, What should I do? Any suggestion? ERROR: 429 Resource has been exhausted (e.g. check quota). grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.RESOURCE_EXHAUSTED details = "Resource has been exhausted (e.g. check quota)." debug_error_string = "UNKNOWN:Error received from peer ipv4: ########:443 {created_time:"2024-05-26T04:18:56.862289+00:00", grpc_status:8, grpc_message:"Resource has been exhausted (e.g. check quota)."}"
Here is the Code:
import google.generativeai as genai
from dotenv import load_dotenv
import os
from datetime import datetime
import re
import time
def main():
load_dotenv()
os.environ['GOOGLE_API_KEY'] = "API_KEY"
if not os.environ['GOOGLE_API_KEY']:
raise ValueError(
"API key not found. Please set your GEMINI_API_KEY in the environment.")
genai.configure(api_key=os.environ['GOOGLE_API_KEY'])
generation_config = {
"temperature": 0.7,
"top_p": 1,
"top_k": 1,
"max_output_tokens": 150,
}
safety_settings = {
"HARM_CATEGORY_HARASSMENT": "BLOCK_NONE",
"HARM_CATEGORY_HATE_SPEECH": "BLOCK_NONE",
"HARM_CATEGORY_SEXUALLY_EXPLICIT": "BLOCK_NONE",
"HARM_CATEGORY_DANGEROUS_CONTENT": "BLOCK_NONE",
}
model = genai.GenerativeModel(
'gemini-1.5-pro-latest', generation_config=generation_config, safety_settings=safety_settings)
chat = model.start_chat(history=[])
while True:
generate_prompt_qg = [f"""
Ask a question about weather
"""]
print("#################################")
time.sleep(5)
question = chat.send_message(generate_prompt_qg)
user_input = question.text.strip()
print(user_input)
if __name__ == "__main__":
main()
Please be informed that I recreate another project with new API key but the problem still exists.
This is the status of my errors:
and this is the status of my traffic:
The Limitation Quota: {
"displayName": "",
"userLabels": {},
"conditions": [
{
"displayName": "Consumed API - Request count",
"conditionThreshold": {
"filter": "resource.type = \"consumed_api\" AND metric.type = \"serviceruntime.googleapis.com/api/request_count\"",
"aggregations": [
{
"alignmentPeriod": "300s",
"crossSeriesReducer": "REDUCE_NONE",
"perSeriesAligner": "ALIGN_RATE"
}
],
"comparison": "COMPARISON_GT",
"duration": "0s",
"trigger": {
"count": 1
}
}
},
{
"displayName": "Consumer Quota - Quota limit",
"conditionThreshold": {
"filter": "resource.type = \"consumer_quota\" AND metric.type = \"serviceruntime.googleapis.com/quota/limit\"",
"aggregations": [
{
"alignmentPeriod": "300s",
"crossSeriesReducer": "REDUCE_NONE",
"perSeriesAligner": "ALIGN_MEAN"
}
],
"comparison": "COMPARISON_GT",
"duration": "0s",
"trigger": {
"count": 1
}
}
}
],
"alertStrategy": {},
"combiner": "OR",
"enabled": true,
"notificationChannels": [],
"severity": "SEVERITY_UNSPECIFIED"
}
Actual vs expected behavior:
No response
Any other information you'd like to share?
No response