This guide gets you started with the Gemini API using the Interactions API. You'll make your first API call in under a minute and explore text generation, multimodal understanding, image generation, structured output, tools, function calling, agents, and background execution.
The Interactions API is available through the Python and JavaScript SDKs, as well as through REST.
1. Get an API key
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.
- Google AI Studio automatically creates a project and API key for new users. You can copy it from the API keys page.
- If you need a new key, click Create API key in AI Studio and follow the dialog to add a new key-project pair.
Set your key as an environment variable:
export GEMINI_API_KEY="YOUR_API_KEY"
Upgrade to the paid tier
Upgrading to the paid tier increases your rate limits and requires setting up Cloud Billing.
- Click Set up billing on the AI Studio API keys or Projects pages.
- Follow the Cloud Billing dialog to create or link a billing account, add a payment method, and prepay a minimum of $5 (or currency equivalent) in paid credits.
- View your API usage in Google AI Studio under Dashboard > Usage.
See the Billing page for more information.
2. Install the SDK and make your first call
Install the SDK and generate text with a single API call.
Python
Install the SDK:
pip install -U google-genai
Initialize the client and make a request:
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
Install the SDK:
npm install @google/genai
Initialize the client and make a request:
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(