Created
June 23, 2025 20:10
-
-
Save codeas/9c959d75090400d5ee423cb4b35f50d3 to your computer and use it in GitHub Desktop.
Calling Gemini API from Google Appps Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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