# Gemini API quickstart

> [!NOTE]
> **Note** : This version of the page covers the new [Interactions API](https://ai.google.dev/gemini-api/docs/interactions), which is currently in Beta.  
> For stable production deployments, we recommend you continue to use the `generateContent` API. You can use the toggle on this page to switch between the versions.

This quickstart shows you how to install our [libraries](https://ai.google.dev/gemini-api/docs/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:

[Create a Gemini API Key](https://aistudio.google.com/app/apikey)

## Install the Google GenAI SDK

### Python

Using [Python 3.9+](https://www.python.org/downloads/), install the
[`google-genai` package](https://pypi.org/project/google-genai/)
using the following
[pip command](https://packaging.python.org/en/latest/tutorials/installing-packages/):

    pip install -q -U google-genai

### JavaScript

Using [Node.js v18+](https://nodejs.org/en/download/package-manager),
install the
[Google Gen AI SDK for TypeScript and JavaScript](https://www.npmjs.com/package/@google/genai)
using the following
[npm command](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm):

    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](https://ai.google.dev/api/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.
- [`generateContent`](https://ai.google.dev/api/generate-content#method:-models.generatecontent) provides a way to generate a simple, stateless response from a model. While we recommend using Interactions API, `generateContent` is 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](https://ai.google.dev/gemini-api/docs/interactions/api-key#set-api-env-var) as the
environment variable `GEMINI_API_KEY`, it will be picked up automatically by the
client when using the [Gemini API libraries](https://ai.google.dev/gemini-api/docs/libraries).
Otherwise you will need to [pass your API key](https://ai.google.dev/gemini-api/docs/interactions/api-key#provide-api-key-explicitly) 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](https://ai.google.dev/gemini-api/docs/interactions/text-generation#stateless-conversations).

## What's next

Now that you made your first API request, you might want to explore the
following guides that show Gemini in action:

- [Text generation](https://ai.google.dev/gemini-api/docs/interactions/text-generation)
- [Image generation](https://ai.google.dev/gemini-api/docs/interactions/image-generation)
- [Image understanding](https://ai.google.dev/gemini-api/docs/interactions/image-understanding)
- [Thinking](https://ai.google.dev/gemini-api/docs/interactions/thinking)
- [Function calling](https://ai.google.dev/gemini-api/docs/interactions/function-calling)
- [Long context](https://ai.google.dev/gemini-api/docs/long-context)
- [Embeddings](https://ai.google.dev/gemini-api/docs/embeddings)