How to use Gemma 4 with the Gemini API and Google AI Studio
Google's Gemma 4 family of open models is now available through the Gemini API and Google AI Studio. Built from the same research behind Gemini 3, these models bring advanced reasoning, native function calling, multimodal understanding, and 256K context windows to an open, Apache 2.0-licensed package you can run anywhere.
Two models are available through the Gemini API today:
gemma-4-26b-a4b-itgemma-4-31b-it
What makes Gemma 4 different#
Gemma 4 models handle function calling, structured JSON output, and system instructions at the model level rather than through prompt engineering. The 31B dense model currently ranks as the #3 open model on the Arena AI text leaderboard, with the 26B MoE model at #6, competing with models 20x their size.
Key capabilities:
- 256K context window on both models
- Native function calling and structured output
- Multimodal text, images, and video
- 140+ languages trained natively
- Apache 2.0 license full commercial use, no restrictions
Getting started with AI Studio#
The fastest way to try Gemma 4 is Google AI Studio. Select gemma-4-26b-a4b-it or gemma-4-31b-it from the model picker, type a prompt, and start chatting. You can test system instructions, adjust temperature, and experiment with multimodal inputs all through the browser. No API key or code required.
Or click Get Code to export Python, JavaScript, or cURL snippets from any conversation.
Using Gemma 4 with the Gemini API#
Install the Python SDK:
Bash
Set your API key as an environment variable. You can create one at aistudio.google.com/apikey.
Bash
Text generation#
Generate text with Gemma 4:
Python
=
=
Pass a system instruction to set the model's behavior:
Python
=
=
Multi-turn conversations#
The SDK provides a chat interface that tracks conversation history automatically:
Python
=
=
=
=
Image understanding#
Pass an image alongside your text prompt:
Python
=
=
=
Function calling#
Define tools as function declarations. The model decides when to call them:
Python
# Define the function declaration
=
=
=
=
=
# The model returns a function call instead of text
= ...
Google Search#
Ground Gemma 4 responses in real-time web data with Google Search:
Python
=
=
# Access grounding metadata for citations
Where to go next#
- Google AI Studio — Try Gemma 4 in the browser
- Gemini API documentation
- Gemma Documentation
- Gemma Cookbooks
Thanks for reading! If you have any questions or feedback, please let me know on Twitter or LinkedIn.