Generating API Keys for OpenAI, Google Gemini, and Anthropic for usage in Apps Script

Last updated: April 13, 2025

This tutorial will guide you through generating API keys for major AI platforms and adding them as Script Properties in Google Apps Script. Setting up these keys properly allows you to integrate multiple AI services into your Apps Script projects.

Create API Key

OpenAI API Key

  • Go to https://platform.openai.com/

  • Log in to your OpenAI account

  • Open the Settings page by clicking on the gear icon in the top-right corner

  • Select "View API Keys"

  • Click "Create new secret key"

  • Copy your key immediately (it won't be shown again)

  • Store it securely (you'll need it later). Use a password manager or other secure storage.

Google Gemini API Key

  • Go to https://aistudio.google.com/apikey

  • Log in with your Google account

  • Click "Create API key"

  • Create a new project or use an existing one

  • Name your key and click "Create"

  • Copy your key immediately

  • Store it securely (you'll need it later). Use a password manager or other secure storage.

Anthropic API Key

  • Go to https://console.anthropic.com/settings/keys

  • Log in to your Anthropic account

  • Click "Create Key"

  • Name your key and set permissions

  • Copy your key immediately

  • Store it securely (you'll need it later). Use a password manager or other secure storage.

Adding API Keys as Script Properties in Apps Script

Using Script Properties is the recommended way to store information like API keys in Apps Script, rather than pasting them directly into your code.

  • Open your Google Apps Script project.

  • Click on "Project Settings" (the gear icon ⚙️) in the left sidebar menu.

  • Scroll down within the Project Settings until you find the "Script Properties" section.

  • Click "Add script property" (note: You may have to click "Edit script properties" first if you've previously added script properties)

  • Enter the property name: Use a clear, descriptive name that you will reference in your code. Conventionally, these are uppercase with underscores. Examples:

  • OPENAI_API_KEY (for OpenAI models)

  • GOOGLE_API_KEY (for Google Gemini models)

  • ANTHROPIC_API_KEY (for Anthropic models)

  • Paste your secret API key into the "Value" field next to the property name you just entered.

  • Repeat steps 4-6 for each different API key (e.g., one for OpenAI, one for Google) that you plan to use in your project.

  • Click "Save script properties" to save the new property (or properties).

In the screenshot below, I have configured API Keys for all three AI model providers. It is a best practice to only add API Keys for model providers you plan to use in your Apps Script project.

Screenshot of the Apps Script settings page displaying three Script properties.

Accessing API Keys in Your Apps Script Code

Once you configure API Keys as script properties, you can access them in your Apps Script code using the PropertiesService.

function callAIService() {
  // Get API keys from Script Properties
  const openAiKey = PropertiesService.getScriptProperties().getProperty('OPENAI_API_KEY');
  const googleKey = PropertiesService.getScriptProperties().getProperty('GOOGLE_API_KEY');
  const anthropicKey = PropertiesService.getScriptProperties().getProperty('ANTHROPIC_API_KEY');
  
  // Use keys in your API calls
  // ...
}

DISCLAIMER: This content is provided for educational purposes only. All code, templates, and information should be thoroughly reviewed and tested before use. Use at your own risk. Full Terms of Service apply.

Small Scripts, Big Impact

Join 1,500+ professionals who are supercharging their productivity with Google Sheets automation

Exclusive Google Sheets automation tutorials and hands-on exercises
Ready-to-use scripts and templates that transform hours of manual work into seconds
Email updates with new automation tips and time-saving workflows

By subscribing, you agree to our Privacy Policy and Terms of Service