◉GEMINI LABJP
●CLI 0.71 — Gemini CLI v0.71.0 is out as a preview. The stable release is still v0.70.0●TOOL RETR — Tool retrieval (Preview) lets the model load tool definitions only when it needs them●2.5 ROUTE — From 12/1, gemini-2.5-pro routes to 3.8 Flash and 2.5-flash to 3.5 Flash-Lite, billed at the new rates (9 days left)●OAUTH — Users report a stored MCP OAuth token being sent to a repointed server URL without asking●PICK — Choosing a daily Gemini 4 model gets easier when you weigh reasoning, long context and price●AG NEON — Antigravity App v2.34.0 adds Gemini 4 Neon for Gemini API keys●CLI 0.71 — Gemini CLI v0.71.0 is out as a preview. The stable release is still v0.70.0●TOOL RETR — Tool retrieval (Preview) lets the model load tool definitions only when it needs them●2.5 ROUTE — From 12/1, gemini-2.5-pro routes to 3.8 Flash and 2.5-flash to 3.5 Flash-Lite, billed at the new rates (9 days left)●OAUTH — Users report a stored MCP OAuth token being sent to a repointed server URL without asking●PICK — Choosing a daily Gemini 4 model gets easier when you weigh reasoning, long context and price●AG NEON — Antigravity App v2.34.0 adds Gemini 4 Neon for Gemini API keys
Articles/Dev Tools
⟐ Dev Tools/2026-06-24Intermediate

Folding a Local Gemma 4 into Daily Work — Practical Notes on the Ollama API and Response Speed

Taking a local Gemma 4 you can now run interactively and folding it into real work: how to hit Ollama's local API from a script, tricks to improve perceived response speed, and a two-tier fallback that automatically routes to the cloud Gemini API — code included.

GemmaGemma 412Ollama8local LLM6API12Gemini99premium4

✦ Premium Article

The previous article covered launching Gemma 4 locally with Ollama and running it interactively. This follow-up steps into folding that local model into real work. Typing into the conversation window by hand draws out only half the benefit. Only once you can call it from a script can you hand it the work that repeats.

As an indie developer, I have moments where I try a great many store-listing phrasings and blog drafts, and I offload those trials to a local Gemma 4. Here I lay out how to hit the API, how to squeeze the speed, and how to escape safely to the cloud, implementation included.

Ollama stands up a local REST API

It is less known than it should be, but on launch Ollama quietly stands up a local HTTP server behind the scenes. By default it listens on localhost:11434, and posting there lets you call the model without opening the conversation window. The clearest start is hitting the generate endpoint.

curl http://localhost:11434/api/generate -d '{
  "model": "gemma4:e2b",
  "prompt": "Give me three polite review replies",
  "stream": false
}'

With stream set to false, you receive the result in one piece after generation finishes. When wiring into a script, this single-call shape is the easiest to handle. Conversely, to show long text gradually, set stream to true and process the fragments as they arrive.

Call it from Python and fold it into repeated work

You can hit the CLI directly, but for repeated use it is easier to wrap it in a script. That it can be written with the standard library alone also fits indie development, where you would rather not add dependencies.

import json, urllib.request
 
def ask_local(prompt: str, model: str = "gemma4:e2b") -> str:
    payload = json.dumps({"model": model, "prompt": prompt, "stream": False}).encode()
    req = urllib.request.Request(
        "http://localhost:11434/api/generate",
        data=payload, headers={"Content-Type": "application/json"},
    )
    with urllib.request.urlopen(req, timeout=120) as res:
        return json.loads(res.read())["response"]
 
if __name__ == "__main__":
    print(ask_local("Summarize this note into three bullet points: ..."))

With a wrapper this thin, you can call a canned instruction as a function as many times as you like. I run store-listing phrasings and note summaries through this shape, and one layer of retyping by hand vanished. Always attaching a timeout matters quietly — it keeps the whole process from freezing when the model jams.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Minimal code to hit Ollama's local REST API from a script and receive results
✦A measurement script that splits load time from generation speed via load_duration and eval_count, so you can verify keep_alive numerically
✦A two-tier setup that judges local output by how it ends, not just its length, and logs how often it escalated to the cloud
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⟐ Dev Tools2026-08-21
How Many Assistant-Dependent Lines Are Still in Your App?
Since September 4th, Google Assistant on Android has been progressively replaced by Gemini. Here is how to grep your own project for every entry point an assistant can open, and how to turn that list into utterances you can actually test on a device.
◈ API / SDK2026-04-26
Production-Ready Function Calling with Gemini 2.5 Pro API — Realistic Patterns for Failures, Timeouts, and Hallucinations
Gemini 2.5 Pro's Function Calling is powerful, but it tends to land in 'works, but does odd things sometimes' territory in production. Here are the design patterns I arrived at running search, reservation, and notification agents.
⟐ Dev Tools2026-11-07
The Morning an Android Build Stopped on 'Duplicate Resources' and Dropbox Was the Cause
Building inside a synced folder left more than 80 conflicted copies in my generated files and stopped an Android build. Here is how I found the cause, how I took build and .gradle out of sync, and where I now keep a project before letting an agent run builds.