The
Gemini API lets developers add
Google’s generative models to applications. It can generate text and images, analyze documents and media, return structured data, call functions, use tools, stream audio and support agents. Google AI Studio provides a browser environment for testing those capabilities and creating an API project.
The shortest path is:
- test a task in Google AI Studio;
- obtain an API key;
- call the Interactions API with an exact model ID;
- evaluate the output on real examples;
- add billing, monitoring, security and failure handling before production.
This page owns developer intent. Consumer features and subscriptions belong in the
complete Google Gemini guide and
Gemini pricing comparison.
The API was checked on July 24, 2026. Model IDs, previews, prices and SDK behavior can change. Verify current documentation before shipping.
What is the Gemini API?
The Gemini Developer API is Google’s direct interface for using Gemini, Nano Banana, Veo and related models in software. A request supplies input and configuration; the service returns generated output or tool interactions.
Current capabilities include:
- text generation;
- multimodal understanding;
- long-context analysis;
- structured JSON outputs;
- function calling;
- search and maps grounding;
- code execution;
- file inputs;
- image generation and editing;
- video and audio models;
- embeddings;
- realtime and streaming experiences;
- stateful interactions;
- background execution, webhooks and batch work;
- compatibility options for existing OpenAI-style applications.
An API call is not the same as using the Gemini app. The developer is responsible for the interface, retrieval, permissions, state, evaluation and user experience around the model.
What is Google AI Studio?
Google AI Studio is a web development environment for exploring models, prompts and Gemini API capabilities.
Use it to:
- compare models;
- prototype instructions;
- test multimodal inputs;
- inspect token use;
- experiment with structured outputs and tools;
- generate starter code;
- manage API keys and projects;
- view usage and billing;
- prototype agents and full-stack applications.
AI Studio reduces the time from idea to first response. It does not automatically make a prototype production-ready.
The browser environment may contain sensitive prompts, files and credentials. Data terms depend on whether the project is using free or paid services. Review that distinction before adding non-public material.
Gemini API versus AI Studio
| Google AI Studio | Gemini API |
| Browser interface | Programmatic interface |
| Fast experimentation | Application integration |
| Manual prompt testing | Automated requests |
| Starter code and project controls | Runtime behavior in your product |
| Useful for evaluation setup | Requires engineering, monitoring and security |
They are two parts of the same developer path, not competing products.
Gemini API versus Gemini Enterprise Agent Platform
The Developer API is the simpler route for direct access and rapid product development. Gemini Enterprise Agent Platform, formerly Vertex AI, is the Google Cloud route for larger organizations that need broader governance, regional controls, managed agents, Model Garden, enterprise identity and integration with cloud infrastructure.
Choose the Developer API when:
- a small team needs a quick start;
- the direct model endpoint is sufficient;
- AI Studio is the preferred control surface;
- the data and contract fit the service terms.
Choose the enterprise platform when:
- centralized cloud governance is required;
- models from several providers are needed;
- production agents need managed runtime and evaluation;
- organization, folder and project policies matter;
- regional, networking or procurement requirements apply.
Read the
Gemini Enterprise guide for the platform decision.
The Interactions API
Google recommends the Interactions API for current Gemini models and agent features. It supports stateful interactions, tool use and modern Gemini capabilities under one interface.
The basic Python example is:
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.6-flash",
input="Explain retrieval-augmented generation in three sentences."
)
print(interaction.output_text)
The SDK reads the API key from the configured environment. Do not hard-code a production credential into source control.
JavaScript:
import { GoogleGenAI } from"@google/genai";
const ai = newGoogleGenAI({});
const interaction = await ai.interactions.create({
model: "gemini-3.6-flash",
input: "Explain retrieval-augmented generation in three sentences.",
});
console.log(interaction.output_text);
REST:
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.6-flash",
"input": "Explain retrieval-augmented generation in three sentences."
}'
Use these as minimal connectivity tests. Production requests need timeouts, retries, validation, observability and cost controls.
Create a Gemini API key
- Open Google AI Studio.
- Create or select a project.
- Generate an API key for that project.
- Store it in a secret manager or environment variable.
- Restrict where and how it can be used when supported.
- Never place it in frontend code that exposes the key to users.
- Rotate the key if it appears in logs, screenshots or a repository.
Treat the API key as a billing and access credential. A key leaked into a public repository can create unauthorized usage and cost.
Which model should a developer choose?
Start from the workload:
| Need | Starting model or family |
| Strong general and agentic performance | Gemini 3.6 Flash |
| Difficult multimodal reasoning | Gemini 3.1 Pro |
| High-volume, low-latency processing | Gemini 3.5 Flash-Lite |
| Image generation or editing | Nano Banana family |
| Conversational video output | Gemini Omni when API access is available |
| Dedicated video generation | Veo |
| Speech or realtime translation | Gemini Audio/Live models |
| Embeddings and semantic retrieval | Gemini embedding model |
The
Gemini models guide explains the families in detail.
Do not select the largest model by default. Evaluate accepted-result rate, latency and total cost.
Thinking levels
Gemini 3 models can use configurable thinking levels. Supported values vary by model and can include minimal, low, medium and high.
Example:
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.1-pro-preview",
input="Compare two database migration strategies for a zero-downtime service.",
generation_config={"thinking_level": "high"},
)
print(interaction.output_text)
Use lower thinking for simple, latency-sensitive requests and higher thinking for genuinely difficult analysis. The setting is a relative reasoning control, not a guaranteed hidden-token budget.
Google advises retaining the default temperature of 1.0 for Gemini 3 models. Older habits of lowering temperature for every factual task can cause degraded or looping behavior in the current generation.
Stateful and stateless interactions
Stateful mode allows the service to maintain interaction continuity through an earlier interaction identifier. Stateless mode requires the developer to manage history and relevant thought signatures.
Stateful mode can simplify agent and conversation design. It also creates retention and state-management questions:
- How long should an interaction persist?
- Which user owns it?
- Can one tenant access another tenant’s state?
- How is deletion handled?
- What happens after a model migration?
Do not let convenience replace application-level authorization.
Multimodal inputs
Gemini can reason over combinations of:
- text;
- images;
- PDFs and documents;
- audio;
- video;
- code;
- structured data.
Large multimodal contexts can be powerful and expensive. Pre-process and select material deliberately:
- remove irrelevant pages;
- normalize formats;
- use metadata;
- split very long media when exact time references matter;
- keep the original file identifier;
- record which inputs produced the output.
For consequential extraction, require locations and compare them with the source.
Structured outputs
Structured outputs constrain Gemini to a schema such as JSON. They are essential when model output feeds another system.
Validate even schema-conforming output:
- required fields may be semantically wrong;
- numerical units may be inconsistent;
- an enum can be valid and unsupported by evidence;
- strings can contain instructions or unsafe content;
- nested objects can exceed business limits.
Use application-side schema validation and domain rules. Never trust generated JSON solely because it parses.
Function calling and tools
Function calling lets Gemini request an operation defined by the application. The application decides whether to execute it and returns the result.
A secure pattern is:
- model proposes a tool and arguments;
- application validates authorization and schema;
- high-impact actions require confirmation;
- tool executes with least privilege;
- result returns to the model;
- logs record the decision and outcome.
The model should not hold unrestricted credentials. Separate read, write, send, buy and delete permissions.
Grounding with Google Search and Maps
Grounding lets an application use current information from Google services. It can improve recency and provide source attribution.
Grounding has separate pricing and quota rules. Google currently includes a monthly allowance across eligible Gemini 3 models before charging per search query.
One user request can trigger more than one underlying search. Estimate costs from actual traces rather than multiplying user prompts by a headline rate.
Grounding also requires citation evaluation. A returned source can be irrelevant, low quality or incorrectly applied.
Long context, files and caching
Large context makes it possible to process substantial repositories, documents and media. Context caching can reduce repeated input cost for stable material.
Use caching when:
- a large prefix is reused;
- the source remains unchanged;
- the storage cost is lower than repeated input;
- the retention and access model are acceptable.
Do not cache confidential data without understanding who can address the cache and how it expires.
Retrieval can still be better than sending everything. A smaller evidence set reduces cost, distraction and prompt-injection surface.
Batch, background work and webhooks
Batch processing is useful for large non-interactive workloads. Background execution and webhooks support longer tasks without keeping a client connection open.
Design for:
- idempotency;
- job status;
- partial failure;
- duplicate callbacks;
- retry limits;
- cost ceilings;
- cancellation;
- output validation;
- retention and cleanup.
An agent or batch job can continue consuming resources after the user closes a browser. Billing controls must live on the server.
Gemini API pricing
The API uses model- and feature-specific pricing. Costs can include:
- input tokens;
- output and reasoning tokens;
- cached input and cache storage;
- images, audio or video;
- grounding queries;
- batch, priority or flexible inference;
- agent and tool services.
Examples change by model. Google published these launch rates:
| Model | Input per 1M tokens | Output per 1M tokens |
| Gemini 3.6 Flash | $1.50 | $7.50 |
| Gemini 3.5 Flash-Lite | $0.30 | $2.50 |
Do not use those two figures as a universal API price. Check the
live pricing page for the selected ID.
Estimate cost per completed task
Use:
input cost
+ output/reasoning cost
+ grounding and tool charges
+ storage/caching
+ retries and failed workflow steps
+ human review
= cost per accepted result
Token price alone can make an inaccurate cheap model appear economical.
Free tier versus paid tier data use
Google’s pricing table indicates that data sent through the free tier for eligible models can be used to improve its products, while paid-tier data is not used for that purpose under the applicable terms.
This is a critical boundary.
Use the free tier for public, synthetic or approved test material. Enable paid services and review the terms before using confidential data. Google AI Studio prompts can fall under paid-service terms when the account has an eligible paid API project, but the project status must be checked.
Enterprise requirements may still justify the Google Cloud platform rather than the direct developer service.
Billing in 2026
Google introduced Prepay and Postpay billing structures for the Gemini API in 2026.
Under Prepay:
- credits are purchased in advance;
- the minimum purchase is currently $10;
- unused credits expire after 12 months;
- a depleted balance can stop keys associated with the billing account;
- auto-reload can reduce interruption;
- billing pipeline delay can allow limited overage.
Assigned billing mode and eligibility can differ by account. Monitor the AI Studio billing page rather than assuming every project uses the same system.
Consumer Google AI subscriptions are unrelated to this balance.
Rate limits
Rate limits apply at the project level rather than individually to each key. They can include:
- requests per minute;
- tokens per minute;
- requests or tokens per day;
- image-specific limits;
- spend-based limits;
- batch queues;
- separate preview restrictions.
Quota can depend on model, tier, billing history and account standing. Published limits are not guaranteed capacity.
Handle 429 RESOURCE_EXHAUSTED with bounded exponential backoff, jitter and workload control. Blind immediate retries can amplify the problem.
Production checklist
Before launch:
- pin an appropriate model ID;
- maintain a model migration test;
- store secrets securely;
- enforce tenant isolation;
- set request and output limits;
- validate structured output;
- sanitize tool arguments;
- require approval for external changes;
- defend retrieval against prompt injection;
- add timeouts and bounded retries;
- monitor latency, errors and spend;
- log enough for investigation without logging secrets;
- evaluate safety and refusal behavior;
- create a user disclosure and correction path;
- define retention and deletion;
- test fallback behavior.
The model call is usually the easiest part of the system.
Common mistakes
Shipping a prompt that worked once
Create a representative evaluation set and rerun it after changes.
Using a preview alias without a migration plan
Preview models can change. Pin, monitor and test.
Putting the API key in a mobile or browser bundle
Route sensitive calls through a controlled backend.
Trusting structured output semantically
Schema validity does not prove truth.
Giving the model direct write access
Validate and authorize every action in application code.
Ignoring free-tier data terms
Prototype with non-sensitive data or move to the appropriate paid service.
Measuring tokens but not corrections
Human repair can dominate total cost.
Frequently asked questions
Is the Gemini API free?
Eligible models have a free tier with quotas. Paid use follows model-specific pricing. Free-tier data terms differ from paid-tier terms.
Does Google AI Pro include API credits?
No. Consumer subscriptions and API billing are separate.
Is Google AI Studio the same as the Gemini API?
No. AI Studio is Google’s browser environment for experimenting with Gemini models, prompts, tools, agents, projects, keys, usage and billing. The API is the programmatic interface used by software.
Which Gemini API should I use?
Google currently recommends the Interactions API for access to the newest Gemini features and agents.
Which model should I start with?
Gemini 3.6 Flash is a strong general starting point. Test 3.1 Pro for difficult reasoning and Flash-Lite for high-volume bounded tasks.
Can Gemini return JSON?
Yes. Use structured outputs and validate the result in application code.
Can Gemini call my functions?
Yes. The model can propose a tool call, but the application should validate permission and arguments before execution.
Can the Gemini API search the web?
Eligible models support grounding with Google Search. Pricing and query limits apply.
Is AI Studio safe for confidential data?
It depends on the project’s paid status and applicable terms. Use non-sensitive material until the data boundary is confirmed.
When should I use the enterprise platform?
Use it when cloud governance, managed agents, organization policies, regional controls, broad model choice or enterprise procurement are required.
Bottom line
Google AI Studio gets a developer to the first useful prototype. The Gemini API turns that prototype into an application. Production quality comes from everything built around the call: evaluation, authorization, observability, cost control and failure recovery.
Start with Gemini 3.6 Flash, a small test set and public data. Move to another model only when the evaluation demonstrates a need. Move to paid or enterprise services before the data and organizational requirements exceed the free developer environment.