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

# Stream Events

> Stream events for a task by its unique ID using Server-Sent Events (SSE).

    Supports automatic reconnection with Last-Event-ID header. When the client
    reconnects, it sends the Last-Event-ID header with the last received event ID,
    and the server resumes from that point.

    Returns TextStreamPart events (Vercel AI SDK compatible format).

**SSE Behavior:**

* Supports automatic reconnection with `Last-Event-ID` header
* When the client reconnects, the server resumes from the last received event
* Stream terminates with `[DONE]` message

## Stream Event Types

The stream returns `TextStreamPartWrapper` events with a discriminated `type` field. These events are compatible with the Vercel AI SDK format.

| Event Type         | Description                                       |
| ------------------ | ------------------------------------------------- |
| `start`            | Marks the beginning of the streaming session      |
| `start-step`       | Marks the beginning of an agentic step            |
| `text-start`       | Marks the beginning of a text block               |
| `text-delta`       | Incremental text content                          |
| `text-end`         | Marks the end of a text block                     |
| `reasoning-start`  | Marks the beginning of reasoning/thinking content |
| `reasoning-delta`  | Incremental reasoning content                     |
| `reasoning-end`    | Marks the end of reasoning content                |
| `tool-input-start` | Marks the beginning of tool input streaming       |
| `tool-input-delta` | Incremental tool input (JSON streaming)           |
| `tool-input-end`   | Marks the end of tool input                       |
| `tool-call`        | Complete tool call with parsed input              |
| `tool-result`      | Tool execution result                             |
| `finish-step`      | Marks the end of an agentic step                  |
| `finish`           | Marks the end of the streaming session            |
| `error`            | Error during streaming                            |

### text-delta

Incremental text content from the agent.

```typescript theme={"dark"}
interface TextDeltaPart {
  type: 'text-delta';
  id: string;          // Text block ID
  text: string;        // Text delta content
  metadata?: {
    parentToolUseId?: string;  // For subagent context
  };
}
```

### tool-call

Complete tool call with parsed input arguments.

```typescript theme={"dark"}
interface ToolCallPart {
  type: 'tool-call';
  toolCallId: string;              // Unique tool call ID
  toolName: string;                // Name of the tool
  input: Record<string, unknown>;  // Parsed input arguments
  metadata?: {
    parentToolUseId?: string;
  };
}
```

### tool-result

Tool execution result.

```typescript theme={"dark"}
interface ToolResultPart {
  type: 'tool-result';
  toolCallId: string;   // Tool call ID
  toolName: string;     // Name of the tool
  output?: unknown;     // Tool output
  metadata?: {
    parentToolUseId?: string;
  };
}
```

### finish

Marks the end of the streaming session.

```typescript theme={"dark"}
interface FinishPart {
  type: 'finish';
  finishReason: 'stop' | 'tool-calls' | 'length' | 'content-filter' | 'error' | 'other';
  totalUsage: {
    inputTokens: number;
    outputTokens: number;
    totalTokens?: number;
  };
  metadata?: {
    cost?: number;
    durationMs?: number;
  };
}
```

### error

Error during streaming.

```typescript theme={"dark"}
interface StreamErrorPart {
  type: 'error';
  error: string;         // Error message
  rawContent?: unknown;  // Original content that caused the error
}
```

