> ## Documentation Index
> Fetch the complete documentation index at: https://docs.playapi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini streamGenerateContent

> Native SSE text and function calls.

`POST /v1beta/models/{model}:streamGenerateContent?alt=sse`

Send the gateway token in `x-goog-api-key` and select SSE with `alt=sse`. The request shape matches nonstreaming generateContent, but uses a different path action; a Chat-style `stream` body field is not a substitute.

Each SSE data payload contains a Gemini response. Text and function calls appear in candidate content parts. Check prompt feedback, candidate indices, and the final finish reason; EOF alone is insufficient. Declare tools through `tools[].functionDeclarations` and return results as `functionResponse`.

[The complete Python SSE and tool-loop example](/en/guides/native-gemini-streaming) covers both run modes, signature preservation, optional ID association, and failures. This schema expands common fields only, without guaranteeing Live API, fine-grained argument extensions, or support on every channel.

[阅读中文](/zh/api-reference/gemini-stream)

## Media content parts

Native `contents[].parts[]` can contain `inlineData: {mimeType, data}` or `fileData: {mimeType, fileUri}`; inline data is plain Base64. The target upstream must support the format and source. `videoMetadata` and `mediaResolution` are conditional native extensions, not a universal gateway transcoding or frame-extraction service.

Media input does not change the response protocol or completion checks. The audited gateway scope provides no Gemini Files upload/management or Interactions endpoints; SDK auto-upload introduces extra unsupported requests. Start with the [complete non-streaming video example](/en/guides/video-understanding); streamed output still follows this endpoint's SSE events.

## Built-in metadata in SSE

The request accepts the same conditional native `googleSearch`, `urlContext`, and `codeExecution` tool fields. Native SSE forwards upstream JSON events. Retain candidate metadata and code/result parts across events; do not flatten all events into plain text or assume each event contains a complete grounding record. The existing text/function SSE sample does not implement these built-in consumers. Start with the [non-streaming built-in example](/en/guides/gemini-builtins); native byte offsets and source association need protocol-aware accumulation before adding streaming.


## OpenAPI

````yaml openapi/relay.json POST /v1beta/models/{model}:streamGenerateContent
openapi: 3.0.3
info:
  title: API — Core inference API
  version: 0.5.0
  description: >-
    面向接入的精选规范，不是全部管理或供应商接口。 / Curated integration specification, not the entire
    management or provider API.
  license:
    name: AGPL-3.0-or-later
servers:
  - url: https://gateway.example.com
    description: >-
      Example only; replace with your gateway origin and optional path prefix,
      without /v1.
security:
  - BearerAuth: []
