google / generative-ai-docs

Documentation for Google's Gen AI site - including the Gemini API and Gemma
https://ai.google.dev
Apache License 2.0
1.46k stars 494 forks source link

429 StatusCode "Resource has been exhausted" , Check Quota #438

Closed saramirabi closed 1 week ago

saramirabi commented 1 month ago

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: image and this is the status of my traffic: image

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

singhniraj08 commented 1 month ago

@saramirabi, Thank you reporting this issue. This looks like an rate limit error. This repository is for issues related to website(https://ai.google.dev/) like documentation bugs or improvements. For issues related to Gemini, we would suggest you to use "Send Feedback" option in Gemini docs. Ref: Screenshot below. You can also post this issue on Discourse forum.

image

github-actions[bot] commented 3 weeks ago

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

github-actions[bot] commented 1 week ago

This issue was closed because it has been inactive for 28 days. Please post a new issue if you need further assistance. Thanks!