
Google AI Studio API: Access, Rate Limits & SDKs 2026
The Gemini API, reached with a free AI Studio key, exposes the GA Interactions API through the google-genai SDKs and REST, plus a three-line OpenAI-compatible swap.
Google AI Studio API verdict
The Gemini API is reached with a free key from Google AI Studio.
It exposes one rich surface, the now-GA Interactions API, through the google-genai SDKs for Python and JavaScript and REST, plus an OpenAI-compatible endpoint for a three-line migration. The Interactions API covers text generation, SSE streaming, stateful multi-turn through previous_interaction_id, native multimodal understanding, and media generation across Nano Banana images, Veo video, Gemini TTS and Lyria 3 music.
Build on the Gemini API when you want one surface for text, multimodal understanding, media generation and agents behind a free AI Studio key. For the deepest control, use the native google-genai SDK and the GA Interactions API. That gives stateful previous_interaction_id for chat and agents, background=True for long jobs, built-in Google Search and code-execution tools, and managed agents in a remote sandbox. If you already run OpenAI code, migrate in three lines through the compatibility endpoint and reach chat, images, video, embeddings and batch, using extra_body for Gemini-only features like thinking_config and cached_content. Tune cost and priority with service_tier and reasoning effort. The trade-off is real. The OpenAI-compatible path is beta and lossy on unlisted params, and thinking cannot be disabled on newer models. Some features like Search grounding and batch file transfer need the native client, so reach for the SDK when the compat shim falls short.
- Two API surfaces coexist: the recommended GA Interactions API and the older generateContent API. A page toggle switches the docs, so match your code to the one you call.
- The OpenAI-compatible layer is in beta and silently ignores parameters it does not recognize, so verify behaviour rather than assume full OpenAI parity.
- Thinking is mandatory on Gemini 2.5 Pro and 3 models and cannot be turned off, and reasoning_effort and thinking_level or budget cannot be combined.
- Get a key
- Free in AI Studio
- Native
- google-genai SDK + REST
- Surface
- Interactions API (GA)
- OpenAI compat
- 3-line swap (beta)
- Base URL (compat)
- generativelanguage.../openai/
This page covers the Gemini API surface reached with an AI Studio key. The model's benchmark quality and total cost live on their own pages.
Build with the Google AI Studio API
from openai import OpenAI
client = OpenAI(
api_key="GEMINI_API_KEY",
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
)
response = client.chat.completions.create(
model="gemini-3.5-flash",
messages=[{"role": "user", "content": "Explain how AI works"}],
)
print(response.choices[0].message.content){
"choices": [{
"message": { "role": "assistant", "content": "AI learns patterns from data..." },
"finish_reason": "stop"
}],
"usage": { "total_tokens": 197 }
}- Cost levers: service_tier (Flex / Priority); Batch API (24h completion window); cached_content via extra_body.
- Handle: 401 (invalid Gemini API key), 429 (rate or quota limit (per project)).
Real Google AI Studio code from the official docs. The raw cURL hello-world is the code block above; full limits and endpoints are in the tables on this page.
Your first Google AI Studio API request
from openai import OpenAI
client = OpenAI(
api_key="GEMINI_API_KEY",
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
)
response = client.chat.completions.create(
model="gemini-3.5-flash",
messages=[{"role": "user", "content": "Explain how AI works"}],
)
print(response.choices[0].message.content)How to authenticate with the Google AI Studio API
| Aspect | Detail | Notes |
|---|---|---|
| Get a key | Free Gemini API key in AI Studio | export GEMINI_API_KEY=... |
| Native SDKs | google-genai (Python) + @google/genai (JS/TS) | Full Interactions API; SDKs read GEMINI_API_KEY |
| REST | Returns the full Interaction resource | Metadata, usage, step-by-step history |
| OpenAI compat | base_url generativelanguage.../v1beta/openai/ | 3-line change; beta |
| Auth (compat) | api_key = your Gemini API key | From Google AI Studio |
| Models | gemini-3.5-flash, 3.1 Pro/Flash, Nano Banana, Veo, Lyria 3 | Multimodal model family |
| Agent skill | npx skills add google-gemini/gemini-skills | Keep coding agents current |
Core endpoints and capabilities
| Capability | How | Purpose |
|---|---|---|
| Text generation | interactions.create (model + input) | Single-call generation; interaction.output_text convenience |
| Streaming | SSE step.delta events | Stream text chunks as they are generated |
| Multi-turn | previous_interaction_id / stateless | Server-side history + caching, or client-managed |
| Multimodal | media alongside text in one request | Native image, audio, video, document understanding |
| Generation | Nano Banana / Veo / TTS / Lyria 3 | Image, video, speech and music generation |
| Structured output | Pydantic (Python) / Zod (JS) | JSON conforming exactly to a schema |
| Tools + functions | google_search, code, function_call | Built-in tools + your own functions (requires_action) |
| Agents + background | environment="remote", background=True | Remote-sandbox agents and async long tasks |
Tiers, thinking and rules
| Aspect | Detail | Notes |
|---|---|---|
| Service tiers | service_tier: standard / flex / priority | Matches OpenAI tier name and logic |
| Thinking control | reasoning_effort -> thinking_level/budget | minimal/low/medium/high mapping |
| Thinking off | Only on 2.5 models (reasoning_effort=none) | Cannot disable on 2.5 Pro or 3 models |
| Batch API | JSONL, completion_window 24h | Create/monitor/view; upload/download via genai client |
| Compat status | OpenAI libraries support is in beta | Unlisted params silently ignored |
| Search grounding | Gemini 3+ only (via compat) | Enable with extra_body tools |
| Embeddings | gemini-embedding-001 / -2-preview | Text or multimodal embeddings |
SDKs, features and developer fit
| Aspect | Detail | Notes |
|---|---|---|
| SDKs | google-genai (Python), @google/genai (JS/TS), OpenAI libs | Plus REST |
| Gemini extras | extra_body: cached_content, thinking_config, aspect_ratio | Enable Gemini-only features in OpenAI calls |
| Thought signatures | OpenAI-compatible thought signatures (Gemini 3) | Chat completion APIs |
| Models API | List models / retrieve a model | Discover available Gemini models |
| Image params | n, size, response_format (+ extra_body aspect_ratio) | gemini-3-pro-image-preview, Nano Banana |
| Video endpoint | Sora-compatible /v1/videos (poll for result) | veo-3.1; async long-running op |
| Agent skill | gemini-skills coding-agent skill | Keep agents current with Interactions API |
Google AI Studio API FAQ
How do I authenticate with the Gemini API from AI Studio?
Create a free Gemini API key in Google AI Studio and set it as the GEMINI_API_KEY environment variable. The native google-genai SDKs for Python and JavaScript and REST read it for the GA Interactions API, and for REST you send it in an x-goog-api-key header. If you use the OpenAI libraries, pass it as api_key and point base_url at https://generativelanguage.googleapis.com/v1beta/openai/.
What is the Interactions API?
It is the now-GA Gemini API surface Google recommends for the latest features and models, available through the Python and JavaScript SDKs and REST. One surface covers text generation, SSE streaming, stateful multi-turn through previous_interaction_id, and native multimodal understanding. It also handles image, video, speech and music generation, structured output, built-in tools, function calling, managed agents with environment='remote', and background execution with background=True.
Is the Gemini API OpenAI-compatible?
Yes, in beta. Reach Gemini models from the OpenAI Python and TypeScript libraries by changing three lines: api_key to your Gemini key, base_url to https://generativelanguage.googleapis.com/v1beta/openai/, and model to a Gemini model. It covers chat, image and video generation through a Sora-compatible /v1/videos endpoint, embeddings and the Batch API. It maps reasoning_effort to Gemini thinking levels and matches service_tier. Unlisted parameters are silently ignored, and some features need the native client.
How do I control thinking and cost on the Gemini API?
Through reasoning effort and service tiers. The compatibility layer maps OpenAI's reasoning_effort, from minimal to high, to Gemini thinking levels or budgets. But reasoning_effort and thinking_level or budget cannot be combined, and thinking cannot be turned off on Gemini 2.5 Pro or 3 models. For cost and latency, the service_tier parameter matches OpenAI's standard, Flex and Priority logic, and the Batch API runs jobs within a 24-hour completion window.
What can the API generate besides text?
Plenty, on the same key. It generates images with the Nano Banana models and video with Veo through the Sora-compatible /v1/videos endpoint, which you poll for the result. It also produces expressive multi-speaker speech with Gemini 3.1 Flash TTS, and music with Lyria 3. It also produces text and multimodal embeddings through gemini-embedding-001 and gemini-embedding-2-preview. Image and video generation accept rich parameters like aspect_ratio, resolution and reference_images through extra_body.
Sources & verification
| Source | What was checked | Last checked |
|---|---|---|
| Google Official | Official product page | July 10, 2026 |
| Google AI | Aistudio | July 10, 2026 |
| Google AI | Gemini API Get Started | July 10, 2026 |
| Google AI | Gemini API Openai | July 10, 2026 |
Every fact on this Google AI Studio page is tied to a named source and a verification date. Freshness-sensitive figures trace to the sources above; verify against the vendor before relying on them.
Explore Google AI Studio
Every page on Google AI Studio in one place, you are on api.