<Note>
  These event types are designed to be compatible with the [Vercel AI SDK](https://sdk.vercel.ai/docs) streaming format, making it easy to integrate with AI SDK-based applications.
</Note>


## OpenAPI

````yaml openapi.json GET /tasks/{task_id}/stream
openapi: 3.1.0
info:
  title: Sb0 API
  version: 0.1.0
servers: []
security: []
paths:
  /tasks/{task_id}/stream:
    get:
      tags:
        - Tasks
      summary: Stream Task Events by ID
      description: >-
        Stream events for a task by its unique ID using Server-Sent Events
        (SSE).

            Supports automatic reconnection with Last-Event-ID header. When the client
            reconnects, it sends the Last-Event-ID header with the last received event ID,
            and the server resumes from that point.

            Returns TextStreamPart events (Vercel AI SDK compatible format).
      operationId: tasks_stream
      parameters:
        - in: path
          name: task_id
          required: true
          schema:
            title: Task Id
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TextStreamPartWrapper'
          description: SSE stream of TextStreamPart events
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: Validation Error
components:
  schemas:
    TextStreamPartWrapper:
      description: Wrapper for TextStreamPart union for proper serialization.
      discriminator:
        mapping:
          error:
            $ref: '#/components/schemas/StreamErrorPart'
          finish:
            $ref: '#/components/schemas/FinishPart'
          finish-step:
            $ref: '#/components/schemas/FinishStepPart'
          handler-complete:
            $ref: '#/components/schemas/HandlerCompletePart'
          reasoning-delta:
            $ref: '#/components/schemas/ReasoningDeltaPart'
          reasoning-end:
            $ref: '#/components/schemas/ReasoningEndPart'
          reasoning-start:
            $ref: '#/components/schemas/ReasoningStartPart'
          start:
            $ref: '#/components/schemas/StartPart'
          start-step:
            $ref: '#/components/schemas/StartStepPart'
          text-delta:
            $ref: '#/components/schemas/TextDeltaPart'
          text-end:
            $ref: '#/components/schemas/TextEndPart'
          text-start:
            $ref: '#/components/schemas/TextStartPart'
          tool-call:
            $ref: '#/components/schemas/ToolCallPart'
          tool-input-delta:
            $ref: '#/components/schemas/ToolInputDeltaPart'
          tool-input-end:
            $ref: '#/components/schemas/ToolInputEndPart'
          tool-input-start:
            $ref: '#/components/schemas/ToolInputStartPart'
          tool-result:
            $ref: '#/components/schemas/ToolResultPart'
        propertyName: type
      oneOf:
        - $ref: '#/components/schemas/StartPart'
        - $ref: '#/components/schemas/StartStepPart'
        - $ref: '#/components/schemas/FinishStepPart'
        - $ref: '#/components/schemas/FinishPart'
        - $ref: '#/components/schemas/HandlerCompletePart'
        - $ref: '#/components/schemas/TextStartPart'
        - $ref: '#/components/schemas/TextDeltaPart'
        - $ref: '#/components/schemas/TextEndPart'
        - $ref: '#/components/schemas/ReasoningStartPart'
        - $ref: '#/components/schemas/ReasoningDeltaPart'
        - $ref: '#/components/schemas/ReasoningEndPart'
        - $ref: '#/components/schemas/ToolInputStartPart'
        - $ref: '#/components/schemas/ToolInputDeltaPart'
        - $ref: '#/components/schemas/ToolInputEndPart'
        - $ref: '#/components/schemas/ToolCallPart'
        - $ref: '#/components/schemas/ToolResultPart'
        - $ref: '#/components/schemas/StreamErrorPart'
      title: TextStreamPartWrapper
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: Detail
          type: array
      title: HTTPValidationError
      type: object
    StreamErrorPart:
      description: Error during streaming.
      properties:
        error:
          description: Error message
          title: Error
          type: string
        rawContent:
          anyOf:
            - {}
            - type: 'null'
          description: Original content that caused the error
          title: Rawcontent
        type:
          const: error
          default: error
          title: Type
          type: string
      required:
        - error
      title: StreamErrorPart
      type: object
    FinishPart:
      description: Marks the end of the entire streaming session.
      properties:
        finishReason:
          $ref: '#/components/schemas/FinishReason'
          description: Reason session finished
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Extended metadata including cost and duration
        totalUsage:
          $ref: '#/components/schemas/StreamUsage'
          description: Total token usage
        type:
          const: finish
          default: finish
          title: Type
          type: string
      required:
        - finishReason
        - totalUsage
      title: FinishPart
      type: object
    FinishStepPart:
      description: Marks the end of a step (API call).
      properties:
        finishReason:
          $ref: '#/components/schemas/FinishReason'
          description: Reason step finished
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        type:
          const: finish-step
          default: finish-step
          title: Type
          type: string
        usage:
          $ref: '#/components/schemas/StreamUsage'
          description: Token usage for this step
      required:
        - finishReason
        - usage
      title: FinishStepPart
      type: object
    HandlerCompletePart:
      description: Marks completion of event/send handler lifecycle for a specific event.
      properties:
        durationMs:
          anyOf:
            - type: integer
            - type: 'null'
          description: Handler runtime in milliseconds
          title: Durationms
        error:
          anyOf:
            - type: string
            - type: 'null'
          description: Handler error text when execution failed
          title: Error
        eventId:
          description: Event ID correlated to this handler completion
          title: Eventid
          type: string
        success:
          description: Whether handler execution succeeded
          title: Success
          type: boolean
        taskId:
          description: Task ID whose handler lifecycle completed
          title: Taskid
          type: string
        type:
          const: handler-complete
          default: handler-complete
          title: Type
          type: string
      required:
        - eventId
        - taskId
        - success
      title: HandlerCompletePart
      type: object
    ReasoningDeltaPart:
      description: Incremental reasoning content.
      properties:
        id:
          description: ID of the reasoning block this belongs to
          title: Id
          type: string
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        text:
          description: Reasoning delta content
          title: Text
          type: string
        type:
          const: reasoning-delta
          default: reasoning-delta
          title: Type
          type: string
      required:
        - id
        - text
      title: ReasoningDeltaPart
      type: object
    ReasoningEndPart:
      description: Marks the end of a reasoning block.
      properties:
        id:
          description: ID of the completed reasoning block
          title: Id
          type: string
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        type:
          const: reasoning-end
          default: reasoning-end
          title: Type
          type: string
      required:
        - id
      title: ReasoningEndPart
      type: object
    ReasoningStartPart:
      description: Marks the start of a reasoning block.
      properties:
        id:
          description: Unique ID for this reasoning block
          title: Id
          type: string
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        type:
          const: reasoning-start
          default: reasoning-start
          title: Type
          type: string
      required:
        - id
      title: ReasoningStartPart
      type: object
    StartPart:
      description: Marks the start of a streaming session.
      properties:
        type:
          const: start
          default: start
          title: Type
          type: string
      title: StartPart
      type: object
    StartStepPart:
      description: Marks the start of a new step (API call).
      properties:
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        request:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          description: Request details for this step
          title: Request
        type:
          const: start-step
          default: start-step
          title: Type
          type: string
        warnings:
          anyOf:
            - items: {}
              type: array
            - type: 'null'
          description: Warnings from this step
          title: Warnings
      title: StartStepPart
      type: object
    TextDeltaPart:
      description: Incremental text content.
      properties:
        id:
          description: ID of the text block this belongs to
          title: Id
          type: string
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        text:
          description: Text delta content
          title: Text
          type: string
        type:
          const: text-delta
          default: text-delta
          title: Type
          type: string
      required:
        - id
        - text
      title: TextDeltaPart
      type: object
    TextEndPart:
      description: Marks the end of a text block.
      properties:
        id:
          description: ID of the completed text block
          title: Id
          type: string
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        type:
          const: text-end
          default: text-end
          title: Type
          type: string
      required:
        - id
      title: TextEndPart
      type: object
    TextStartPart:
      description: Marks the start of a text block.
      properties:
        id:
          description: Unique ID for this text block
          title: Id
          type: string
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        type:
          const: text-start
          default: text-start
          title: Type
          type: string
      required:
        - id
      title: TextStartPart
      type: object
    ToolCallPart:
      description: Complete tool call with parsed input.
      properties:
        input:
          additionalProperties: true
          description: Parsed input arguments
          title: Input
          type: object
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        toolCallId:
          description: Unique tool call ID
          title: Toolcallid
          type: string
        toolName:
          description: Name of the tool
          title: Toolname
          type: string
        type:
          const: tool-call
          default: tool-call
          title: Type
          type: string
      required:
        - toolCallId
        - toolName
        - input
      title: ToolCallPart
      type: object
    ToolInputDeltaPart:
      description: Incremental tool input JSON.
      properties:
        delta:
          description: Partial JSON input
          title: Delta
          type: string
        id:
          description: Tool call ID
          title: Id
          type: string
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        type:
          const: tool-input-delta
          default: tool-input-delta
          title: Type
          type: string
      required:
        - id
        - delta
      title: ToolInputDeltaPart
      type: object
    ToolInputEndPart:
      description: Marks the end of tool input streaming.
      properties:
        id:
          description: Tool call ID
          title: Id
          type: string
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        type:
          const: tool-input-end
          default: tool-input-end
          title: Type
          type: string
      required:
        - id
      title: ToolInputEndPart
      type: object
    ToolInputStartPart:
      description: Marks the start of tool input streaming.
      properties:
        id:
          description: Tool call ID (e.g., toolu_01XYZ)
          title: Id
          type: string
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        toolName:
          description: Name of the tool
          title: Toolname
          type: string
        type:
          const: tool-input-start
          default: tool-input-start
          title: Type
          type: string
      required:
        - id
        - toolName
      title: ToolInputStartPart
      type: object
    ToolResultPart:
      description: Tool execution result.
      properties:
        metadata:
          anyOf:
            - $ref: '#/components/schemas/StreamMetadata'
            - type: 'null'
          description: Metadata including parentToolUseId for subagents
        output:
          description: Tool output
          title: Output
        toolCallId:
          description: Tool call ID
          title: Toolcallid
          type: string
        toolName:
          description: Name of the tool
          title: Toolname
          type: string
        type:
          const: tool-result
          default: tool-result
          title: Type
          type: string
      required:
        - toolCallId
        - toolName
        - output
      title: ToolResultPart
      type: object
    ValidationError:
      properties:
        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
    FinishReason:
      description: Reason for stream completion.
      enum:
        - stop
        - tool-calls
        - length
        - content-filter
        - error
        - other
      title: FinishReason
      type: string
    StreamMetadata:
      description: Extended metadata for finish events.
      properties:
        cacheCreationInputTokens:
          anyOf:
            - type: integer
            - type: 'null'
          description: Cache creation input tokens
          title: Cachecreationinputtokens
        cacheReadInputTokens:
          anyOf:
            - type: integer
            - type: 'null'
          description: Cache read input tokens
          title: Cachereadinputtokens
        costUsd:
          anyOf:
            - type: number
            - type: 'null'
          description: Total cost in USD
          title: Costusd
        durationMs:
          anyOf:
            - type: integer
            - type: 'null'
          description: Total duration in milliseconds
          title: Durationms
        parentToolUseId:
          anyOf:
            - type: string
            - type: 'null'
          description: Parent tool use ID for subagent context
          title: Parenttooluseid
      title: StreamMetadata
      type: object
    StreamUsage:
      description: Token usage for streaming events.
      properties:
        inputTokens:
          description: Input tokens used
          title: Inputtokens
          type: integer
        outputTokens:
          description: Output tokens used
          title: Outputtokens
          type: integer
        totalTokens:
          anyOf:
            - type: integer
            - type: 'null'
          description: Total tokens
          title: Totaltokens
      required:
        - inputTokens
        - outputTokens
      title: StreamUsage
      type: object

````