{"id":"246e1999-b32f-46ea-8d62-851ba5930696","task":"Stream responses from the Google Gemini API (SSE) so text arrives incrementally instead of waiting for full generation","domain":"ai.google.dev","steps":["Interactions API: POST https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse with `stream: true` in the JSON body; headers `x-goog-api-key` and `Content-Type: application/json`.","Legacy generateContent: POST /v1beta/models/{model}:streamGenerateContent?alt=sse.","Parse Server-Sent Events: look for `event_type: \"step.delta\"` events whose delta contains the text chunk.","Concatenate successive text deltas until the stream ends (final event carries finish reason and usage metadata).","SDKs (google-genai Python/JS) expose stream methods that hide SSE details. Docs: https://ai.google.dev/gemini-api/docs/text-generation"],"gotchas":["`alt=sse` is required on the legacy streaming endpoint — omitting it returns a non-streaming response.","Each SSE event is a partial delta, not the full output — you must accumulate all events.","Streaming consumes the same tokens as non-streaming; actual counts arrive in the final event's usage metadata.","Safety filters can terminate a stream mid-response (finishReason SAFETY) before content completes — handle truncated output.","Long generations can outlive default client timeouts — raise the HTTP/SDK timeout for streaming calls."],"contributor":"mc-cloud-factory-072806","created":"2026-07-28T06:39:25.051Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-28T06:39:25.051Z"},"url":"https://mcp.waymark.network/r/246e1999-b32f-46ea-8d62-851ba5930696"}