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

# Stream an AI agent

> Runs the general AI agent and streams its response as Server-Sent Events over `text/event-stream`.

Each event carries a `type` (delta, tool_call, tool_result, done, or error) and a per-type payload.

The `done` event includes `sessionId`, `hasUndo`, and a `changes` summary of entities modified during the run.



## OpenAPI

````yaml post /ai-agent/stream
openapi: 3.1.0
info:
  title: HERO API
  version: current
  description: |-
    The HERO REST API.

    See https://developers.myhero.so for the rendered docs.
servers:
  - url: https://app.myhero.so
security: []
paths:
  /ai-agent/stream:
    post:
      tags:
        - AI
      summary: Stream an AI agent
      description: >-
        Runs the general AI agent and streams its response as Server-Sent Events
        over `text/event-stream`.


        Each event carries a `type` (delta, tool_call, tool_result, done, or
        error) and a per-type payload.


        The `done` event includes `sessionId`, `hasUndo`, and a `changes`
        summary of entities modified during the run.
      operationId: aiStream
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                chatMessages:
                  type: array
                  items:
                    type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - user
                          - ai
                      text:
                        type: string
                      metadata:
                        type: object
                        additionalProperties: {}
                    required:
                      - type
                      - text
                  minItems: 1
                context:
                  type: object
                  properties:
                    documentId:
                      type: string
                    projectId:
                      type: string
                    workspaceId:
                      type: string
                    organizationId:
                      type: string
                    mentions:
                      type: array
                      items: {}
                options:
                  type: object
                  properties:
                    provider:
                      type: string
                    model:
                      type: string
                attachments:
                  type: array
                  items:
                    type: object
                    properties:
                      filename:
                        type: string
                      mimeType:
                        type: string
                      base64:
                        type: string
                      size:
                        type: integer
                        minimum: 0
                    required:
                      - filename
                      - mimeType
                      - base64
                      - size
                sessionId:
                  type: string
                documentRefs:
                  type: array
                  items:
                    type: object
                    properties:
                      documentId:
                        type: string
                      format:
                        type: string
                        enum:
                          - editor
                          - docx
                          - pdf
                      addedAt:
                        type: number
                    required:
                      - documentId
                      - format
                      - addedAt
              required:
                - chatMessages
      responses:
        '200':
          description: SSE stream of EventStreamChunk events
          content:
            text/event-stream:
              schema:
                type: object
                properties:
                  type:
                    type: string
                    enum:
                      - delta
                      - tool_call
                      - tool_result
                      - done
                      - error
                  data: {}
                required:
                  - type
        '400':
          description: 400 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '401':
          description: 401 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '403':
          description: 403 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '429':
          description: 429 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: HERO personal access token

````