Python 88.3%
TypeScript 7.6%
Shell 4.1%
1#!/usr/bin/env python32# STATUS: LIVE_VERIFIED — executed 2026-09-18 (exit 0 in 0.9s)3# streamGenerateContent with ?alt=sse (SSE framing) — prints each chunk's text and the final finishReason/usage.4# Run: .venv/bin/python examples/gemini/streaming/stream.py (GEMINI_API_KEY read from .env via scripts.live; google-genai 2.24)5import pathlib6import sys78ROOT = pathlib.Path(__file__).resolve().parents[3]9sys.path.insert(0, str(ROOT))10from scripts import live # noqa: E402 loads .env, provides log_request1112from google import genai # noqa: E40213from google.genai import types # noqa: E402,F4011415client = genai.Client()16MODEL = "gemini-3.5-flash-lite"17n = 018for chunk in client.models.generate_content_stream(model=MODEL, contents="Count from 1 to 12 separated by spaces.", config=types.GenerateContentConfig(max_output_tokens=32)):19 n += 120 print(repr(chunk.text), chunk.candidates[0].finish_reason, chunk.usage_metadata.candidates_token_count)21live.log_request("gemini", "POST", "/v1beta/models/{model}:streamGenerateContent", 200, 0.00007, f"example streaming/stream.py ({n} chunks)")22assert n >= 223