◉GEMINI LABJP
●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer
Articles/API / SDK
◈ API / SDK/2026-04-12Advanced

Gemini API Production Performance Tuning — Removing Latency, Throughput, and Cost Bottlenecks One at a Time

A rewritten guide to lowering Gemini API latency, throughput limits, and cost together, updated for the December 1 automatic reroute of the 2.5 models (3.5 Flash-Lite, 3.8 Flash, 4 Argon). Covers streaming retries that never duplicate output, choosing Standard, Flex, Priority, or Batch, break-even-based Context Caching, three-lane model routing, 429-aware flow control, and thinking_level, with runnable code and a symptom triage table.

gemini-api291performance4optimization4production140latency3throughputcost6flex-inferencecontext-caching4streaming28

✦ Premium Article

I was reading the morning report for an overnight tagging run on my wallpaper app when all three problems showed up on the same screen: responses were slower, the bill was higher, and the log was full of 429s. I tried to fix everything at once. The day I added retries to the streaming path, I shipped a new bug — the same paragraph appeared twice on screen. The retry itself wasn't the problem. I was restarting the stream from the top without remembering what I had already sent.

This page is a rewrite of how I handle latency, throughput, and cost together, with runnable code and a triage table. Because the Gemini API starts automatically rerouting the 2.5 models on December 1, 2026, I've also updated every model name and price to what's current.

The one thing I'd like you to take away up front: you don't pick two of the three. You measure first, then remove one bottleneck at a time. The order below is measurement → perceived speed → pricing tiers → caching → model routing → flow control → thinking depth.

The Ground Rules as of November 2026 — The December 1 Reroute and the Model Table

The previous version of this article assumed gemini-2.5-flash and gemini-2.5-pro. According to the official deprecations page, starting December 1, 2026, gemini-2.5-pro is automatically routed to gemini-3.8-flash and gemini-2.5-flash to gemini-3.5-flash-lite, billed at the destination model's price. Your code keeps working, which is exactly why your measurements and invoice change without anyone noticing.

Model in your codeModel that answers from 12/1Input / output (per 1M tokens)Watch out for
gemini-2.5-flashgemini-3.5-flash-lite$0.30 / $2.50Same text price; different output behavior
gemini-2.5-progemini-3.8-flash$0.75 / $3.75 (through 12/31) → $1.50 / $7.50 (from 2027-01-01)Price doubles in January
gemini-4-argon (heavy work)unchanged$2.00 / $10.00 (through 11/30) → $4.00 / $20.00 (from 12/1)No explicit caching; temperature and friends are ignored

These are the values listed on the official Pricing page as of November 2026. Because two introductory-price deadlines fall a month apart, the gap between Argon and 3.8 Flash is widest in December. I keep my estimates split by month for that reason.

Every snippet in this article pulls model names from one module, so a reroute means editing one file.

# models.py — model names and prices live here only (as of 2026-11; check official Pricing)
from datetime import date
 
LITE = "gemini-3.5-flash-lite"   # classification, tagging, short summaries
FLASH = "gemini-3.8-flash"       # default: chat and most generation
HEAVY = "gemini-4-argon"         # long multi-step work and hard reasoning only
 
# (date this price starts applying in my calculations, input, output) USD per 1M tokens, newest first
PRICES = {
    LITE:  [(date(2026, 1, 1), 0.30, 2.50)],
    FLASH: [(date(2027, 1, 1), 1.50, 7.50), (date(2026, 9, 2), 0.75, 3.75)],
    HEAVY: [(date(2026, 12, 1), 4.00, 20.00), (date(2026, 1, 1), 2.00, 10.00)],
}
 
def price_on(model: str, day: date) -> tuple[float, float]:
    """Return the (input, output) price valid on that day. Unknown models raise."""
    for start, inp, out in PRICES[model]:
        if day >= start:
            return inp, out
    raise KeyError(f"{model}: no price registered for {day}")

The KeyError is deliberate. An estimate that silently computes an unknown model at zero dollars is how an unnoticed loss begins.

Measure First — Break "Slow" Into Parts

"Slow" is never one thing. It splits into time to first token (TTFT), generation time, and time lost to retries. The old profiler counted stream chunks and called them tokens, which understated generation speed. The fixed version reads the real output token count from the final chunk's usage_metadata.

# profile.py — TTFT, total time, and output tokens/sec for one request
import time
from google import genai
from models import LITE, FLASH
 
client = genai.Client()  # reads GEMINI_API_KEY from the environment
 
def profile_request(model: str, prompt: str) -> dict:
    t0 = time.perf_counter()
    ttft = None
    usage = None
    served = None
    for chunk in client.models.generate_content_stream(model=model, contents=prompt):
        if ttft is None and chunk.text:
            ttft = time.perf_counter() - t0
        if chunk.usage_metadata:          # totals arrive on the last chunk
            usage = chunk.usage_metadata
        served = getattr(chunk, "model_version", None) or served
    total = time.perf_counter() - t0
    out_tokens = (usage.candidates_token_count or 0) if usage else 0
    thoughts = (getattr(usage, "thoughts_token_count", 0) or 0) if usage else 0
    gen = total - (ttft or total)
    return {
        "requested": model, "served": served,
        "ttft_s": round(ttft or -1, 3), "total_s": round(total, 3),
        "out_tokens": out_tokens, "thought_tokens": thoughts,
        "out_tok_per_s": round(out_tokens / gen, 1) if gen > 0 else None,
    }
 
if __name__ == "__main__":
    for m in (LITE, FLASH):
        print(profile_request(m, "Write a Python binary search and explain its complexity in three lines."))

The output has this shape (the numbers vary a lot by environment and time of day, so I'm only showing the structure):

{'requested': 'gemini-3.5-flash-lite', 'served': 'gemini-3.5-flash-lite', 'ttft_s': ..., 'total_s': ..., 'out_tokens': ..., 'thought_tokens': 0, 'out_tok_per_s': ...}

The point of this function is logging requested and served side by side. From December 1, any row that asked for gemini-2.5-flash will show a different served name, and the log itself tells you the day your baseline changed underneath you.

✦

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
✦The 12/1 reroute (2.5 Pro to 3.8 Flash, 2.5 Flash to 3.5 Flash-Lite), month-by-month prices, and a single models.py for every model name
✦Streaming retries that never resend delivered text, and batch calls that go back through the rate limiter on every retry
✦A seven-row triage table (symptom, cause, check, fix) and a one-line rule for picking Standard, Flex, Priority, or Batch
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

◈ API / SDK2026-04-21
Rendering Gemini's Thought Summaries in a Next.js UI — A Production Pattern for Explainable AI
A production walkthrough for surfacing Gemini 2.5 / 3 thought summaries in a Next.js UI. Covers the SDK configuration, Server-Sent Events, a React collapsible component, observability, and the UX judgement calls you face when you decide how much of the AI's reasoning to show.
◈ API / SDK2026-07-15
Sample what you already accepted — an audit budget that catches silent quality drift
A confidence gate only ever looks at output the model hesitated on. Silent drift sinks into the batch that sailed through. Working from a fixed 30-minutes-a-day review budget, this walks through deriving detection time from the binomial, reallocating the same budget across risk strata, and catching slow decay with a cumulative monitor.
◈ API / SDK2026-07-04
When Gemini API Leaks Japanese Into Your English Output Once in a While — Field Notes on Measuring the Contamination Rate and Tightening It in Stages
You told Gemini to answer in English, and 3 out of 100 runs slip a Japanese sentence into the tail. Here is why you cannot stop that 'once in a while', and a production pattern that measures the contamination rate as an SLO and tightens it with graded recovery, with working code.