
Google Gemini API: Access, Rate Limits & SDKs 2026
The Gemini API uses a single free API key in an x-goog-api-key header, with Python, JavaScript and REST. The Interactions API is the GA surface to build on.
Google Gemini API verdict
The Google Gemini API authenticates with a single free API key, passed in an x-goog-api-key header, and is reachable from Python, JavaScript and REST.
The primary surface is the now-GA Interactions API, with the older generateContent surface still available. It covers text generation and native multimodal input across image, audio, video and documents.
Gemini's API is the easiest of the big three to start: one free API key, an x-goog-api-key header, and SDKs for Python and JavaScript plus REST. The Interactions API is the surface to build on, with stateful multi-turn through previous_interaction_id, built-in Google Search grounding, managed agents and background execution. Server-side state and tool orchestration come for free. Budget around RPM, TPM and RPD per project. Limits rise automatically with cumulative Google Cloud spend, from Free to Tier 3, but preview models are throttled harder, and priority and batch traffic have separate limits. Use the Batch API and the 90% cache discount for volume, and shrink context or outputs to absorb 429s.
- Rate limits are hit across whichever of RPM, TPM and RPD comes first. 21 requests in a minute trip a 20-RPM limit even with tokens to spare.
- Preview and experimental models, including Gemini 3.1 Pro Preview, carry stricter rate limits than stable releases.
- Spend-based limits return a 429 RESOURCE_EXHAUSTED independent of RPM and TPM, gated by billing history and tier.
- Priority inference runs at 0.3x the standard rate limit per model and tier, and the Batch API has its own separate limits.
- Auth
- x-goog-api-key (free key)
- Primary surface
- Interactions API (GA)
- SDKs
- Python, JS, REST
- Usage tiers
- Free to Tier 3
- Cache discount
- 90% ($0.20/1M)
Build with the Google Gemini API
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.1-pro",
contents="Hello, Gemini",
)
print(response.text){
"candidates": [{
"content": { "parts": [{ "text": "Hello! How can I help?" }] },
"finishReason": "STOP"
}],
"usageMetadata": { "promptTokenCount": 4, "candidatesTokenCount": 8 }
}- Cost levers: Batch API (separate limits); prompt caching (cache hit $0.20/1M, 90% off); smaller context / shorter outputs.
- Handle: 429 (RESOURCE_EXHAUSTED (rate or spend limit)).
Real Google Gemini 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 Gemini API request
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-pro:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{ "parts": [{ "text": "Hello, Gemini" }] }]
}'How to authenticate with the Google Gemini API
| Aspect | Detail | Notes |
|---|---|---|
| Get a key | Free API key from Google AI Studio | export GEMINI_API_KEY=... |
| Auth | x-goog-api-key header with the API key | Set as an environment variable |
| Primary surface | Interactions API (generally available) | Recommended for newest features and models |
| Legacy surface | generateContent API still available | Toggle between API versions in docs |
| Access methods | Python SDK, JavaScript SDK, REST | Same Interactions API across all three |
| Scope | Rate limits and quotas per project | Not per API key |
| Response shape | Interaction resource: id, status, usage, steps[] | object: interaction |
Google Gemini core endpoints
| Capability | How | Purpose |
|---|---|---|
| Generate | :generateContent / interactions | Text generation from text or multimodal input |
| Streaming | Server-sent events (SSE) | step.delta events stream text as generated |
| Multi-turn | previous_interaction_id (stateful) or client history | Server-managed or client-managed conversation |
| Multimodal in | image / audio / video / documents | Native understanding of media alongside text |
| Structured output | Pydantic (Python) / Zod (JavaScript) | JSON conforming to a schema you define |
| Built-in tools | Google Search, code execution, URL context, Maps, computer use | Grounding and actions with automatic citations |
| Managed agents | environment="remote" | Agents in a remote sandbox with code execution + file management |
| Background | background=True, poll interactions.get() | Long tasks run asynchronously |
Google Gemini rate limits and tiers
| Limit | Detail | Notes |
|---|---|---|
| Dimensions | RPM, TPM (input), RPD | Hit on whichever comes first |
| Scope / reset | Per project; RPD resets midnight Pacific | Not per API key |
| Usage tiers | Free, Tier 1-3; auto-upgraded by spend | Tier 1 link billing, Tier 3 $1,000 paid |
| Spend-based limits | 429 RESOURCE_EXHAUSTED on spend cap | Caps by billing history / tier |
| Preview models | Stricter limits for preview/experimental | Gemini 3.1 Pro Preview is one |
| Priority inference | 0.3x the standard limit per model and tier | Counts toward overall interactive limits |
| Batch API | 100 concurrent, 2GB input file, 20GB storage | Separate from non-batch limits |
| Tier promotion | Free to Tier 1 instant; later within 10 min | Set up billing first in AI Studio |
Google Gemini SDKs, error handling and developer fit
| Aspect | Detail | Notes |
|---|---|---|
| Official SDKs | Python, JavaScript, REST | Same Interactions API surface |
| Convenience accessors | interaction.output_text, interaction.output_image | Skip parsing the steps array |
| Function calling | status requires_action + function_call step | Run locally, submit result for turn 2 |
| Generation outputs | Text + image (Nano Banana), speech (TTS), music (Lyria 3) | Multimodal generation |
| Rate-limit errors | 429 RESOURCE_EXHAUSTED; wait, retry, shrink requests | Smaller context windows or shorter outputs |
| Cost levers | Batch API (separate limits); 90% cache discount; concise outputs | Batch off the synchronous limits |
| API pricing (Gemini 3.1 Pro) | $2/1M in, $12/1M out, cache hit $0.20/1M | Independent cross-reference |
Google Gemini API FAQ
How do I authenticate with the Gemini API?
Create a free API key in Google AI Studio, set it as the GEMINI_API_KEY environment variable, and send it in an x-goog-api-key header. The SDKs read the env var automatically. Rate limits and quotas apply per project, not per API key, so multiple keys in one project share the same limits.
What can the Gemini API do beyond text generation?
The Interactions API, now GA, covers native multimodal understanding across image, audio, video and documents. It generates images through Nano Banana, speech through TTS and music through Lyria 3. Structured output uses Pydantic or Zod, and built-in tools include Google Search grounding, code execution, URL context, Google Maps and computer use. It also supports function calling, managed agents in a remote sandbox, and background execution for long tasks.
What are the Gemini API rate limits?
Limits apply per project across requests per minute, input tokens per minute and requests per day, enforced on whichever is reached first, and RPD resets at midnight Pacific. Usage tiers raise the ceiling automatically by cumulative Google Cloud spend, from Free through Tier 3. Preview models carry stricter limits, priority inference runs at 0.3x the standard limit, and the Batch API has its own limits, at 100 concurrent and a 2GB input file.
Which SDKs does the Gemini API offer?
Official Python and JavaScript SDKs, plus a REST interface, all on the same Interactions API. The SDKs expose the full Interaction response and convenience accessors like interaction.output_text and interaction.output_image, so you do not have to parse the steps array. Multi-turn conversations can be stateful, server-managed through previous_interaction_id, or stateless, with client-managed history.
How do I handle Gemini API rate-limit errors and control cost?
A 429 RESOURCE_EXHAUSTED means a request or spend limit was hit. Wait and retry, or reduce expensive requests by using smaller context windows or shorter outputs. For volume, use the Batch API, which is separate from synchronous limits, and rely on the 90% cache-hit discount, where cached input runs at $0.20 per 1M on Gemini 3.1 Pro. Tier upgrades that raise limits happen automatically as cumulative spend grows.
Sources & verification
| Source | What was checked | Last checked |
|---|---|---|
| Google Official | Official product page | July 10, 2026 |
| Artificial Analysis | Independent reference | July 10, 2026 |
| Google AI | Gemini API Get Started | July 10, 2026 |
| Google AI | Gemini API Rate Limits | July 10, 2026 |
Every fact on this Google Gemini 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 Gemini
Every page on Google Gemini in one place, you are on api.
