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

# Stream a session



## AsyncAPI

````yaml asyncapi.yaml session
id: session
title: Session
description: |
  Real-time session execution stream.
servers:
  - id: production
    protocol: wss
    host: api.raccoonai.tech
    bindings: []
    variables: []
address: /ws/sessions/{sessionId}?token={token}&message_id={messageId}
parameters:
  - id: sessionId
    jsonSchema:
      type: string
      description: Session ID (`session_id` from the `/sessions/new` response)
    description: Session ID (`session_id` from the `/sessions/new` response)
    type: string
    required: true
    deprecated: false
  - id: messageId
    jsonSchema:
      type: string
      description: |
        Message ID (`agent_message_id` from the `/sessions/new` response)
    description: |
      Message ID (`agent_message_id` from the `/sessions/new` response)
    type: string
    required: true
    deprecated: false
  - id: token
    jsonSchema:
      type: string
      description: |
        Raccoon AI API key

        **Other optional query params:**
             - `last_stream_entry_id` - Last received stream entry ID for reconnection (e.g., "0-0")
    description: |
      Raccoon AI API key

      **Other optional query params:**
           - `last_stream_entry_id` - Last received stream entry ID for reconnection (e.g., "0-0")
    type: string
    required: true
    deprecated: false
bindings: []
operations:
  - &ref_2
    id: receiveUpdates
    title: Receive updates
    description: Receive turn updates
    type: receive
    messages:
      - &ref_4
        id: ack
        contentType: application/json
        payload:
          - name: Connection Acknowledged
            description: Confirms WebSocket connection established
            type: object
            properties:
              - name: type
                type: string
                description: ack
                required: false
              - name: resume_from
                type: string
                description: Stream entry ID to resume from (empty if starting fresh)
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              const: ack
              x-parser-schema-id: <anonymous-schema-5>
            resume_from:
              type: string
              description: Stream entry ID to resume from (empty if starting fresh)
              x-parser-schema-id: <anonymous-schema-6>
          x-parser-schema-id: <anonymous-schema-4>
        title: Connection Acknowledged
        description: Confirms WebSocket connection established
        example: |-
          {
            "type": "ack",
            "resume_from": ""
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: ack
      - &ref_5
        id: thought
        contentType: application/json
        payload:
          - name: Agent Thought
            description: Agent reasoning/thinking content
            type: object
            properties:
              - name: event_id
                type: integer
                description: >-
                  Monotonically increasing event ID for ordering and
                  deduplication
                required: true
              - name: timestamp
                type: integer
                description: Unix timestamp in milliseconds
                required: true
              - name: kind
                type: string
                description: Event type
                enumValues:
                  - thought
                  - text
                  - tool.start
                  - tool.result
                  - plan.update
                  - message.received
                  - task.completed
                  - task.aborted
                  - task.error
                  - sandbox.snapshot
                required: true
              - name: block_id
                type: string
                description: >-
                  Block this event relates to (e.g., "answer:main",
                  "tool:bash:run-1", "plan:root")
                required: false
              - name: message_id
                type: string
                description: Message ID this event belongs to
                required: false
              - name: payload
                type: object
                description: Event-specific data
                required: true
        headers: []
        jsonPayloadSchema: &ref_0
          type: object
          required:
            - event_id
            - timestamp
            - kind
            - payload
          properties:
            event_id:
              type: integer
              description: Monotonically increasing event ID for ordering and deduplication
              x-parser-schema-id: <anonymous-schema-7>
            timestamp:
              type: integer
              description: Unix timestamp in milliseconds
              x-parser-schema-id: <anonymous-schema-8>
            kind:
              type: string
              description: Event type
              enum:
                - thought
                - text
                - tool.start
                - tool.result
                - plan.update
                - message.received
                - task.completed
                - task.aborted
                - task.error
                - sandbox.snapshot
              x-parser-schema-id: <anonymous-schema-9>
            block_id:
              type: string
              nullable: true
              description: >-
                Block this event relates to (e.g., "answer:main",
                "tool:bash:run-1", "plan:root")
              x-parser-schema-id: <anonymous-schema-10>
            message_id:
              type: string
              description: Message ID this event belongs to
              x-parser-schema-id: <anonymous-schema-11>
            payload:
              type: object
              description: Event-specific data
              x-parser-schema-id: <anonymous-schema-12>
          x-parser-schema-id: Event
        title: Agent Thought
        description: Agent reasoning/thinking content
        example: |-
          {
            "event_id": 3,
            "timestamp": 1703001234200,
            "kind": "thought",
            "block_id": "thought:reasoning",
            "message_id": "msg_ghi789",
            "payload": {
              "thought": "Let me analyze the requirements...",
              "finalize": false
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: thought
      - &ref_6
        id: text
        contentType: application/json
        payload:
          - name: Text Content
            description: Plain text content
            type: object
            properties:
              - name: event_id
                type: integer
                description: >-
                  Monotonically increasing event ID for ordering and
                  deduplication
                required: true
              - name: timestamp
                type: integer
                description: Unix timestamp in milliseconds
                required: true
              - name: kind
                type: string
                description: Event type
                enumValues:
                  - thought
                  - text
                  - tool.start
                  - tool.result
                  - plan.update
                  - message.received
                  - task.completed
                  - task.aborted
                  - task.error
                  - sandbox.snapshot
                required: true
              - name: block_id
                type: string
                description: >-
                  Block this event relates to (e.g., "answer:main",
                  "tool:bash:run-1", "plan:root")
                required: false
              - name: message_id
                type: string
                description: Message ID this event belongs to
                required: false
              - name: payload
                type: object
                description: Event-specific data
                required: true
        headers: []
        jsonPayloadSchema: *ref_0
        title: Text Content
        description: Plain text content
        example: |-
          {
            "event_id": 4,
            "timestamp": 1703001234300,
            "kind": "text",
            "block_id": "text:message",
            "message_id": "msg_ghi789",
            "payload": {
              "text": "Processing your request"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: text
      - &ref_7
        id: toolStart
        contentType: application/json
        payload:
          - name: Tool Started
            description: Tool execution started
            type: object
            properties:
              - name: event_id
                type: integer
                description: >-
                  Monotonically increasing event ID for ordering and
                  deduplication
                required: true
              - name: timestamp
                type: integer
                description: Unix timestamp in milliseconds
                required: true
              - name: kind
                type: string
                description: Event type
                enumValues:
                  - thought
                  - text
                  - tool.start
                  - tool.result
                  - plan.update
                  - message.received
                  - task.completed
                  - task.aborted
                  - task.error
                  - sandbox.snapshot
                required: true
              - name: block_id
                type: string
                description: >-
                  Block this event relates to (e.g., "answer:main",
                  "tool:bash:run-1", "plan:root")
                required: false
              - name: message_id
                type: string
                description: Message ID this event belongs to
                required: false
              - name: payload
                type: object
                description: Event-specific data
                required: true
        headers: []
        jsonPayloadSchema: *ref_0
        title: Tool Started
        description: Tool execution started
        example: |-
          {
            "event_id": 10,
            "timestamp": 1703001235000,
            "kind": "tool.start",
            "block_id": "tool:bash:run-1",
            "message_id": "msg_ghi789",
            "payload": {
              "tool_name": "bash"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: toolStart
      - &ref_8
        id: toolResult
        contentType: application/json
        payload:
          - name: Tool Result
            description: Tool execution completed
            type: object
            properties:
              - name: event_id
                type: integer
                description: >-
                  Monotonically increasing event ID for ordering and
                  deduplication
                required: true
              - name: timestamp
                type: integer
                description: Unix timestamp in milliseconds
                required: true
              - name: kind
                type: string
                description: Event type
                enumValues:
                  - thought
                  - text
                  - tool.start
                  - tool.result
                  - plan.update
                  - message.received
                  - task.completed
                  - task.aborted
                  - task.error
                  - sandbox.snapshot
                required: true
              - name: block_id
                type: string
                description: >-
                  Block this event relates to (e.g., "answer:main",
                  "tool:bash:run-1", "plan:root")
                required: false
              - name: message_id
                type: string
                description: Message ID this event belongs to
                required: false
              - name: payload
                type: object
                description: Event-specific data
                required: true
        headers: []
        jsonPayloadSchema: *ref_0
        title: Tool Result
        description: Tool execution completed
        example: |-
          {
            "event_id": 15,
            "timestamp": 1703001236000,
            "kind": "tool.result",
            "block_id": "tool:bash:run-1",
            "message_id": "msg_ghi789",
            "payload": {
              "status": "success",
              "output": {
                "exit_code": 0
              },
              "finalize": true
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: toolResult
      - &ref_9
        id: planUpdate
        contentType: application/json
        payload:
          - name: Plan Updated
            description: Todo list updated
            type: object
            properties:
              - name: event_id
                type: integer
                description: >-
                  Monotonically increasing event ID for ordering and
                  deduplication
                required: true
              - name: timestamp
                type: integer
                description: Unix timestamp in milliseconds
                required: true
              - name: kind
                type: string
                description: Event type
                enumValues:
                  - thought
                  - text
                  - tool.start
                  - tool.result
                  - plan.update
                  - message.received
                  - task.completed
                  - task.aborted
                  - task.error
                  - sandbox.snapshot
                required: true
              - name: block_id
                type: string
                description: >-
                  Block this event relates to (e.g., "answer:main",
                  "tool:bash:run-1", "plan:root")
                required: false
              - name: message_id
                type: string
                description: Message ID this event belongs to
                required: false
              - name: payload
                type: object
                description: Event-specific data
                required: true
        headers: []
        jsonPayloadSchema: *ref_0
        title: Plan Updated
        description: Todo list updated
        example: |-
          {
            "event_id": 20,
            "timestamp": 1703001240000,
            "kind": "plan.update",
            "block_id": "plan:root",
            "message_id": "msg_ghi789",
            "payload": {
              "patch": {
                "todos": [
                  {
                    "id": "todo_1",
                    "content": "Set up project structure",
                    "status": "completed"
                  },
                  {
                    "id": "todo_2",
                    "content": "Implement main logic",
                    "status": "active"
                  },
                  {
                    "id": "todo_3",
                    "content": "Add tests",
                    "status": "pending"
                  }
                ]
              }
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: planUpdate
      - &ref_10
        id: messageReceived
        contentType: application/json
        payload:
          - name: Message Received
            description: User message received by agent
            type: object
            properties:
              - name: event_id
                type: integer
                description: >-
                  Monotonically increasing event ID for ordering and
                  deduplication
                required: true
              - name: timestamp
                type: integer
                description: Unix timestamp in milliseconds
                required: true
              - name: kind
                type: string
                description: Event type
                enumValues:
                  - thought
                  - text
                  - tool.start
                  - tool.result
                  - plan.update
                  - message.received
                  - task.completed
                  - task.aborted
                  - task.error
                  - sandbox.snapshot
                required: true
              - name: block_id
                type: string
                description: >-
                  Block this event relates to (e.g., "answer:main",
                  "tool:bash:run-1", "plan:root")
                required: false
              - name: message_id
                type: string
                description: Message ID this event belongs to
                required: false
              - name: payload
                type: object
                description: Event-specific data
                required: true
        headers: []
        jsonPayloadSchema: *ref_0
        title: Message Received
        description: User message received by agent
        example: |-
          {
            "event_id": 1,
            "timestamp": 1703001230000,
            "kind": "message.received",
            "message_id": "msg_ghi789",
            "payload": {
              "text": "Build a REST API with authentication",
              "files": [],
              "references": []
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: messageReceived
      - &ref_11
        id: sandboxSnapshot
        contentType: application/json
        payload:
          - name: Sandbox Snapshot
            description: Sandbox file system state updated
            type: object
            properties:
              - name: event_id
                type: integer
                description: >-
                  Monotonically increasing event ID for ordering and
                  deduplication
                required: true
              - name: timestamp
                type: integer
                description: Unix timestamp in milliseconds
                required: true
              - name: kind
                type: string
                description: Event type
                enumValues:
                  - thought
                  - text
                  - tool.start
                  - tool.result
                  - plan.update
                  - message.received
                  - task.completed
                  - task.aborted
                  - task.error
                  - sandbox.snapshot
                required: true
              - name: block_id
                type: string
                description: >-
                  Block this event relates to (e.g., "answer:main",
                  "tool:bash:run-1", "plan:root")
                required: false
              - name: message_id
                type: string
                description: Message ID this event belongs to
                required: false
              - name: payload
                type: object
                description: Event-specific data
                required: true
        headers: []
        jsonPayloadSchema: *ref_0
        title: Sandbox Snapshot
        description: Sandbox file system state updated
        example: |-
          {
            "event_id": 35,
            "timestamp": 1703001252000,
            "kind": "sandbox.snapshot",
            "message_id": "msg_ghi789",
            "payload": {
              "sandbox_id": "sbx_abc123",
              "snapshot": {
                "src/main.py": {
                  "key": "src/main.py",
                  "name": "main.py",
                  "updatedAt": 1703001252000
                }
              },
              "deleted": []
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: sandboxSnapshot
      - &ref_12
        id: taskCompleted
        contentType: application/json
        payload:
          - name: Task Completed
            description: Task finished successfully
            type: object
            properties:
              - name: event_id
                type: integer
                description: >-
                  Monotonically increasing event ID for ordering and
                  deduplication
                required: true
              - name: timestamp
                type: integer
                description: Unix timestamp in milliseconds
                required: true
              - name: kind
                type: string
                description: Event type
                enumValues:
                  - thought
                  - text
                  - tool.start
                  - tool.result
                  - plan.update
                  - message.received
                  - task.completed
                  - task.aborted
                  - task.error
                  - sandbox.snapshot
                required: true
              - name: block_id
                type: string
                description: >-
                  Block this event relates to (e.g., "answer:main",
                  "tool:bash:run-1", "plan:root")
                required: false
              - name: message_id
                type: string
                description: Message ID this event belongs to
                required: false
              - name: payload
                type: object
                description: Event-specific data
                required: true
        headers: []
        jsonPayloadSchema: *ref_0
        title: Task Completed
        description: Task finished successfully
        example: |-
          {
            "event_id": 100,
            "timestamp": 1703001300000,
            "kind": "task.completed",
            "message_id": "msg_ghi789",
            "payload": {}
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: taskCompleted
      - &ref_13
        id: taskAborted
        contentType: application/json
        payload:
          - name: Task Aborted
            description: Task stopped by user or system
            type: object
            properties:
              - name: event_id
                type: integer
                description: >-
                  Monotonically increasing event ID for ordering and
                  deduplication
                required: true
              - name: timestamp
                type: integer
                description: Unix timestamp in milliseconds
                required: true
              - name: kind
                type: string
                description: Event type
                enumValues:
                  - thought
                  - text
                  - tool.start
                  - tool.result
                  - plan.update
                  - message.received
                  - task.completed
                  - task.aborted
                  - task.error
                  - sandbox.snapshot
                required: true
              - name: block_id
                type: string
                description: >-
                  Block this event relates to (e.g., "answer:main",
                  "tool:bash:run-1", "plan:root")
                required: false
              - name: message_id
                type: string
                description: Message ID this event belongs to
                required: false
              - name: payload
                type: object
                description: Event-specific data
                required: true
        headers: []
        jsonPayloadSchema: *ref_0
        title: Task Aborted
        description: Task stopped by user or system
        example: |-
          {
            "event_id": 55,
            "timestamp": 1703001265000,
            "kind": "task.aborted",
            "message_id": "msg_ghi789",
            "payload": {
              "reason": "User requested stop"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: taskAborted
      - &ref_14
        id: taskError
        contentType: application/json
        payload:
          - name: Task Error
            description: Task failed with error
            type: object
            properties:
              - name: event_id
                type: integer
                description: >-
                  Monotonically increasing event ID for ordering and
                  deduplication
                required: true
              - name: timestamp
                type: integer
                description: Unix timestamp in milliseconds
                required: true
              - name: kind
                type: string
                description: Event type
                enumValues:
                  - thought
                  - text
                  - tool.start
                  - tool.result
                  - plan.update
                  - message.received
                  - task.completed
                  - task.aborted
                  - task.error
                  - sandbox.snapshot
                required: true
              - name: block_id
                type: string
                description: >-
                  Block this event relates to (e.g., "answer:main",
                  "tool:bash:run-1", "plan:root")
                required: false
              - name: message_id
                type: string
                description: Message ID this event belongs to
                required: false
              - name: payload
                type: object
                description: Event-specific data
                required: true
        headers: []
        jsonPayloadSchema: *ref_0
        title: Task Error
        description: Task failed with error
        example: |-
          {
            "event_id": 50,
            "timestamp": 1703001260000,
            "kind": "task.error",
            "message_id": "msg_ghi789",
            "payload": {
              "message": "Failed to execute code",
              "code": "execution_error"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: taskError
    bindings: []
    extensions: &ref_1
      - id: x-parser-unique-object-id
        value: session
  - &ref_3
    id: sendMessages
    title: Send messages
    description: Send messages to the session
    type: send
    messages:
      - &ref_15
        id: clientMessage
        contentType: application/json
        payload:
          - name: Send Message
            description: Send a message to the running task
            type: object
            properties:
              - name: type
                type: string
                description: MESSAGE
                required: true
              - name: content
                type: string
                description: Message content
                required: true
              - name: files
                type: array
                required: false
                properties:
                  - name: key
                    type: string
                    description: File path/key
                    required: false
                  - name: name
                    type: string
                    description: Display name
                    required: false
                  - name: type
                    type: string
                    description: MIME type
                    required: false
                  - name: size
                    type: integer
                    description: File size in bytes
                    required: false
              - name: references
                type: array
                required: false
                properties:
                  - name: url
                    type: string
                    required: false
                  - name: title
                    type: string
                    required: false
              - name: timestamp
                type: integer
                description: Unix timestamp (ms)
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - type
            - content
          properties:
            type:
              type: string
              const: MESSAGE
              x-parser-schema-id: <anonymous-schema-14>
            content:
              type: string
              description: Message content
              x-parser-schema-id: <anonymous-schema-15>
            files:
              type: array
              items:
                type: object
                properties:
                  key:
                    type: string
                    description: File path/key
                    x-parser-schema-id: <anonymous-schema-17>
                  name:
                    type: string
                    description: Display name
                    x-parser-schema-id: <anonymous-schema-18>
                  type:
                    type: string
                    description: MIME type
                    x-parser-schema-id: <anonymous-schema-19>
                  size:
                    type: integer
                    description: File size in bytes
                    x-parser-schema-id: <anonymous-schema-20>
                x-parser-schema-id: FileReference
              x-parser-schema-id: <anonymous-schema-16>
            references:
              type: array
              items:
                type: object
                properties:
                  url:
                    type: string
                    x-parser-schema-id: <anonymous-schema-23>
                  title:
                    type: string
                    x-parser-schema-id: <anonymous-schema-24>
                x-parser-schema-id: <anonymous-schema-22>
              x-parser-schema-id: <anonymous-schema-21>
            timestamp:
              type: integer
              description: Unix timestamp (ms)
              x-parser-schema-id: <anonymous-schema-25>
          x-parser-schema-id: <anonymous-schema-13>
        title: Send Message
        description: Send a message to the running task
        example: |-
          {
            "type": "MESSAGE",
            "content": "Also add error handling for network failures",
            "timestamp": 1703001270000
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: clientMessage
      - &ref_16
        id: clientStop
        contentType: application/json
        payload:
          - name: Stop Task
            description: Stop the running task
            type: object
            properties:
              - name: type
                type: string
                description: STOP
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - type
          properties:
            type:
              type: string
              const: STOP
              x-parser-schema-id: <anonymous-schema-27>
          x-parser-schema-id: <anonymous-schema-26>
        title: Stop Task
        description: Stop the running task
        example: |-
          {
            "type": "STOP"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: clientStop
    bindings: []
    extensions: *ref_1
sendOperations:
  - *ref_2
receiveOperations:
  - *ref_3
sendMessages:
  - *ref_4
  - *ref_5
  - *ref_6
  - *ref_7
  - *ref_8
  - *ref_9
  - *ref_10
  - *ref_11
  - *ref_12
  - *ref_13
  - *ref_14
receiveMessages:
  - *ref_15
  - *ref_16
extensions:
  - id: x-parser-unique-object-id
    value: session
securitySchemes: []

````