Google Gemini API Quickstart: From AI Studio to Your First Request
A practical companion to Google's official quickstart: create a key, protect it, make a text request, and turn the prototype into a maintainable app.
Open the official tutorialWhat this tutorial is for
Google's Gemini API quickstart is the right first stop for developers new to Gemini. The useful learning order is not to study every model first. Close one small loop: obtain a key, read it from an environment variable, make one request, and inspect the response.
Step 1: Create a key in AI Studio
Create a key in Google AI Studio and store it in an environment variable such as GEMINI_API_KEY. Never put it in browser code, commit it to Git, or include it in screenshots. A browser app should call your backend; the backend owns the secret.
Step 2: Validate the smallest request
Whether you use JavaScript, Python, or REST, the first request should do one thing: ask a short question and print the text response. Do not add RAG, tool calls, streaming, or a complex system prompt until the basic path works.
```ts import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY }); const response = await ai.models.generateContent({ model: "gemini-2.5-flash", contents: "Explain cross-border commerce in one sentence.", }); console.log(response.text); ```
Model names, SDK syntax, and regional availability change. Treat the snippet as a learning shape and use Google's current documentation before production deployment.
Step 3: Move from demo to production
Add input and rate limits, request IDs, latency and error logging, timeout/retry handling, and privacy and safety checks. Never treat model output as a source of truth for pricing, compliance, or order status; retrieve those facts from your own systems.
A useful first project
For a cross-border team, classify English inquiries into quote, lead time, certification, and after-sales categories, then generate a draft for human approval. Measure accuracy, time saved, and edit rate instead of whether the answer merely sounds intelligent.
Official source: Google Gemini API Quickstart. This is a structured companion, not a replacement for Google's SDK, quota, or safety documentation.