paths:
  /v1beta/models/{model}:streamGenerateContent:
    post:
      summary: Gemini 原生流式生成 / Native Gemini streaming generation
      description: >-
        原生 SSE；每个 data 包含 Gemini 响应对象。完成状态与工具处理见指南。 / Native SSE; each data
        payload is a Gemini response object. See the guide for completion and
        tool handling.
      operationId: streamGeminiContent
      parameters:
        - name: model
          in: path
          required: true
          description: >-
            裸模型 ID，不含 models/ 和动作后缀 / Bare model ID without models/ or an action
            suffix.
          schema:
            type: string
            example: YOUR_MODEL_ID
        - name: alt
          in: query
          required: true
          schema:
            type: string
            enum:
              - sse
          description: 选择 SSE 传输 / Select SSE transport.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - contents
              properties:
                contents:
                  type: array
                  minItems: 1
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                      parts:
                        type: array
                        items:
                          type: object
                          properties:
                            text:
                              type: string
                            thought:
                              type: boolean
                            thoughtSignature:
                              type: string
                            functionCall:
                              type: object
                              properties:
                                id:
                                  type: string
                                name:
                                  type: string
                                args:
                                  type: object
                                  additionalProperties: true
                              additionalProperties: true
                            functionResponse:
                              type: object
                              properties:
                                id:
                                  type: string
                                name:
                                  type: string
                                response:
                                  type: object
                                  additionalProperties: true
                              additionalProperties: true
                            inlineData:
                              type: object
                              required:
                                - mimeType
                                - data
                              properties:
                                mimeType:
                                  type: string
                                  example: video/mp4
                                data:
                                  type: string
                                  description: >-
                                    纯 Base64，不带 Data URL 前缀 / Plain Base64, no
                                    Data URL prefix
                              description: >-
                                原生内联媒体，格式与大小依模型 / Native inline media;
                                model-dependent formats and limits
                            fileData:
                              type: object
                              properties:
                                mimeType:
                                  type: string
                                fileUri:
                                  type: string
                              description: >-
                                上游可访问的 URI；不是网关上传服务 / Upstream-accessible URI,
                                not a gateway upload service
                            videoMetadata:
                              type: object
                              additionalProperties: true
                              description: >-
                                模型依赖的原生扩展；请核对实际上游结构 / Model-dependent native
                                extension; verify the upstream structure
                            mediaResolution:
                              type: object
                              additionalProperties: true
                              description: >-
                                模型依赖的原生扩展；请核对实际上游结构 / Model-dependent native
                                extension; verify the upstream structure
                            executableCode:
                              type: object
                              properties:
                                language:
                                  type: string
                                  example: PYTHON
                                code:
                                  type: string
                              additionalProperties: true
                            codeExecutionResult:
                              type: object
                              properties:
                                outcome:
                                  type: string
                                  description: 检查 OUTCOME_OK / Check OUTCOME_OK
                                output:
                                  type: string
                              additionalProperties: true
                          additionalProperties: true
                    additionalProperties: true
                systemInstruction:
                  type: object
                  properties:
                    role:
                      type: string
                    parts:
                      type: array
                      items:
                        type: object
                        properties:
                          text:
                            type: string
                          thought:
                            type: boolean
                          thoughtSignature:
                            type: string
                          functionCall:
                            type: object
                            properties:
                              id:
                                type: string
                              name:
                                type: string
                              args:
                                type: object
                                additionalProperties: true
                            additionalProperties: true
                          functionResponse:
                            type: object
                            properties:
                              id:
                                type: string
                              name:
                                type: string
                              response:
                                type: object
                                additionalProperties: true
                            additionalProperties: true
                        additionalProperties: true
                  additionalProperties: true
                tools:
                  type: array
                  items:
                    type: object
                    properties:
                      functionDeclarations:
                        type: array
                        items:
                          type: object
                          required:
                            - name
                          properties:
                            name:
                              type: string
                            description:
                              type: string
                            parameters:
                              type: object
                              additionalProperties: true
                              description: >-
                                工具参数 Schema；示例额外执行本地校验 / Tool parameter schema;
                                examples also validate locally.
                          additionalProperties: true
                      googleSearch:
                        type: object
                        additionalProperties: true
                        description: >-
                          以空对象启用；依赖原生模型及渠道支持 / Enable with an empty object;
                          native model and channel support required
                        example: {}
                      urlContext:
                        type: object
                        additionalProperties: true
                        description: >-
                          以空对象启用；依赖原生模型及渠道支持 / Enable with an empty object;
                          native model and channel support required
                        example: {}
                      codeExecution:
                        type: object
                        additionalProperties: true
                        description: >-
                          以空对象启用；依赖原生模型及渠道支持 / Enable with an empty object;
                          native model and channel support required
                        example: {}
                    additionalProperties: true
              additionalProperties: true
      responses:
        '200':
          description: >-
            检查候选结束状态并处理流内错误 / Validate candidate finish status and in-stream
            errors.
          content:
            text/event-stream:
              schema:
                type: string
        default:
          description: >-
            网关或上游错误，结构可能随协议变化 / Gateway or upstream error; structure may vary by
            protocol.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
      security:
        - GeminiApiKey: []
        - BearerAuth: []
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: 模型调用 API Key，不是控制台登录凭据 / Model API key, not console login credentials
    GeminiApiKey:
      type: apiKey
      in: header
      name: x-goog-api-key
      description: 网关令牌 / Gateway token

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.