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

# Stream generated content

> The streaming form of generate content: the answer arrives in parts as it is written.



## OpenAPI

````yaml /api-reference/openapi.json post /genai/v1beta/models/{model}:streamGenerateContent
openapi: 3.1.0
info:
  title: Altrum AI Gateway API
  version: 1.0.0
  description: >-
    The public API of the Altrum AI Gateway. It accepts the OpenAI, Anthropic
    and Gemini request formats, so an existing client needs only a new base URL
    and a virtual key.
servers:
  - url: https://api.altrum.ai
security:
  - bearer: []
  - apiKey: []
  - googleApiKey: []
  - altrumKey: []
tags:
  - name: OpenAI
  - name: Anthropic
  - name: Gemini
  - name: MCP
  - name: Health
paths:
  /genai/v1beta/models/{model}:streamGenerateContent:
    post:
      tags:
        - Gemini
      summary: Stream generated content
      description: >-
        The streaming form of generate content: the answer arrives in parts as
        it is written.
      operationId: streamGenerateContent
      parameters:
        - name: model
          in: path
          required: true
          schema:
            type: string
          description: The model, such as `gemini-3.5-flash` or `gemini/gemini-3.5-flash`.
          example: gemini-3.5-flash
        - $ref: '#/components/parameters/RequestIdIn'
        - $ref: '#/components/parameters/PromptId'
        - $ref: '#/components/parameters/PromptVersion'
        - $ref: '#/components/parameters/CacheKey'
        - $ref: '#/components/parameters/CacheTtl'
        - $ref: '#/components/parameters/CacheThreshold'
        - $ref: '#/components/parameters/CacheType'
        - $ref: '#/components/parameters/CacheNoStore'
        - $ref: '#/components/parameters/DisableContentLogging'
        - $ref: '#/components/parameters/DirectKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              description: A Gemini generateContent request.
              required:
                - contents
              properties:
                contents:
                  type: array
                  items:
                    type: object
                    additionalProperties: true
              additionalProperties: true
            example:
              contents:
                - role: user
                  parts:
                    - text: Say hello.
      responses:
        '200':
          description: The answer.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
            x-alt-trace-id:
              $ref: '#/components/headers/TraceId'
            x-alt-provider:
              $ref: '#/components/headers/Provider'
            x-alt-resolved-model:
              $ref: '#/components/headers/ResolvedModel'
            x-alt-fallback-index:
              $ref: '#/components/headers/FallbackIndex'
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
                example:
                  candidates:
                    - content:
                        role: model
                        parts:
                          - text: Hello.
                      finishReason: STOP
              example:
                candidates:
                  - content:
                      role: model
                      parts:
                        - text: Hello.
                    finishReason: STOP
            text/event-stream:
              schema:
                type: string
                description: >-
                  Sent when the request asks to stream. Events keep the format
                  of the API you called.
        '400':
          description: >-
            The request was refused: a guardrail stopped it, or the body or a
            header is not valid.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeminiError'
        '401':
          description: No virtual key was sent, or the key does not exist or was revoked.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeminiError'
        '402':
          description: A budget that covers this key is used up.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeminiError'
        '403':
          description: >-
            The key, AI system, organization, model, provider or tool is not
            allowed.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeminiError'
        '404':
          description: A prompt named in `x-alt-prompt-id` was not found.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeminiError'
        '413':
          description: The request has more text than the guardrails can check at once.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeminiError'
        '422':
          description: A guardrail stopped the reply.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeminiError'
        '429':
          description: A rate limit that covers this key was reached.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeminiError'
        '503':
          description: The guardrails could not be checked, or the provider is unavailable.
          headers:
            x-request-id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeminiError'
components:
  parameters:
    RequestIdIn:
      name: x-request-id
      in: header
      required: false
      description: >-
        Your own reference for the request. Altrum uses it instead of making
        one, and returns it.
      schema:
        type: string
    PromptId:
      name: x-alt-prompt-id
      in: header
      required: false
      description: >-
        Use a prompt saved in your AI Gateway prompts. Its messages go before
        yours.
      schema:
        type: string
    PromptVersion:
      name: x-alt-prompt-version
      in: header
      required: false
      description: The prompt version to use, such as `2`. Without it, the latest version.
      schema:
        type: integer
    CacheKey:
      name: x-alt-cache-key
      in: header
      required: false
      description: >-
        Keeps this request's cached answers apart from others, for example per
        customer.
      schema:
        type: string
    CacheTtl:
      name: x-alt-cache-ttl
      in: header
      required: false
      description: >-
        Keeps the answer for less time than your setting: `30s`, `5m`, `1h` or a
        number of seconds.
      schema:
        type: string
      example: 5m
    CacheThreshold:
      name: x-alt-cache-threshold
      in: header
      required: false
      description: Asks for a closer match than your setting, from 0 to 1.
      schema:
        type: number
    CacheType:
      name: x-alt-cache-type
      in: header
      required: false
      description: '`direct` matches word for word only, `semantic` by meaning only.'
      schema:
        type: string
        enum:
          - direct
          - semantic
    CacheNoStore:
      name: x-alt-cache-no-store
      in: header
      required: false
      description: >-
        `true` serves from the cache when it can, but does not store this
        answer.
      schema:
        type: string
        enum:
          - 'true'
    DisableContentLogging:
      name: x-alt-disable-content-logging
      in: header
      required: false
      description: >-
        `true` keeps this request's prompt and reply out of the request log,
        even when your organization keeps content.
      schema:
        type: string
        enum:
          - 'true'
    DirectKey:
      name: x-alt-direct-key
      in: header
      required: false
      description: >-
        `true` sends your own provider key in `Authorization`, `x-api-key` or
        `x-goog-api-key`, with your virtual key in `x-alt-vk`. Only when your
        organization allows it.
      schema:
        type: string
        enum:
          - 'true'
  headers:
    RequestId:
      description: The request's reference. Quote it to support.
      schema:
        type: string
    TraceId:
      description: The trace the request belongs to.
      schema:
        type: string
    Provider:
      description: The provider that answered.
      schema:
        type: string
    ResolvedModel:
      description: The model that answered.
      schema:
        type: string
    FallbackIndex:
      description: 'Present when a fallback answered: `1` for the first fallback.'
      schema:
        type: integer
  schemas:
    GeminiError:
      type: object
      description: >-
        An error on the Gemini routes. The request id is in the `x-request-id`
        header.
      properties:
        error:
          type: object
          properties:
            code:
              type: integer
            message:
              type: string
            status:
              type: string
              description: A refusal code or a stable code.
      example:
        error:
          code: 429
          message: 'Rate limit exceeded: ...'
          status: rate_limited
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: >-
        Your virtual key, `sk-alt-...`. What every OpenAI and Anthropic SDK
        sends.
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: Your virtual key, as Anthropic clients send it.
    googleApiKey:
      type: apiKey
      in: header
      name: x-goog-api-key
      description: Your virtual key, as Gemini clients send it.
    altrumKey:
      type: apiKey
      in: header
      name: x-alt-vk
      description: >-
        Your virtual key. Needed when `Authorization` carries your own provider
        key (`x-alt-direct-key`).

````

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