Use Gemma 4 for free with Google AI Studio
Use Google's open Gemma 4 31B free in Google AI Studio: set instructions, ask about an image, then call it from code in under 20 minutes.

What you need
You must be 18 or older and in a supported country to use AI Studio. On the free tier, Google may use what you send to improve its products.
Step 1: Open Gemma 4 in AI Studio
2 minAI Studio runs Gemma 4 on Google's servers, so you need no download and no GPU.
- Go to this AI Studio link and sign in. It opens a new chat with Gemma 4 31B.
- Check that the model shown for the chat is Gemma 4 31B.
- For faster replies, switch to the Gemma 4 26B A4B model in the model list.
You should see an empty chat, ready to use Gemma 4 31B.
You see a 403 Access Restricted error?
AI Studio isn't offered where you are, or your Google account isn't set to 18 or older. Check the birthday in your Google Account settings.
31B is the larger dense model. 26B A4B only uses about 4 billion parameters per token, so it answers faster. Both read up to 256K tokens.
Step 2: Write system instructions
3 minSystem instructions set the role, tone and format once, so you don't repeat them in every message.
- Click Run settings in the top-right corner to open the panel.
- Paste the text below into System Instructions, and fill in the part in brackets.
- Leave temperature at 1.0, the value Google recommends for Gemma 4 in every task.
Your system instructionsYou are a helpful analyst for [YOUR ROLE OR TEAM]. Answer in plain English for a busy reader. Start with a one-line answer, then give up to 5 bullet points. When you read an image, say what you see before you explain it. If something is unclear or missing, say so instead of guessing.
You should see your instructions saved in the System Instructions field.
Answers got worse after you lowered the temperature?
Set it back to 1.0. Google's Gemma 4 guide uses temperature 1.0, top P 0.95 and top K 64 for all tasks.
Step 3: Ask about an image
4 minGemma 4 reads images as well as text, so it can explain a chart or pull facts from a screenshot.
- Use the add button next to the prompt box to upload your image.
- Paste the prompt below into the Type something... box, then click Run.
- Ask a follow-up in the same chat to dig into one detail.
Your promptWhat does this image show? List the 3 most important numbers or facts in it, and say what they mean for [YOUR GOAL].
You should see an answer in your format that names details from your image.
It misreads small text in the image?
Crop the image to the part you need and upload it again. Tiny text inside a large image is the hardest part to read.
Google's tip for Gemma 4: put the image before the text. In AI Studio, add the image first, then type.
Step 4: Copy the code
2 minGet code turns the chat you built into an API request you can run anywhere.
- When the chat gives the answers you want, click Get code.
- Pick the language you work in and copy the code.
You should see code that calls the model
gemma-4-31b-it.Step 5: Call Gemma 4 with an API key
5 minAn API key lets your own scripts and apps call Gemma 4, still for free.
- Open the API keys page. New users already have a key there. Copy it, or click Create API key.
- In a terminal, paste the command below with your key in place of [YOUR API KEY].
- Press Enter to run it.
Run this (Mac or Linux)export GEMINI_API_KEY="[YOUR API KEY]" 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' \ -d '{ "system_instruction": {"parts": [{"text": "Answer in 2 short sentences."}]}, "contents": [{"parts": [{"text": "What is an open model?"}]}] }'You should see a JSON reply with Gemma's answer in the
textfield.You get a 429 error?
You've hit a free tier rate limit. Check your limits on the rate limit page, wait a minute and try again.
Keep your key out of code you share or commit. Store it in an environment variable, as here, or in a git-ignored file.
You get
Gemma 4 31B set up in AI Studio with your instructions, and a free API key that calls it from code
Try next
Did this guide work for you?
Thanks. It helps us fix the steps.


