Skip to content

Reject empty OpenAI API keys - #203

Open
Button99 wants to merge 1 commit into
openai-php:mainfrom
Button99:main
Open

Reject empty OpenAI API keys#203
Button99 wants to merge 1 commit into
openai-php:mainfrom
Button99:main

Conversation

@Button99

Copy link
Copy Markdown

What:

  • Bug Fix
  • New Feature
  • Docs

Description:

This PR treats empty and whitespace-only OpenAI API keys as missing configuration.

Previously, config('openai.api_key') only had to be a string. That allowed values like '' or ' ' to pass validation and build a client, causing the failure to happen later as an API authentication error instead of the package's ApiKeyIsMissing exception.

Related:

N/A

@iBotPeaches iBotPeaches left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm fairly sure this will break OIDC for those using AWS Bedrock roles vs keys. I'll have to test when I have a chance. Since we keep the API key blank and it assumes the role for some ephemeral OIDC token.

Though looking at code it was probably accidental that it worked that way in the first place. Good find regardless, but don't want to risk this enforcement until I understand the different ways we can auth outside of a basic api key.

So holding for a bit.

@Button99

Copy link
Copy Markdown
Author

That makes sense. I did not consider OpenAI-compatible/custom base URI setups where auth may happen outside of a static API key.

Would you prefer this validation to only reject empty API keys when using the default OpenAI base URI, while allowing empty keys for custom openai.base_uri configurations?

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