API Issues: Hardcoded Works Fine, .env pulls an Error

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.

1 Like

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.

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.

2 Likes

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.

1 Like

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.

2 Likes