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

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Programmer-RD-AI
Copy link

@Programmer-RD-AI Programmer-RD-AI commented Feb 12, 2025

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.

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

Thank you for your time and consideration!

@Programmer-RD-AI Programmer-RD-AI requested a review from a team as a code owner February 12, 2025 05:19
Copy link

@MisileLab MisileLab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think raising an error needs to be in verify_api_key or change the function's name to get_api_key.

@Programmer-RD-AI Programmer-RD-AI changed the title fix(api): implement verify_api_key utility for API key validation fix(api): implement get_api_key utility for API key validation Feb 18, 2025
@Programmer-RD-AI
Copy link
Author

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!

Copy link

@MisileLab MisileLab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just don't forget to change pr's description.
(verify_api_key to get_api_key)

@Programmer-RD-AI
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants