Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw exception if API key ENV vars are empty #2092

Open
1 task done
iloveitaly opened this issue Feb 5, 2025 · 2 comments
Open
1 task done

Throw exception if API key ENV vars are empty #2092

iloveitaly opened this issue Feb 5, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@iloveitaly
Copy link

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

If you use an ENV var for setting the API key, and the ENV happens to be empty, no exception is thrown until a call is made and the exception is ambiguous (i.e., not clear that the token is empty).

To Reproduce

export OPENAI_API_KEY=""

and use the completions API

Code snippets

OS

15.3

Python version

v3.13.1

Library version

1.61.0

@Programmer-RD-AI
Copy link

Hi @iloveitaly, thanks for raising this. From what I’ve seen the API itself eventually throws an error when the API key ENV variable is empty. That said, I'll set up a PR to catch this earlier and provide a clearer message. Let's see what the OpenAI team has to say. Thanks for your patience and input!

@iloveitaly
Copy link
Author

@Programmer-RD-AI it does, but the error is more obscure and you don't end up getting an error until after the code is run, which degrades the DX.

Programmer-RD-AI added a commit to Programmer-RD-AI/openai-python that referenced this issue Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants