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

# Stream agent response (AI SDK format)

> Build and stream responses from an agent in AI SDK v6 UIMessageStream format. Compatible with assistant-ui and AI SDK useChat. Provide either agentId or copilotId. Requests with the shared TRUSTED_KEY bypass DB API-key lookup; otherwise an API key in the Authorization header is validated.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/chat
openapi: 3.1.0
info:
  title: Sidenet API
  version: 1.0.0
  description: >-
    Custom HTTP endpoints exposed by the Sidenet Mastra server. All routes
    require a bearer token and resolve org context from the API key (or the
    `X-Organization-Id` header). This reference is generated from the live route
    definitions in `src/mastra/routes`.
servers:
  - url: ''
security:
  - bearerAuth: []
paths:
  /v1/chat:
    servers:
      - url: /
    post:
      tags:
        - V1
      summary: Stream agent response (AI SDK format)
      description: >-
        Build and stream responses from an agent in AI SDK v6 UIMessageStream
        format. Compatible with assistant-ui and AI SDK useChat. Provide either
        agentId or copilotId. Requests with the shared TRUSTED_KEY bypass DB
        API-key lookup; otherwise an API key in the Authorization header is
        validated.
      parameters:
        - name: X-Organization-Id
          in: header
          required: false
          schema:
            type: string
          description: >-
            Organization to scope the request to. Optional when authenticating
            with an org API key (the org is taken from the key; if sent, it must
            match). Required when authenticating with the trusted key.
        - name: X-User-Id
          in: header
          required: false
          schema:
            type: string
          description: >-
            End-user identity for the request; user-scoped data (threads,
            memory) resolves to `{orgId}_{userId}`. Required by endpoints that
            read or write user-scoped resources. A `userId` query param (or body
            field, where documented) is accepted as a fallback.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                messages:
                  type: array
                  minItems: 1
                agentId:
                  type: string
                  description: Stable agents.id — runs the agent's ACTIVE published version
                agentVersionId:
                  type: string
                  description: >-
                    Override: run this EXACT agent_versions.id (e.g. preview a
                    draft or a non-active published version) instead of the
                    active one
                copilotId:
                  type: string
                  description: Copilot id to route through (alternative to agentId)
                threadId:
                  type: string
                  description: Conversation thread id
                groupId:
                  type: string
                  minLength: 1
                  maxLength: 255
                  nullable: true
                  description: >-
                    Optional STABLE caller-supplied chatter group id
                    (chatter_groups.external_id). When sent, group matching is
                    by this id; a differing groupName renames the group.
                groupName:
                  type: string
                  nullable: true
                  description: >-
                    Optional chatter group name. Without groupId this
                    matches/provisions by name (legacy behavior); alongside
                    groupId it is display-only (rename on change).
                runtimeAuth:
                  type: object
                  additionalProperties:
                    type: object
                    additionalProperties: {}
                  description: >-
                    Runtime authentication map: { [providerNameOrId]: {
                    credentials } }
                context:
                  type: array
                  items:
                    type: string
                  description: Additional context messages to provide to the agent.
                trigger:
                  type: string
                  enum:
                    - submit-message
                    - regenerate-message
                  description: AI SDK trigger type
                tools:
                  type: object
                  additionalProperties: {}
                  description: AI SDK client-side tools
                metadata:
                  type: object
                  additionalProperties: {}
                  description: AI SDK session metadata
                use_routing:
                  type: boolean
                  default: true
                  description: >-
                    Default true. When the request lands on an orchestrator
                    (copilot routing agent that was not optimized to a
                    subagent), a pre-stream Handoff Agent picks whether to
                    stream the orchestrator (multi-step / synthesis) or a single
                    subagent directly (domain-specific ask). No-op when the
                    resolved agent is not an orchestrator flow. Pass false to
                    disable.
              required:
                - messages
              additionalProperties: false
      responses:
        '200':
          description: AI SDK v6 UIMessageStream response
          content:
            text/event-stream:
              schema:
                type: string
        '400':
          description: Bad request - missing required fields
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    type: string
        '404':
          description: Agent version not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    type: string
        '429':
          description: Usage limit exceeded
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  message:
                    type: string
                  details:
                    type: object
                    properties:
                      currentUsage:
                        type: number
                      limit:
                        type: number
                      groupLimitRemaining:
                        type: number
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    type: string
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Org API key (scopes the request to its organization) or the shared
        trusted key (requires `X-Organization-Id` on every request).

````