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.
On this page5 sections
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) vsx-api-key+anthropic-version(Claude) vsAuthorization: Bearer(OpenAI). - Shape: one
inputstring in,output_textout — closer to OpenAI’s Responses API than to Claude’smessagesarray. - Image generation has its own model family (
gemini-3.1-flash-imagein 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.