Get API Key

What "Gemma 4 API" means today: Gemma 4 is an open-weight family from Google DeepMind, but Google also provides hosted access to Gemma through the Gemini API. That matters because many developers want the strengths of Gemma 4 without standing up their own runtime, scaling layer, and API wrapper. So the Gemma 4 API story is twofold: call hosted Gemma models with an API key for the fastest path to building, or download the open weights and self-host for full control. This guide covers both - starting with the newest changes to API keys and pricing.

๐Ÿ†• Latest (2026): API keys are moving to "auth keys"

All new Gemini API keys created in Google AI Studio are now auth keys by default. Google is retiring older "standard" keys: from June 19, 2026 the API rejects unrestricted standard keys, and by September 2026 standard keys stop working entirely - create a new key or migrate before then. Good news on cost: Gemma 4 models run on the API at $0 per token (see Pricing below).

Watch: Gemma 4 & Getting an API Key

Official overview - "What's new in Gemma 4" (Google)
Community walkthrough - creating a Gemini API key in AI Studio

What Is the Gemma 4 API?

The most accurate way to describe the Gemma 4 API right now is this: Gemma 4 can be accessed as hosted models through the Gemini API. Google's official "Run Gemma with the Gemini API" guidance positions the Gemini API as a convenient alternative to setting up your own local instance and web service. That framing tells developers exactly where Gemma 4 fits in the stack. You can still self-host Gemma weights if you want that level of control, but if you want the fastest path to building, the Gemini API is the supported hosted route.

For teams building chat tools, document workflows, coding assistants, internal copilots, image-aware tools, or structured automation, hosted access changes the equation. Instead of worrying first about GPU memory, inference servers, and traffic bursts, you can focus on prompts, UX, output schemas, and product logic. That is why "Gemma 4 API" captures a real developer need: how to use Gemma 4 as a programmable service rather than only as raw weights.

๐Ÿ’ก Practical summary

If you want the easiest path to trying Gemma 4 in an app or prototype, use the Gemini API route with an API key. If you want maximum control, download the open weights and self-host instead (see the Download section).

Which Gemma 4 Models Are Available Through the API?

Google's Gemma documentation lists the Gemma 4 family as E2B, E4B, the unified 12B, 26B A4B, and 31B, launched on April 2, 2026 (the unified 12B followed on June 3, 2026). Through the Gemini API you reach the instruction-tuned variants - such as gemma-4-31b-it, gemma-4-26b-a4b-it, and gemma-4-12b-it - on AI Studio and via the API. These are the model IDs to use in hosted examples.

API-relevant model info Current signal Why it matters
Gemma 4 family E2B, E4B, 12B, 26B A4B, and 31B - launched April 2, 2026 (12B added June 3) Establishes the current baseline for developers evaluating capability and size options.
Hosted model IDs (instruction-tuned) gemma-4-31b-it, gemma-4-26b-a4b-it, gemma-4-12b-it These are the key model IDs to use in hosted API examples and calls.
Instruction-tuned access Hosted examples use instruction-tuned names ending in -it Common hosted flows (chat, coding, function calling) center on instruction-tuned variants.

In plain English, the hosted API story is strongest for instruction-tuned Gemma 4 models. If you are building a public-facing tool, chatbot, or assistant, that is what you want anyway - instruction-tuned models are the natural fit for conversational prompts, coding helpers, rewriting tasks, and function-calling workflows. Exact edge model IDs (E2B/E4B) and availability can vary, so confirm the current list in the official model and API docs.

Gemma 4 API Pricing

Here's the headline: as open models, Gemma 4 is available through the Gemini API at $0 per token. What you actually manage is rate limits and infrastructure, not per-token cost. Google AI Studio itself is always free, and you can self-host the open weights for free too - paying only for your own compute.

Access optionCostBest for
Google AI Studio (web)FreePrompting & testing Gemma 4 in the browser
Gemini API - free tier$0 / token ยท rate-limited (requests per minute & per day)Prototyping & low-volume apps
Gemini API - paid tierHigher rate limits ยท Gemma stays $0 / tokenProduction throughput; your data isn't used for training
Self-host (HF / Ollama / vLLM)Free weights - you pay only for computeFull control, privacy, offline use
๐Ÿ’ก Notes on cost

Free-tier requests may be used by Google to improve their products; the paid tier does not train on your content. Batch mode is roughly 50% cheaper for async jobs, and context caching can sharply cut repeated-prompt input costs. Rate limits and pricing change frequently - always confirm the current numbers on Google's official pricing and rate-limit pages before you build.

Why Use the Gemma 4 API Instead of Self-Hosting?

Self-hosting has real benefits: deeper control, stronger privacy boundaries, and the freedom to pick your own runtime stack. But hosted access through the Gemini API removes a large amount of operational work. You do not need to provision GPUs, manage model loading, handle scaling and cold starts, or expose your own gateway just to test an idea. For many product teams - especially early-stage ones - that difference is huge. It lets you validate the user experience before committing to infrastructure.

