◉GEMINI LABJP
●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 6 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 6 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…
Articles/API / SDK
◈ API / SDK/2026-07-17Advanced

A Gemini stream drops halfway — restart it, or have the model continue?

Most apps silently restart a dropped stream. Here is the arithmetic behind continuing from the partial output instead, and where to put the threshold.

Gemini API249streaming28cost design7idempotency5mobile6

✦ Premium Article

My train pulled into a station and the text my app was generating stopped mid-sentence. The app quietly started over, and the same opening paragraph scrolled past a second time.

What stuck with me was not the wait. It was that the 600 tokens of prose that had just vanished were almost certainly billed. The user never saw a word of it, and a second generation was already underway.

Google's Southeast Asia report put roughly three quarters of Gemini app requests on mobile. Flaky connections are not an edge case you handle later; they are the normal operating condition. As an indie developer shipping Gemini into mobile apps, I have stopped treating a dropped stream as an anomaly.

Why streams drop is a separate investigation. This piece is about the decision you make afterwards.

You cannot tell how much a dropped stream cost you

The usageMetadata block on streamGenerateContent arrives near the end of the chunk sequence. If you receive the stream to completion, you get exact input, output, and thinking token counts.

Which means that for the attempt that died, you get nothing. The client has no way to confirm how far generation had progressed when the connection dropped.

And what happens server-side when a client disconnects — whether generation stops immediately, whether billing stops with it — is not spelled out in the public documentation.

Assuming "probably not billed" quietly corrupts your design. I work on the assumption that every chunk I received was paid for. That is not pessimism so much as refusing to round an unknown in my own favour.

SituationusageMetadataActual billing
Stream completesAvailableKnown exactly
Connection dropsNever arrivesUnknown — assume the worst
Client cancelsNever arrivesUnknown (same)

If you cannot measure the spend, at least count the events. Logging each disconnect with the number of characters already received costs nothing and pays off later.

Restarting and continuing have different cost shapes

Let P be the prompt tokens, O the output tokens needed to finish, and R the output tokens you received before the drop. Let Ci be the input rate and Co the output rate.

The dead attempt (Ci×P + Co×R) is spent either way. The difference shows up in what comes next.

ApproachSecond inputSecond outputWhat you throw away
RestartPOThe R tokens you already have
ContinueP + RO − RA clean seam

Subtract one from the other:

restart − continue
 = (Ci×P + Co×O) − (Ci×(P+R) + Co×(O−R))
 = Co×R − Ci×R
 = R × (Co − Ci)

Gemini prices output above input, so Co − Ci is positive and continuing is always nominally cheaper.

Read the formula more carefully, though. The saving scales with R. At R = 60 tokens you save 60 × (Co − Ci), which will not repay the code you are about to write.

Deciding "always continue" on cost alone misreads this result. Continuation earns its keep only when R is large — when a long piece of prose died near the end.

✦

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
✦You can replace blanket retries with a rule that decides per drop whether to reuse the text you already received
✦You can plug your own pricing into R × (output rate − input rate) and see whether continuation is worth building at all
✦You can fix the three seam defects — restatement, tonal steps, renumbered lists — before they reach users
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-08-01
When Sampling Parameters Were Deprecated, Diversity Broke Before Determinism Did
Deprecating temperature, top_p and top_k hurt the diversity-generating side of my pipeline, not the deterministic side. Counting real call sites, moving diversity to the input layer, and measuring effective diversity.
◈ API / SDK2026-07-05
Splitting Bulk Image Generation Cost in Two with Nano Banana 2 Lite: A Draft-and-Render Design
A two-tier cost design that routes first-pass generation to Nano Banana 2 Lite and final renders to the standard Nano Banana 2, with a minimal Python router you can adapt.
◈ API / SDK2026-04-03
Gemini API × SwiftUI in Production: Streaming, Multimodal, Error Handling, and App Store Submission
A production-grade guide to integrating the Gemini API into SwiftUI apps at production quality. Covers streaming responses, multimodal input, error handling, test strategies, and App Store submission requirements.