[Feat]: Implement Regex Validation for OpenAI Key Format
yatendra2001 opened this issue · comments
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
- The isOldOpenAIKey function uses regex for validation.
- The function should not produce false positives or negatives.
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.
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:
- 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).
- 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.
Sure, sounds cool,
let's wait for any official regex from openAI itself.
Closing it since there's no estimated date for REGEX, we can re-open once an official regex is out.