Skip to content

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.

CurrentLast verified

Platforms

  • Gemini API (Python, JavaScript, Java, REST)

What the official documentation says

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:

  1. Open the API keys page in Google AI Studio and copy the key AI Studio already created for you.

  2. 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.

  3. 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

  1. 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.
  2. Set the key as an environment variable: `export GEMINI_API_KEY="YOUR_API_KEY"`.
  3. Install the SDK for your language — google-genai for Python, @google/genai for JavaScript, or use REST directly.
  4. Call client.interactions.create with a model such as gemini-3.8-flash and an input string.
  5. Read the answer from interaction.output_text, or inspect the full step-by-step execution history for more detail.
  6. Pass stream=True (Python) or stream true (JavaScript) instead if you want the response delivered as it is generated.
  7. 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

N/AThe Gemini API itself has no Windows-specific setup beyond a normal Python/Node/Java install; OS-specific tooling is covered in the Gemini CLI tutorial.

On mobile

N/AThe get-started guide covers SDK and REST usage from a development machine; it does not document a mobile workflow.

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.

Source status