This is the code I am trying to run :
import os
from dotenv import load_dotenv
from google import genai
load_dotenv()
key = os.getenv("GEMINI_API_KEY").strip()
print(key)
client = genai.Client(api_key=key)
response = client.models.generate_content(
model="gemini-2.0-flash", contents="Explain why I am dumb"
)
print(response.text)
The curious thing is that I only get the quota exhausted error when importing the API key from the .env file. Otherwise this works fine when I enter the api key directly in the api_key parameter.
Hello Aditya,
Welcome to the community,
You may have a misunderstanding—using .env
to load the API key should not cause a quota exhausted error.
Gemini Flash has a rate limit of 15 requests per minute (RPM) on the free plan. It’s possible that you hit this limit and which made you seem like .env
was causing the issue.
Here you can check, I have tested on google colab:
1 Like
Hello! Thank you for the response! That does not seem to be the issue, I tried this again today and got the quota exceeded error. But as soon as I wrote it like so (within seconds) :
key2 = "xyzzy"
client = genai.Client(api_key=key2)
It worked again. If the problem was quota being exceeded, it should have persisted.
That’s very strange; I’m curious to see your code. Could you share your code, including the masked key?