Hands-On AI WorkshopHomeProjectsLearnResourcesPresenterHelpProgress

Gemini Setup Center

Connect your own Apps Script project to the Gemini API safely. Ten of the thirty projects (15–20, 24, 27, 29, 30) call Gemini at run time. In this website those calls are answered by prepared fixtures; nothing is sent to Google.

Your API key belongs in your Apps Script project's Script Properties only. Never paste it into a web page, a spreadsheet cell, a shared document or this site. This site never asks for it.

Twelve steps

  1. Open Google AI Studio and sign in.
  2. Create or select an API key (Get API key). Use a key dedicated to this workshop.
  3. Open the lesson's Apps Script project (from the spreadsheet: Extensions → Apps Script).
  4. Open Project Settings (gear icon).
  5. Under Script Properties choose Add script property.
  6. Name it exactly GEMINI_API_KEY (the name the repository's callGemini reads) and paste the key as the value.
  7. Add GEMINI_MODEL with a model available to your key. The repository sets no default. The deck shows gemini-flash-lite-latest on one slide and gemini-2.5-flash on another; model availability changes, so confirm with step 10.
  8. Save the script properties and the project.
  9. Run the lesson's checkPermissions function (where present) or the entry point once, and accept the authorization prompt (it needs "Connect to an external service").
  10. Optional: add GeminiDiagnostics.gs from the tools ZIP and run testGeminiConnection(); listGeminiModels() lists models that support generateContent. Both print only a masked key. These diagnostics are a DiscoveryVIP addition: the deck mentions a connection test, but the repository does not contain one.
  11. Inspect the result in the execution log: HTTP 200 and a short reply mean you are ready.
  12. Run the first AI application (Project 15) from Workshop → Run application, and check every output row before using it.

The repository's helper calls https://generativelanguage.googleapis.com/v1beta/models/MODEL:generateContent with the key in the x-goog-api-key header and requests responseMimeType: application/json for JSON tasks. Check the current official Gemini API documentation for supported models and methods.

Check a key is masked before you share a screenshot

Troubleshooting

ProblemWhat you seeWhat to do
Missing API keyError "Add GEMINI_API_KEY in Script Properties" (or similar from callGemini).Project Settings → Script Properties → add GEMINI_API_KEY. The name must match exactly (case-sensitive).
Invalid API keyHTTP 400 "API key not valid" or HTTP 403.Create a new key in Google AI Studio; paste it without spaces or quotes. Check the key is not restricted to other APIs.
Malformed numeric input"Invalid number" or "Invalid amount" thrown before the AI call.The code validates sheet values first. Fix the cell (no currency symbols or words) and rerun.
Unsupported modelHTTP 404 "models/... is not found for API version v1beta".Set GEMINI_MODEL to a model your key can use. Run listGeminiModels() from GeminiDiagnostics.gs to see the models that support generateContent.
HTTP 400Invalid JSON payload or unsupported argument.Check generationConfig fields and the model name. Do not hand-edit the request structure in callGemini.
HTTP 401 or 403Unauthenticated or permission denied.Key missing, wrong, deleted or restricted; or the Generative Language API is not enabled for the key's project.
HTTP 404Model or endpoint not found.Model name typo or retired model. Use the diagnostic to list available models.
HTTP 429Quota or rate limit exhausted.Wait and retry with backoff; process fewer rows per run. Check your quota in AI Studio.
Server errors (500/503)Internal or overloaded.Transient: retry later with backoff (Project 20, Challenge 3, shows how).
Invalid JSONJSON.parse error in the AI helper.Request JSON mode (responseMimeType application/json), strip ``` fences, then validate. Never use unparsed text.
Unexpected response structurecandidates missing or empty, or not an array where one is expected.Check finishReason and safety blocks; treat as a failed call and keep the rows unprocessed.
Missing required fieldsValidator rejects a record (missing id, category or field).Do not fill the gap yourself. Leave the row for review or retry; tighten the prompt with an explicit schema.

Practise every one of these safely in any Gemini project's Workspace: choose a prepared response such as "HTTP 429" or "Invalid JSON" in the Gemini response menu and run the original code.

Optional live Gemini on your own website

Live calls from a public page must go through your own server, which holds the key. The tools ZIP includes gemini-proxy.example.php.txt: a minimal, disabled-by-default PHP proxy that reads the key from an environment variable, enforces a size limit, a rate limit and a model allow-list, and never returns the key. It is an example only and is not installed on this site; this site makes no live AI calls.