Hosted access is also useful for teams that want to compare Gemma 4 prompts quickly in Google AI Studio and then move them into production-like code. AI Studio is the place to explore models; the Gemini API is the place to integrate them into apps. That workflow fits Gemma 4 well: prototype fast, refine prompts, and call the model programmatically once the product direction becomes clear.

How to Get a Gemma 4 API Key

To use Gemma through the Gemini API, you need a Gemini API key, created and managed in Google AI Studio. Once you have a key, set it as an environment variable or pass it in requests. The onboarding flow is integrated with AI Studio rather than a separate "Gemma-only" console, so it's the same tooling as the rest of Google's Gemini ecosystem - which lowers the barrier for teams already using it.

1
Open Google AI Studio & accept the terms

Go to aistudio.google.com/app/apikey, sign in, and accept the Generative AI terms. Google creates a Cloud project for you automatically - no prior Cloud setup needed.

2
Create an API key

Click Get API key โ†’ Create API key (new project is simplest). New keys are auth keys by default and start with AIzaโ€ฆ. Copy it and store it safely.

3
Pick a hosted Gemma model & call it

Use a model ID such as gemma-4-31b-it, gemma-4-26b-a4b-it, or gemma-4-12b-it and send a generateContent request (see the REST example below).

๐Ÿ” New: auth keys & key security (2026)

Restrict every key to the Generative Language API, never commit keys to Git, and never ship them in client-side code - run a backend proxy instead. Read keys from an environment variable; the official SDKs auto-detect GEMINI_API_KEY (and GOOGLE_API_KEY). The current standard is the x-goog-api-key header on the v1beta endpoint, though the older ?key= URL parameter still works for now. Unrestricted standard keys are rejected after June 19, 2026, and all standard keys by September 2026, so migrate to an auth key. Dormant unrestricted keys may already show a "Blocked" tag.

Basic REST Example

The core hosted invocation is a generateContent POST request: choose the model, pass your content parts, and authenticate with your API key via the x-goog-api-key header.

# set your key once:  export GEMINI_API_KEY="AIza..."
curl "https://generativelanguage.googleapis.com/v1beta/models/gemma-4-31b-it:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [
        {"text": "Write a short introduction to the Gemma 4 API for developers."}
      ]
    }]
  }'

This captures the essence of Gemma 4 API usage: pick the model, pass structured content parts, and receive generated output from a hosted endpoint. From here you can expand to longer prompts, system instructions, multimodal inputs, JSON mode, and tool usage. (The legacy ?key=YOUR_API_KEY URL form still works if you prefer it.)

Request Structure: Contents, Parts, and Prompt Design

The Gemini API describes content generation in terms of contents and parts. This provides a flexible structure for text, images, and other supported input types. The same request shape that handles text-only prompts also supports richer multimodal scenarios by adding image or media input parts. This unified content structure lets you keep one mental model even as your app evolves from basic text prompts into multimodal or tool-using flows.

Prompt design still matters a lot. Even though the API call is straightforward, the result depends on how clearly you frame the task. If you want concise text, ask for it. If you want valid JSON, explicitly request it and pair that with the relevant output mode. If you want tool arguments, structure your instructions around tool semantics rather than general chat. The API gives you access to the model, but prompt structure shapes how effectively that access becomes product behavior.

Multimodal Requests: Text, Images, and More

Gemma 4 is natively multimodal. All sizes handle text and image input (with video support), and E2B, E4B, and the 12B add native audio. Gemma 4 can perform OCR, visual question answering, image captioning, object-related tasks, and reasoning across multiple images. So the API is not just for prompt-in, text-out chatbots - it can power screenshot analyzers, document-image tools, UI reviewers, and other image-aware applications.

For product builders, multimodal access can simplify architecture. Instead of routing text tasks to one model and image understanding to another vendor, you can prototype both with the same general API pattern - useful for support copilots, document workflows, creative assistants, or browser extensions that blend user text with screenshot context.

๐Ÿ–ผ๏ธ Vision Q&A

Ask Gemma 4 to explain screenshots, extract fields, summarize diagrams, or answer questions about image content.

๐Ÿ“„ OCR-style tasks

Gemma 4's vision capabilities include OCR-related work, making it relevant for scanned content and UI text extraction.

๐ŸŽง Native audio (E2B/E4B/12B)

These sizes process audio directly, expanding the API story beyond text-only inputs.

Long Context and Why It Matters for API Design

Gemma 4 supports up to 256K tokens of context - 128K on the smaller models and 256K on the medium models. From an API standpoint, this changes what feels natural to build: larger document analysis, multi-step conversations, richer retrieved knowledge, and more ambitious agent prompts. You are no longer forced to compress every task into a tiny window.

