fix(api): implement get_api_key utility for API key validation
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_keyfunction insrc/openai/_utils/_utils.py. - Updating API client initialization in
src/openai/_client.pyandsrc/openai/lib/azure.pyto 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!
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!
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!
thanks for the PR but I think we're happy with the current code as-is.