Gemini API quickstart
This quickstart shows you how to install our libraries and make your first Gemini API request using the Interactions API.
Before you begin
To use the Gemini API, you need to have an API key to authenticate your requests, enforce security limits, and track usage to your account.
Create one on AI Studio for free to get started:
Install the Google GenAI SDK
Python
Using Python 3.9+, install the
google-genai package
using the following
pip command:
pip install -q -U google-genai
JavaScript
Using Node.js v18+, install the Google Gen AI SDK for TypeScript and JavaScript using the following npm command:
npm install @google/genai
Make your first request
There are two ways you can use to send a request to the Gemini API:
- (Recommended) Interactions API is a new primitive with native support for multi-step tool use, orchestration, and complex reasoning flows through typed execution steps. Going forward, new models beyond the core mainline family, along with new agentic capabilities and tools, will launch exclusively on the Interactions API.
generateContentprovides a way to generate a simple, stateless response from a model. While we recommend using Interactions API,generateContentis fully supported.
This example uses the Interactions API to send a request to the Gemini API using the Gemini 3 Flash model.
If you set your API key as the
environment variable GEMINI_API_KEY, it will be picked up automatically by the
client when using the Gemini API libraries.
Otherwise you will need to pass your API key as
an argument when initializing the client.
Note that all code samples in the Gemini API docs assume that you have set the
environment variable GEMINI_API_KEY.
Python
# This will only work for SDK newer than 2.0.0
from google import genai
# The client gets the API key from the environment variable `GEMINI_API_KEY`.
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Explain how AI works in a few words"
)
# Print the model's text response
for step in interaction.steps:
if step.type == "model_output":
for content_block in step.content:
if content_block.type == "text":
print(content_block.text)
JavaScript
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
// The client gets the API key from the environment variable `GEMINI_API_KEY`.
const ai = new GoogleGenAI({});
async function main() {
const interaction = await ai.interactions.create({
model: "gemini-3-flash-preview",
input: "Explain how AI works in a few words",
});
const modelStep = interaction.steps.find(s => s.type === 'model_output');
if (modelStep) {
for (const contentBlock of modelStep.content) {
if (contentBlock.type === 'text') console.log(contentBlock.text);
}
}
}
main();
REST
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-H "Api-Revision: 2026-05-20" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Explain how AI works in a few words"
}'
Stateless mode
By default, the Interactions API manages conversation state server-side when you use previous_interaction_id. If you prefer to manage the conversation history yourself on the client side, you can opt into stateless mode by setting store=false and passing the accumulated steps in the input field of subsequent requests.
For details and full multi-turn stateless examples, see the Text generation guide.
What's next
Now that you made your first API request, you might want to explore the following guides that show Gemini in action: