Utilities for managing Gemini long‑decode token budgets and continuation handling.
# Source: https://github.com/NousResearch/hermes-agent | License: MIT | Copyright 2025 Nous Research # Provided via justclaw.it.com; keep this notice with the code. """Gemini long decode: one response spread over several generateContent hops. Gemini 4 caps each request (32,768 tokens unary, 65,536 streamed) but lets ``maxOutputTokens`` reach 1,048,576 minus the input. A hop that hits the per-request cap with budget left ends with ``finishReason: CONTINUATION`` plus a ``continuationToken``; the client resends the SAME request with that token (never the partial output) until any other finish reason. Each hop re-reads the prompt plus everything generated so far, so per-hop ``promptTokenCount`` grows: usage is summed for billing (what the google-genai SDK reports and Google bills) while the f ... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key