Skip to content

Instantly share code, notes, and snippets.

@codeas
Created June 23, 2025 20:10
Show Gist options
  • Save codeas/9c959d75090400d5ee423cb4b35f50d3 to your computer and use it in GitHub Desktop.
Save codeas/9c959d75090400d5ee423cb4b35f50d3 to your computer and use it in GitHub Desktop.
Calling Gemini API from Google Appps Script
function gemini_(model, payload) {
const apiKey = PropertiesService.getScriptProperties().getProperty('GEMINI_API_KEY');
const api = 'generateContent';
const url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:${api}?key=${apiKey}`;
const options = {
method: 'POST',
contentType: 'application/json',
muteHttpExceptions: true,
payload: JSON.stringify(payload),
};
const response = UrlFetchApp.fetch(url, options).getContentText()
console.log(response)
const data = JSON.parse(response);
return data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment