Skip to content

Instantly share code, notes, and snippets.

@abfo
Last active May 31, 2025 17:32
Show Gist options
  • Save abfo/d22cad91e1b1bb398ca4d72826c39dce to your computer and use it in GitHub Desktop.
Save abfo/d22cad91e1b1bb398ca4d72826c39dce to your computer and use it in GitHub Desktop.
Google Apps Script to send an alert when a new OpenAI model is available. Instructions at https://ithoughthecamewithyou.com/post/get-an-email-when-a-new-openai-model-is-available-via-the-api
var AlertEmail = '';
var OpenAIAPIKey = '';
function main() {
// we store known models in script properties
var scriptProperties = PropertiesService.getScriptProperties();
var currentProps = scriptProperties.getProperties();
var anythingNew = false;
var newText = '';
// get list of models that the OpenAIAPIKey has access to
var options = {
'method' : 'get',
'headers' : {
'Authorization': 'Bearer ' + OpenAIAPIKey
},
'muteHttpExceptions': true
};
var response = UrlFetchApp.fetch('https://api.openai.com/v1/models', options);
var json = JSON.parse(response.getContentText());
// chech for new models
if (json.data) {
json.data.forEach(function(model) {
if (!(model.id in currentProps)) {
scriptProperties.setProperty(model.id, model.owned_by);
anythingNew = true;
newText += 'New Model: ' + model.id + '\n';
Logger.log('New Model: ' + model.id)
}
});
} else {
Logger.log('Error: ' + response.getContentText());
}
// send an email if we found anything new
if (anythingNew){
MailApp.sendEmail(AlertEmail, 'New OpenAI Models on ' + new Date(), newText)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment