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

# Send a chat message with file attachments and stream the response via SSE



## OpenAPI

````yaml /api-v2.json post /sessions/{session_id}/chat/stream
openapi: 3.1.0
info:
  title: Meibel AI API
  summary: Meibel Gateway Service
  description: >-
    Our API allows you to interact with our services. Read the
    [docs](https://docs.meibel.ai) to learn how to use it.
  version: 0.6.4
servers:
  - url: https://api.meibel.ai/v2
    description: Meibel API (v2)
  - url: https://api.dev.meibel.ai/v2
    description: Meibel Dev API (v2)
  - url: http://localhost:8000/v2
    description: Local Development
security: []
tags:
  - name: Datasources
    description: v2 datasource management
  - name: Data Elements
    description: v2 data element CRUD and search
  - name: File Upload
    description: Upload files to a datasource and track upload progress
  - name: Ingest
    description: Trigger and monitor datasource ingestion
  - name: Datasource Downloads
    description: Export all datasource content as a zip archive
  - name: Table Descriptions
    description: v2 table and column descriptions
  - name: Metadata Model Catalog
    description: v2 metadata model catalog
  - name: Confidence Scoring
    description: v2 confidence scoring jobs and summaries
  - name: Documents
    description: Parse and transform documents into structured data
  - name: Agents
    description: Agent definition management
  - name: Sessions
    description: Agent session (execution) management and chat
  - name: Execution Policies
    description: Data access and tool usage constraints scoped to agent sessions
  - name: Artifact Schemas
    description: Agent artifact schema management
paths:
  /sessions/{session_id}/chat/stream:
    post:
      tags:
        - Sessions
      summary: >-
        Send a chat message with file attachments and stream the response via
        SSE
      operationId: sendChatMessageStream
      parameters:
        - name: session_id
          in: path
          required: true
          schema:
            type: string
            title: Session Id
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Body_sendChatMessageStream'
      responses:
        '200':
          description: Successful Response
          content:
            text/event-stream:
              x-forge-sse-sentinel: '[DONE]'
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ConnectedEvent'
                  - $ref: '#/components/schemas/StatusEvent'
                  - $ref: '#/components/schemas/ToolCallEvent'
                  - $ref: '#/components/schemas/ToolResultEvent'
                  - $ref: '#/components/schemas/PartialResponseEvent'
                  - $ref: '#/components/schemas/CompletionEvent'
                discriminator:
                  propertyName: event
                  mapping:
                    connected:
                      $ref: '#/components/schemas/ConnectedEvent'
                    status:
                      $ref: '#/components/schemas/StatusEvent'
                    tool_call:
                      $ref: '#/components/schemas/ToolCallEvent'
                    tool_result:
                      $ref: '#/components/schemas/ToolResultEvent'
                    partial_response:
                      $ref: '#/components/schemas/PartialResponseEvent'
                    completion:
                      $ref: '#/components/schemas/CompletionEvent'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
      x-codeSamples:
        - lang: Python
          label: Python
          source: |-
            import os
            from meibel import MeibelClient

            client = MeibelClient(api_key=os.environ["MEIBEL_API_KEY"])

            session_id = "sess_8f3a2b1c9d"

            with open("quarterly_report.pdf", "rb") as file:
                stream = client.agents.sessions.send_chat_message_stream(
                    session_id=session_id,
                    user_message="Summarize the key findings in this report.",
                    file=file,
                )

                for event in stream:
                    if event.event == "partial_response":
                        payload = event.json()
                        print(payload["data"], end="")
                    elif event.event == "tool_call":
                        payload = event.json()
                        print(f"\n[tool call] {payload['data']}")
                    elif event.event == "completion":
                        payload = event.json()
                        print(f"\n\nFinal response: {payload['data']}")
                        break
                    elif event.event == "error":
                        payload = event.json()
                        print(f"\nError: {payload['data']}")
                        break
        - lang: TypeScript
          label: TypeScript
          source: >-
            import { MeibelClient } from "meibel";

            import fs from "fs";


            const client = new MeibelClient({ apiKey: process.env.MEIBEL_API_KEY
            });


            const sessionId = "sess_9f8a7b6c5d4e";


            const stream = await
            client.agents.sessions.sendChatMessageStream(sessionId, {
              file: fs.createReadStream("./quarterly-report.pdf"),
            });


            for await (const event of stream) {
              switch (event.event) {
                case "partial_response":
                  process.stdout.write(event.data);
                  break;
                case "completion":
                  console.log(`\nFinal response: ${event.data}`);
                  break;
                case "error":
                  console.error(`Stream error: ${event.data}`);
                  break;
                default:
                  console.log(`[${event.event}] ${event.data}`);
              }
            }
        - lang: Go
          label: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"os\"\n\n\tv2 \"github.com/meibel-ai/meibel-go/v2\"\n)\n\nfunc main() {\n\tclient := v2.NewClient(v2.WithAPIKey(os.Getenv(\"MEIBEL_API_KEY\")))\n\n\tstream, err := client.Agents.Sessions.SendChatMessageStream(\n\t\tcontext.Background(),\n\t\t\"session_9f8a3c2b\",\n\t\tv2.BodySendChatMessageStream{\n\t\t\tUserMessage: \"Can you summarize the attached report?\",\n\t\t\tAttachments: []string{\"file_7a1b2c3d\"},\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfor event := range stream.Events() {\n\t\tswitch e := event.(type) {\n\t\tcase v2.CompletionEvent:\n\t\t\tfmt.Println(\"completion:\", e.Data)\n\t\tcase v2.ErrorEvent:\n\t\t\tfmt.Println(\"error:\", e.Data)\n\t\tcase v2.PartialResponseEvent:\n\t\t\tfmt.Println(\"partial:\", e.Data)\n\t\t}\n\t}\n\n\tif err := <-stream.Errors(); err != nil {\n\t\tfmt.Println(\"stream error:\", err)\n\t}\n}"
components:
  schemas:
    Body_sendChatMessageStream:
      properties:
        user_message:
          anyOf:
            - type: string
            - type: 'null'
          title: User Message
        timeout_seconds:
          anyOf:
            - type: integer
            - type: 'null'
          title: Timeout Seconds
        include_thinking:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Include Thinking
        include_tool_activity:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Include Tool Activity
        files:
          anyOf:
            - items:
                type: string
                contentMediaType: application/octet-stream
              type: array
            - type: 'null'
          title: Files
      type: object
      title: Body_sendChatMessageStream
    ConnectedEvent:
      description: >-
        A server-sent event indicating the stream connection has been
        established
      type: object
      required:
        - event
        - data
      properties:
        event:
          type: string
          const: connected
        data:
          type: object
          required:
            - signal_id
          properties:
            signal_id:
              type: string
              description: Unique identifier for this stream connection
    StatusEvent:
      description: A server-sent event containing an agent status update
      type: object
      required:
        - event
        - data
      properties:
        event:
          type: string
          const: status
        data:
          type: object
          required:
            - type
            - disposition
            - sequence
            - timestamp
            - content
          properties:
            type:
              type: string
            disposition:
              type: string
            sequence:
              type: string
            timestamp:
              type: string
            content:
              type: string
    ToolCallEvent:
      description: A server-sent event indicating the agent is calling a tool
      type: object
      required:
        - event
        - data
      properties:
        event:
          type: string
          const: tool_call
        data:
          type: object
          required:
            - type
            - disposition
            - sequence
            - timestamp
            - tool_id
            - tool_name
            - arguments
          properties:
            type:
              type: string
            disposition:
              type: string
            sequence:
              type: string
            timestamp:
              type: string
            tool_id:
              type: string
            tool_name:
              type: string
            arguments:
              type: object
    ToolResultEvent:
      description: A server-sent event containing the result of a tool call
      type: object
      required:
        - event
        - data
      properties:
        event:
          type: string
          const: tool_result
        data:
          type: object
          required:
            - type
            - disposition
            - sequence
            - timestamp
            - tool_id
            - result
          properties:
            type:
              type: string
            disposition:
              type: string
            sequence:
              type: string
            timestamp:
              type: string
            tool_id:
              type: string
            result:
              type: object
    PartialResponseEvent:
      description: A server-sent event containing an incremental response from the agent
      type: object
      required:
        - event
        - data
      properties:
        event:
          type: string
          const: partial_response
        data:
          type: object
          required:
            - type
            - disposition
            - sequence
            - timestamp
            - data
          properties:
            type:
              type: string
            disposition:
              type: string
            sequence:
              type: string
            timestamp:
              type: string
            data:
              type: object
              required:
                - message
                - clean_message
              properties:
                message:
                  type: string
                clean_message:
                  type: string
                citations:
                  type: array
                  items:
                    type: object
                sources:
                  type: array
                  items:
                    type: object
                follow_up_questions:
                  items:
                    type: string
                  type: array
                call_to_actions:
                  type: array
                  items:
                    type: object
                artifacts:
                  type: array
                  items:
                    type: object
    CompletionEvent:
      description: >-
        A server-sent event containing the final complete response from the
        agent, sent once at the end of the stream
      type: object
      required:
        - event
        - data
      properties:
        event:
          type: string
          const: completion
        data:
          type: object
          required:
            - type
            - disposition
            - sequence
            - timestamp
            - data
          properties:
            type:
              type: string
            disposition:
              type: string
            sequence:
              type: string
            timestamp:
              type: string
            data:
              type: object
              required:
                - message
                - clean_message
              properties:
                message:
                  type: string
                clean_message:
                  type: string
                citations:
                  type: array
                  items:
                    type: object
                    properties:
                      position:
                        type: integer
                      source_ids:
                        type: array
                        items:
                          type: integer
                sources:
                  type: array
                  items:
                    type: object
                    properties:
                      source_id:
                        type: integer
                      data_element_id:
                        type: string
                      title:
                        type: string
                      url:
                        type: string
                        nullable: true
                      snippet:
                        type: string
                      relevance_score:
                        type: number
                      tool_name:
                        type: string
                follow_up_questions:
                  items:
                    type: string
                  type: array
                call_to_actions:
                  type: array
                  items:
                    type: object
                artifacts:
                  type: array
                  items:
                    type: object
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: Meibel-API-Key

````