Stream content

Endpoint
POST/v1beta/models/{model}:streamGenerateContent

Same request body as Generate content; call this endpoint to stream. The response is text/event-stream.

Request

Headers and parameters are identical to Generate content. The official SDK and examples add the ?alt=sse query parameter; SSE is returned with or without it.

Parameters

Same as Generate content.

Response

Each chunk is a data: {...} line with the same structure as the non-streaming response (candidates, usageMetadata); text is in candidates[0].content.parts[].text, and concatenating the chunks gives the full reply. The connection closes when the stream ends; there is no separate end marker.

Examples

bash
curl "https://api.moyiapi.com/v1beta/models/gemini-3.5-flash:streamGenerateContent?alt=sse" \
  -H "Authorization: Bearer sk-moyiapi-xxxxxx" \
  -H "content-type: application/json" \
  -d '{
    "contents": [
      {"role": "user", "parts": [{"text": "Write a four-line poem"}]}
    ]
  }'

Errors

Errors before the stream starts (authentication failures, unavailable models) are returned as normal JSON errors; see Streaming.

Ready? Three steps to startLog in to the console · top up · create an API key
DiscordGet community help instantly
Stream content · Docs