That said, long context should be used deliberately. It's tempting to throw huge amounts of text at a model just because the window exists. In practice, good chunking, retrieval, and prompt framing still matter - especially when you care about latency, cost, or keeping the prompt focused on the parts of the input that matter.

Thinking Mode and Deliberate Reasoning

Gemma 4 supports configurable thinking for both text-only and multimodal tasks. For API users, that means the Gemma 4 API isn't only about fast direct responses - it can also support more deliberate reasoning when a task needs planning, explanation, or multi-step internal structure before a final answer.

Thinking mode is valuable for planning, research assistance, structured problem solving, and high-confidence output. But don't turn it on by default for everything - a coding autocomplete or quick FAQ response may not need an extended reasoning trace. The API advantage is control: choose when to favor speed and when to favor depth.

Function Calling and Structured App Workflows

Modern application builders care less about plain chat and more about useful action - which is where function calling matters. Gemma 4 ships built-in function-calling support, and its structured instruction-following makes tool-oriented prompting practical. In real applications, this lets you turn a user request into a structured decision about which function to call and what arguments to pass.

Think booking flows, CRM updates, internal dashboards, data extraction, or task automation. Instead of stopping at "here's what you should do," the model can produce structured payloads your app validates and executes. That's where the Gemma 4 API becomes much more than a text endpoint - it becomes a model layer inside an actual system.

{
  "action": "schedule_meeting",
  "arguments": {
    "title": "Gemma 4 API demo",
    "date": "2026-04-05",
    "time": "15:00",
    "attendees": ["team@example.com"]
  }
}

That kind of schema-shaped output is especially useful when paired with validation logic in your backend. The model suggests, your app verifies, then your app executes - usually the safest and most reliable way to build function-calling products.

JSON Mode and Structured Output

The Gemini API supports JSON mode. For Gemma 4 API users that's a big deal, because product teams often need outputs that parse reliably rather than prose that merely sounds good. JSON mode helps with extraction, classification labels, summaries with fixed fields, workflow planning, and anything that feeds another part of your app.

Downstream app logic gets far easier once model output is strongly structured. Instead of fragile regex parsing, you can ask the model for fixed keys and types - lowering engineering friction and reducing UI failures caused by messy freeform responses. This is where the conversation moves from "AI text generation" to "AI-powered application integration."

System Instructions and Prompt Control

Gemma 4 has first-class support for the system role, so the hosted path isn't restricted to raw single-turn prompts. You can shape the model's tone, role, formatting rules, and behavior before the user input even arrives - vital for support flows, internal knowledge assistants, coding tools, and any experience where consistency matters.

The strongest prompt stacks usually have three layers: a system instruction that sets role and boundaries, a user message that states the task, and an output-format instruction that defines the shape of the answer. Combine that with JSON mode or function calling and the result is far more production-friendly than a naive "just answer this question" approach.

Common Gemma 4 API Use Cases

๐Ÿ’ฌ Chat Assistants

Use hosted Gemma 4 for support bots, product guides, onboarding helpers, and internal Q&A assistants.

๐Ÿ–ผ๏ธ Screenshot & Vision Tools

Build screenshot explainers, OCR helpers, visual QA tools, and UI review experiences with Gemma 4's vision support.

๐Ÿงฐ Tool-Using Workflows

Pair Gemma output with backend functions to drive scheduling, search, CRM tasks, reporting, and automation.

๐Ÿ“„ Structured Extraction

Use JSON mode to parse product descriptions, docs, support tickets, and form-like text into fixed fields.

The unifying theme: the Gemma 4 API is most valuable when it's part of a system. It can be a chatbot, but it can also be the reasoning and parsing layer inside a more structured application.

Download Gemma 4 (Open Weights)

Prefer to self-host instead of calling the API? Gemma 4 is open-weight under Apache 2.0 - download any size in Safetensors, GGUF, or PyTorch format and run it yourself with no usage caps.

Mistakes to Avoid

Gemma 4 API FAQ

๐Ÿ’ก Best single-line takeaway

The Gemma 4 API is the hosted route to using Gemma 4 as a programmable service through the Gemini API - free per token, keyed via AI Studio auth keys, with modern developer features. Or download the open weights and self-host.

Final Take

Gemma 4 is not only an open-weight family for local experimentation - it's also a hosted developer story through the Gemini API. That makes "Gemma 4 API" genuinely useful, because it captures what many developers want: a fast way to integrate Gemma 4 into applications without first building their own inference stack. With current hosted model IDs like gemma-4-31b-it, gemma-4-26b-a4b-it, and gemma-4-12b-it, a free-per-token cost model, and AI Studio auth-key onboarding, the path is concrete.

If you're building a chat assistant, vision tool, document parser, coding helper, or agentic workflow, hosted Gemma access is worth serious consideration. Multimodal support, long context, reasoning controls, JSON mode, and function calling give you a practical bridge from experimentation to shipping. And if your needs later expand into self-hosting, the open weights are right there. That flexibility is one of the strongest parts of the Gemma 4 ecosystem.