1. The exact error message: API key not valid. Please pass a valid API key.
  2. The environment: Google Apps Script (Standalone Project).
  3. The steps you have already taken (e.g., generated a new key, enabled the Generative Language API in GCP, linked the Apps Script project to a Standard GCP Project).

Hi @Christopher_Ward,

Welcome to the Google AI Forum! :confetti_ball: :confetti_ball:

Please check the following:

  1. Confirm GCP Project Linkage: In the Apps Script editor, go to Project Settings (gear icon) → Google Cloud Platform (GCP) Project . Ensure the Project Number listed there matches the GCP project you are working in.
  2. If step 1 is correct, then it must be Application restrictions (like HTTP referrers or IP addresses) to your API key in the Google Cloud Console.. To confirm this, Temporarily set your API key restrictions to None in the Google Cloud Console > APIs & Services > Credentials and test your API.

Hope this helps resolve the issue