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

# Chat

> Streaming AI assistant chat endpoint (Server-Sent Events).

Each SSE frame is ``data: <JSON>\n\n`` where the JSON carries
``{type: "chunk"|"done"|"error", content?: str, provider?: str, model?: str}``.

If the client passes ``stream: false`` the full response is returned as a
plain JSON object instead.



## OpenAPI

````yaml /openapi.json post /v1/ai/chat
openapi: 3.1.0
info:
  description: Causeloop Platform Backend
  title: Causeloop API
  version: 1.0.0
servers: []
security: []
paths:
  /v1/ai/chat:
    post:
      tags:
        - ai
      summary: Chat
      description: >-
        Streaming AI assistant chat endpoint (Server-Sent Events).


        Each SSE frame is ``data: <JSON>\n\n`` where the JSON carries

        ``{type: "chunk"|"done"|"error", content?: str, provider?: str, model?:
        str}``.


        If the client passes ``stream: false`` the full response is returned as
        a

        plain JSON object instead.
      operationId: chat_v1_ai_chat_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatBody'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema: {}
          description: Successful Response
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: Validation Error
      security:
        - HTTPBearer: []
components:
  schemas:
    ChatBody:
      properties:
        max_tokens:
          default: 1024
          maximum: 4096
          minimum: 1
          title: Max Tokens
          type: integer
        messages:
          items:
            $ref: '#/components/schemas/ChatMessage'
          minItems: 1
          title: Messages
          type: array
        stream:
          default: true
          title: Stream
          type: boolean
        system:
          anyOf:
            - type: string
            - type: 'null'
          title: System
      required:
        - messages
      title: ChatBody
      type: object
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: Detail
          type: array
      title: HTTPValidationError
      type: object
    ChatMessage:
      properties:
        content:
          title: Content
          type: string
        role:
          pattern: ^(system|user|assistant)$
          title: Role
          type: string
      required:
        - role
        - content
      title: ChatMessage
      type: object
    ValidationError:
      properties:
        ctx:
          title: Context
          type: object
        input:
          title: Input
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          title: Location
          type: array
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
      type: object
  securitySchemes:
    HTTPBearer:
      scheme: bearer
      type: http

````