§15.15

Your First Gemini API Request

Get a Gemini API key from AI Studio, set GEMINI_API_KEY, install the google-genai SDK, and make a working request with the Interactions API. Copy-paste.

published 06 Sept 2026 checked against docs 06 Sept 2026 2 min in Building with the API Markdown

On this page5 sections
  1. 1. Key
  2. 2. Python
  3. 3. JavaScript
  4. 4. curl
  5. What differs from Claude and OpenAI

Google’s Gemini API is the third big one after Claude and OpenAI. The current SDKs are google-genai (Python) and @google/genai (JavaScript); the quickstart uses the Interactions API, which takes an input and gives you output_text back.

1. Key

Create a key on the AI Studio API keys page, then put it in the environment the SDK reads by default:

export GEMINI_API_KEY="AIza..."        # macOS/Linux
$env:GEMINI_API_KEY = "AIza..."         # Windows PowerShell, current session

Never paste the key into code you commit — the client picks it up from GEMINI_API_KEY on its own.

2. Python

pip install -U google-genai

Installs the current SDK (the older google-generativeai package is a different, legacy library).

from google import genai

client = genai.Client()  # reads GEMINI_API_KEY

interaction = client.interactions.create(
    model="gemini-3.8-flash",
    input="Explain how AI works in a few words",
)
print(interaction.output_text)

gemini-3.8-flash is the model the quickstart uses today; output_text is the assembled reply. If you need the structured form, the response’s steps carry content blocks with text fields.

3. JavaScript

npm install @google/genai

Node 18+; the client reads GEMINI_API_KEY from process.env.

4. curl

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gemini-3.8-flash", "input": "Explain how AI works in a few words"}'

The key travels in the x-goog-api-key header (not Authorization: Bearer). The text comes back inside steps[].content[].text.

What differs from Claude and OpenAI

  • Header: x-goog-api-key (Gemini) vs x-api-key + anthropic-version (Claude) vs Authorization: Bearer (OpenAI).
  • Shape: one input string in, output_text out — closer to OpenAI’s Responses API than to Claude’s messages array.
  • Image generation has its own model family (gemini-3.1-flash-image in the current docs); text models don’t draw.

Rate limits and free-tier quotas depend on your AI Studio project — check the limits page there before you put this in a loop.


Next: your first Claude API request · your first OpenAI API request · OpenAI API vs Claude API.

← All Building with the API plates · Search all guides

↑↓ move↵ openalt+↵ copy first command

Keyboard

⌘/ctrl+K or /
Search all guides
alt+↵
In search: copy the guide's first command
j / k
Move through a list of guides
c
On a guide: copy its first command
t
Toggle light / dark
?
This list