Getting Started with the Gemini API: Your First Call in Under a Minute
Get a Gemini API key, install the SDK, and make your first call using the Interactions API — the interface Google recommends for every new project as of June 2026.
Platforms
- Gemini API (Python, JavaScript, Java, REST)
What the official documentation says
The Interactions API has been Google's default interface for the Gemini API since June 2026 and is recommended for all new projects; the original generateContent API remains fully supported but is now considered legacy.
Get started with the Gemini API (Interactions API)To use the Gemini API you need an API key to authenticate requests, enforce security limits, and track usage.
Get started with the Gemini API (Interactions API)Google AI Studio automatically creates a project and API key for new users; you can copy it from the API keys page, or click "Create API key" to add a new key-project pair.
Get started with the Gemini API (Interactions API)The key is set as an environment variable named GEMINI_API_KEY.
Get started with the Gemini API (Interactions API)Upgrading to the paid tier increases rate limits and requires setting up Cloud Billing — creating or linking a billing account, adding a payment method, and prepaying a minimum of $5 (or currency equivalent) in paid credits.
Get started with the Gemini API (Interactions API)The Interactions API is available through the Python SDK (google-genai), the JavaScript SDK (@google/genai), a Java SDK, and REST.
Get started with the Gemini API (Interactions API)A first call creates an interaction with client.interactions.create, passing a model (for example gemini-3.8-flash) and an input string; the result exposes the answer as interaction.output_text.
Get started with the Gemini API (Interactions API)The REST endpoint is https://generativelanguage.googleapis.com/v1beta/interactions, authenticated with an x-goog-api-key header.
Get started with the Gemini API (Interactions API)Responses can be streamed by passing stream=True (Python) / stream true (JavaScript); each event delivers a chunk of the response as it is generated.
Get started with the Gemini API (Interactions API)A coding agent can be given direct access to Interactions API docs and best practices by running `npx skills add google-gemini/gemini-skills --skill gemini-api-dev`.
Get started with the Gemini API (Interactions API)The REST response returns the full Interaction resource, including usage statistics and a step-by-step execution history (for example a `thought` step and a `model_output` step); the SDKs additionally expose convenience properties like interaction.output_text.
Get started with the Gemini API (Interactions API)
The Interactions API is where new Gemini projects start
Google's Gemini API has two interfaces now: the Interactions API, which has been the default since June 2026 and is where every new model, multimodal capability, tool, and agentic feature launches first, and generateContent, the original interface, which still works but is documented as legacy. If you are starting from zero, the official guidance is unambiguous — use the Interactions API.
That distinction matters for anyone following an older tutorial or an AI-generated code sample: a lot of existing sample code out there still targets generateContent. It will keep working, but you are building on the path Google has explicitly deprioritized.
Get an API key
Every request needs a key. Google AI Studio creates a project and a key for you automatically the first time you sign in — you do not have to provision anything yourself for a first test:
-
Open the API keys page in Google AI Studio and copy the key AI Studio already created for you.
-
If you need a second key, or a key tied to a different project, click Create API key and follow the dialog to pair a new key with a project.
-
Set it as an environment variable so your code never hardcodes it:
export GEMINI_API_KEY="YOUR_API_KEY"
That is enough to make free-tier calls. Nothing about this step requires a credit card.
Install the SDK and make your first call
Pick the language you're working in.
Python:
pip install -U google-genai
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash",
input="Explain how AI works in a few words"
)
print(interaction.output_text)
JavaScript:
npm install @google/genai
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: "Explain how AI works in a few words",
});
console.log(interaction.output_text);
REST, if you'd rather skip the SDK entirely:
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 REST call is the most instructive one to try once: the response is the full Interaction resource — an id, status, usage, and a steps array that can include a thought step before the model_output step. The SDKs hand you interaction.output_text as a shortcut to the final text, but the full resource is what actually comes back over the wire, and it is worth looking at once before you start relying on the shortcut.
Stream the response
For anything interactive, don't wait for the whole answer — stream it:
stream = client.interactions.create(
model="gemini-3.8-flash",
input="Explain how AI works",
stream=True
)
for event in stream:
print(event)
Each step.delta event carries one chunk of the response, so you can render text as it's generated instead of blocking on the full call.
Give your coding agent the same docs you just read
If you're building with an AI coding assistant (Claude Code, Codex, or similar), Google publishes a skill that gives the assistant direct, current access to Interactions API documentation rather than whatever it remembers from training:
npx skills add google-gemini/gemini-skills --skill gemini-api-dev
Where to go next
Once a bare text call works, the natural next steps are: Google AI Studio if you want to prototype prompts visually before writing code, the Gemini API overview for pricing and rate limits, and function calling and tools once you need Gemini to actually do something rather than just answer.
How to do it
- Open Google AI Studio and copy the automatically created API key from the API keys page, or click "Create API key" to add a new key-project pair.
- Set the key as an environment variable: `export GEMINI_API_KEY="YOUR_API_KEY"`.
- Install the SDK for your language — google-genai for Python, @google/genai for JavaScript, or use REST directly.
- Call client.interactions.create with a model such as gemini-3.8-flash and an input string.
- Read the answer from interaction.output_text, or inspect the full step-by-step execution history for more detail.
- Pass stream=True (Python) or stream true (JavaScript) instead if you want the response delivered as it is generated.
- If you outgrow the free tier's rate limits, set up Cloud Billing and prepay the $5 minimum to move to the paid tier.
On Windows
On mobile
Use cases
- Validating an API key and a model name work at all before wiring the SDK into a real application.
- Prototyping a single text-generation call in a script, then deciding whether to add streaming or tools.
- Checking whether the free tier's rate limits are enough for a side project before setting up Cloud Billing.
Common mistakes
- Building new code against generateContent by habit or old tutorials. The Interactions API is the current default for new projects; generateContent still works but is documented as legacy.
- Assuming an API key alone raises rate limits. Higher limits require actually setting up Cloud Billing and prepaying credits, not just having a key.
- Forgetting the REST call needs the x-goog-api-key header — a bare Authorization header will not authenticate the request.
- Reading only the SDK's convenience output_text property and never looking at the full step history, then being surprised later by thinking/tool steps that show up once tools are enabled.
FAQ
- Do I have to use the Interactions API, or can I keep using generateContent?
- generateContent remains fully supported, so existing integrations keep working. But it is now documented as the legacy path — Google's own guidance is that new projects should use the Interactions API.
- Is the Gemini API free to start with?
- Yes. Google AI Studio creates a project and API key automatically, and the free tier lets you make calls without Cloud Billing. Paid-tier rate limits and features require setting up billing separately.
- What does client.interactions.create actually return?
- An Interaction resource — an id, a status, usage statistics, and a chronological list of execution steps (thoughts, tool calls, and the final model output). The SDKs' output_text property is a convenience shortcut to the final text content of that resource.
- How do I get streaming output instead of waiting for the full response?
- Pass stream=True in Python or stream true in JavaScript to interactions.create. Instead of one response, you get a sequence of events, and each step.delta event carries a chunk of text you can display as it arrives.
- I have an AI coding assistant — can it learn the Interactions API on its own?
- Google publishes an installable skill for exactly this: running `npx skills add google-gemini/gemini-skills --skill gemini-api-dev` gives a coding agent direct access to current Interactions API docs and best practices.
Official sources
These are the pages this tutorial is checked against. Follow them if you need the vendor's exact wording.
- Get started with the Gemini API (Interactions API)
https://ai.google.dev/gemini-api/docs/get-started.md.txt