Hello,
Hope everyone is doing well. I’ve been having some trouble with calling the GPT 4.1 mini API via my .env file.
When I hard code the API key everything works fine. Checking my directory everything is where it’s suppose to be. I even ran a separate script to check my env and the API key loads just fine.
This is the error message I’m getting:
OpenAI API error: You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors .
I’ve loaded money into my account. I have about $20 worth of credits. I haven’t exceeded any limits. I’ve barely got a chance to use it…
I’m confused, if anyone could aid in shining some light and giving some clarity I’d really appreciate it.
Thanks again.
Welcome to the community!
If it works hardcoded, I would print out the env to make sure it has the right value. Sounds like it’s not loading correctly.
Let us know if that doesn’t work.
_j
June 10, 2025, 4:57pm
3
This post’s script will attempt to make a “list models” call - then give you all the env variables that the client is actually detecting and using, so you can see if others are being grabbed and conflicting, such as a different organization.
Have you tried printing the API key the code obtains, to ensure you have set the key you think you are using?
Here’s a better version of finding out the credentials that are used - which are automatic and don’t need you to specify the default environment variable key.
import openai
def get_org_model(client, model="gpt-4o-mini"):
try:
return client.models.retrieve(model).id # Makes test API call
except Exception as your_error:
return your_error
def env_info():
cl…
The main issue was that my system was using a global key… Once I deleted it out of Environment Variables everything worked as should.
I appreciate the help.
This scripted helped a lot. My system was using a global key. Once I figured that out and deleted it the calls started going through.
Thanks for the help. Much appreciated.
Thanks Man!
Was stuck for about 4-5 hours lol
T_O
November 2, 2025, 9:11pm
7
THANK YOU , I was using a global key that I set in my system environment variables in the past!