---
title: "Stream content with the Google Gemini protocol"
method: POST
path: "/v1beta/models/{model}:streamGenerateContent"
tags: ["Gemini"]
---

# Stream content with the Google Gemini protocol

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

## Request

- Base URL: `https://api.sandbase.ai`
- URL: `https://api.sandbase.ai/v1beta/models/{model}:streamGenerateContent`
- Auth: one of:
  - API key in header `x-goog-api-key`
  - HTTP bearer
  - API key in query parameter `key`

Returns a streamed JSON array by default. Add alt=sse to receive Server-Sent Events instead.

## Path parameters

- `model` string, required

## Query parameters

- `alt` 'sse'

## Request body

- GeminiGenerateContentRequest: Google Gemini GenerateContent request. Native passthrough mappings preserve provider-defined fields; translated mappings use the documented capability subset.
  - `contents` GeminiContent[]
    - `role` 'user' | 'model'
    - `parts` object[]
  - `systemInstruction` GeminiContent
    - `role` 'user' | 'model'
    - `parts` object[]
  - `generationConfig` object
    - `temperature` number
    - `topP` number
    - `topK` integer
    - `maxOutputTokens` integer
    - `stopSequences` string[]
    - `candidateCount` integer: Translated mappings accept only 1 when supplied; native passthrough mappings preserve the provider request.
    - `seed` integer
    - `presencePenalty` number
    - `frequencyPenalty` number
    - `responseMimeType` 'text/plain' | 'application/json' | 'text/x.enum'
    - `responseSchema` object
    - `responseModalities` string[]: Native image mappings support provider image modalities. Other translated mappings may support TEXT only.
    - `thinkingConfig` object
  - `tools` object[]
  - `toolConfig` object
  - `safetySettings` object[]
  - `cachedContent` string: Passed through when the selected provider supports Gemini context caching.

## Response `200`

Gemini response frames

- GeminiGenerateContentResponse[]
  - `candidates` object[]
    - `content` GeminiContent
      - `role` 'user' | 'model'
      - `parts` object[]
    - `finishReason` string
    - `index` integer
    - `safetyRatings` object[]
  - `usageMetadata` object
    - `promptTokenCount` integer
    - `candidatesTokenCount` integer
    - `totalTokenCount` integer
    - `cachedContentTokenCount` integer
    - `thoughtsTokenCount` integer
  - `promptFeedback` object
  - `modelVersion` string
  - `responseId` string

## Other responses

- `400`: Invalid JSON or an input field that SandBase cannot safely translate
- `401`: Missing, invalid, revoked, or expired API key
- `402`: Organization balance and credit are exhausted
- `403`: API Key spending limit reached, organization disabled, or upstream permission rejected
- `404`: Model, method, or upstream resource not found
- `429`: Provider rate limit exceeded before streaming starts
- `500`: Prediction lifecycle or provider error before streaming starts
- `502`: Upstream stream could not be translated
- `503`: Routing failed or all provider candidates were unavailable
- `504`: Upstream request timed out before streaming starts

---

[API](https://skmtc.dev/sandbase/apis/sandbase-api.md) · [All operations](https://skmtc.dev/sandbase/apis/sandbase-api/llms.txt) · [OpenAPI document](https://skmtc.dev/sandbase/apis/sandbase-api/revisions/d40df2467ba2?raw)
