Call Gemini with the Google GenAI SDK (Interactions API)
Install google-genai or @google/genai, set GEMINI_API_KEY and call gemini-3.8-flash through the Interactions API, including a stateful multi-turn follow-up, per Google's official Getting started page.
Verification
- Test environment
- Unknown
- Tested on
- Unknown
- Last updated
- 2026-11-11
Related models: Gemini 4 Argon, Gemini 3.8 Flash
This guide follows Google's official Getting started page for the Gemini API. Google's getting-started flow now uses the Interactions API, available through the Python and JavaScript GenAI SDKs and REST. The code is copied from that page; we have not run it ourselves.
1. Get an API key
Google AI Studio creates a project and API key for new users; copy it from the API keys page, or click Create API key. Then set it as an environment variable:
export GEMINI_API_KEY="YOUR_API_KEY"
The free tier works for testing. The paid tier raises rate limits and needs Cloud Billing; Google's page says you prepay a minimum of $5 (or the currency equivalent) in credits.
2. 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)
3. 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);
genai.Client() and new GoogleGenAI({}) take no key argument here; they read GEMINI_API_KEY from the environment.
4. Multi-turn conversations
The Interactions API can keep the conversation on the server. Pass the previous interaction's id as previous_interaction_id; Google recommends this stateful approach for most chat and agent workflows:
from google import genai
client = genai.Client()
# Server-side state (recommended)
interaction1 = client.interactions.create(
model="gemini-3.8-flash",
input="I have 2 dogs in my house.",
)
print("Response 1:", interaction1.output_text)
interaction2 = client.interactions.create(
model="gemini-3.8-flash",
input="How many paws are in my house?",
previous_interaction_id=interaction1.id,
)
print("Response 2:", interaction2.output_text)
The stateless alternative is to send every previous turn yourself, including the model's intermediate thought and tool steps.
5. What comes back
Over REST the API returns the full Interaction resource: an id, status, usage totals and a list of steps (for example a thought step and a model_output step). The SDKs add shortcuts like output_text and output_image.
6. Models on this site
- Gemini 3.8 Flash:
gemini-3.8-flash, used in the quickstart - Gemini 4 Argon:
gemini-4-argon
Swap the model string to try another one, and check the Pricing page to compare costs.
Sources
- Getting started - Gemini API (Google AI Studio docs)aistudio
.google .com (opens in a new tab) · checked 2026-11-11