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

[Feat]: Implement Regex Validation for OpenAI Key Format #124

Closed
yatendra2001 opened this issue Dec 24, 2023 · 4 comments
Closed

[Feat]: Implement Regex Validation for OpenAI Key Format #124

yatendra2001 opened this issue Dec 24, 2023 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@yatendra2001
Copy link
Contributor

Is your feature request related to a problem?

Currently, the isOldOpenAIKey function uses a simple startsWith check to validate OpenAI keys. This method is not robust and may not accurately validate all key formats.

Describe the solution that you'd like

The solution is to refactor the isOldOpenAIKey function to use a regular expression(REGEX) that matches the expected format of OpenAI keys. This will provide a more accurate validation method.

Describe alternatives that you have considered

An alternative could be to use a third-party library designed for API key validation, but this may introduce unnecessary dependencies. So let's leave it for now.

Additional Information

Research the expected format of both old and new OpenAI keys to create an accurate regex pattern.

Acceptance Criteria

  1. The isOldOpenAIKey function uses regex for validation.
  2. The function should not produce false positives or negatives.
@yatendra2001 yatendra2001 added enhancement New feature or request good first issue Good for newcomers labels Dec 24, 2023
@Yash-Khattar
Copy link

Hey,
I searched and found a similar issue on OpenAI Community Chat (link attached)
https://community.openai.com/t/what-are-the-valid-characters-for-the-apikey/288643

According to it the most common pattern is : sk-[20 characters]T3BlbkFJ[20 characters]

so we can try and create regex according
lemme know if it suits, would like to work on this issue.

@yatendra2001
Copy link
Contributor Author

Hey @Yash-Khattar, Thanks for showing interest in this issue.

I'm on board with the approach, but we need to confirm the exact format of OpenAI keys before moving forward. While it seems likely they follow the pattern sk-[20 characters]T3BlbkFJ[20 characters], we can't rely on assumptions for something this critical.

Here's what I've found so far:

  1. No Official Regex: OpenAI hasn't released an official regular expression for key validation yet (see link: https://community.openai.com/t/regex-s-to-validate-api-key-and-org-id-format/44619).
  2. Community Observations: Some community members have observed the sk-[20 characters]T3BlbkFJ[20 characters] pattern, but it's not guaranteed.

Proposal:

I suggest we keep this issue open until we have an official regex from OpenAI. Once it's available, we can quickly incorporate it for accurate key validation.

Please let me know if you have any other thoughts or suggestions.

@Yash-Khattar
Copy link

Sure, sounds cool,
let's wait for any official regex from openAI itself.

@yatendra2001
Copy link
Contributor Author

Closing it since there's no estimated date for REGEX, we can re-open once an official regex is out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants