Skip to content

Run Gemma with Ollama

Models Gemma 4 Uses Ollama

Ollama downloads quantized weights for you and exposes a CLI plus a local HTTP API. No GPU required, though one helps.

Install

Download from ollama.com/download, then check it worked:

ollama --version

Run

ollama run gemma4:12b "Explain quantum computing simply"

Downloads the model on first use. To fetch without running:

ollama pull gemma4:12b

Model tags

Tag Download Context
gemma4:e2b 7.2 GB 128K
gemma4:e4b 9.6 GB 128K
gemma4:12b 7.6 GB 256K
gemma4:26b 18 GB 256K
gemma4:31b 20 GB 256K

gemma4:latest is an alias for e4b. On Apple Silicon, the -mlx tags (gemma4:12b-mlx) use the MLX runtime. Full list: ollama.com/library/gemma4/tags.

Images

ollama run gemma4:12b ./image.png "What is in this image?"

Note

Ollama publishes Gemma 4 as text and image only. For audio input, use Transformers or llama.cpp.

Server

Ollama serves on port 11434.

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:11434/v1/",
    api_key="ollama",  # required but ignored
)

response = client.chat.completions.create(
    model="gemma4:12b",
    messages=[{"role": "user", "content": "Say this is a test"}],
)
print(response.choices[0].message.content)
curl http://localhost:11434/api/generate -d '{
  "model": "gemma4:12b",
  "prompt": "roses are red"
}'
IMG=$(base64 < test.jpg | tr -d '\n')

curl -X POST http://localhost:11434/api/chat \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemma4:12b",
    "messages": [{
      "role": "user",
      "content": "What is in this image?",
      "images": ["'"$IMG"'"]
    }],
    "stream": false
  }'

Context defaults to 4K under 24 GiB VRAM

Ollama sizes context from available VRAM, not from the model. Raise it when you need it: OLLAMA_CONTEXT_LENGTH=64000 ollama serve, or per request with "options": {"num_ctx": 64000}. Agents and coding tools want at least 64K — Ollama: context length.