openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

fix(api): implement get_api_key utility for API key validation

Open prdai opened this issue 10 months ago • 2 comments

This PR introduces a new utility function, get_api_key, to validate API key environment variables more effectively. Previously, if an API key ENV var was empty, the error raised during API calls was ambiguous. With this update, we now check for empty API keys upfront and return a clearer, descriptive error message.

Changes include:

  • Adding the get_api_key function in src/openai/_utils/_utils.py.
  • Updating API client initialization in src/openai/_client.py and src/openai/lib/azure.py to leverage the new utility.

This change addresses issue #2092 by ensuring that an exception is thrown when API key ENV vars are empty, thus improving error reporting clarity. I'm grateful for the feedback, and I'll continue to monitor any responses from the OpenAI team.

  • [x] I understand that this repository is auto-generated and my pull request may not be merged

Thank you for your time and consideration!

prdai avatar Feb 12 '25 05:02 prdai

Hey @MisileLab, thanks for the feedback. I've updated the code as suggested—I've renamed the function to get_api_key and incorporated the error-raising logic directly within it. Let me know if you need any further adjustments!

prdai avatar Feb 18 '25 01:02 prdai

Hey @MisileLab, I updated the PR description to replace all instances of verify_api_key with get_api_key as suggested. Thanks for the feedback!

prdai avatar Feb 18 '25 03:02 prdai

thanks for the PR but I think we're happy with the current code as-is.

RobertCraigie avatar Jul 10 '25 11:07 RobertCraigie