Building with the API

Your First Gemini API Request

2 min read

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

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.

Open the full interactive version (with copy buttons) ↗

← All guides