Are there any ‘official’ regular expressions for the API key string and the Organisation ID string formats?
To save pointless usage of the api endpoint, I would like to do some simple pre-validation in my functions before attempting a connection/authentication.
Hey! We don’t have anything official to do this right now but it’s a good suggestion. Can’t promise we will have anything soon but you can ask ChatGPT to write the regex for you and it should be pretty close to what you need for something like this.
For reference, this is the output ChatGPT gave me:
function isValidFormat(apiKey) {
// Check if it's a string, has some length, and starts with 'sk'
return typeof apiKey === 'string' && apiKey.length > 0 && apiKey.startsWith('sk');
}
var apiKey = 'YOUR_API_KEY_HERE'; // Replace with your OpenAI key
console.log(isValidFormat(apiKey) ? 'Key format looks good' : 'Key format is incorrect');