Streaming API

    ExecutionStreamController reference for real-time SSE streaming.

    Creating a Stream

    typescript
    const stream = await client.agents.stream('agent-uuid', {
      task: 'Generate a report',
    });
    
    // Or from an existing execution
    const stream2 = client.agents.createStream(executionId, sessionId);

    Events

    EventPayloadDescription
    textDelta{ delta: string }Incremental text chunk
    toolCall{ name, input, toolCallId }Tool invocation started
    toolResult{ toolCallId, output }Tool returned a result
    started{ executionId }Execution began
    progress{ percent, message }Progress update
    statusUpdate{ status, message }Status change
    log{ level, message }Debug/info log entry
    delegationStarted{ delegationId, agentName }Team delegation began
    delegationCompleted{ delegationId, result }Team delegation finished
    executionPaused{ prompt, options }Waiting for user input
    complete{ execution }Execution finished
    errorCadraErrorError occurred

    Methods

    typescript
    // Connect and start receiving events
    await stream.connect();
    
    // Cancel the execution
    await stream.cancel();
    
    // Disconnect without cancelling
    stream.disconnect();
    
    // Check connection state
    stream.connected; // boolean

    Reconnection

    The stream automatically reconnects on network failures with exponential backoff. Events are deduplicated via sequence IDs.

    typescript
    const stream = await client.agents.stream('agent-uuid', {
      task: 'Long running task',
    }, {
      // StreamConfig options
      maxRetries: 5,
      retryDelay: 1000,
      maxRetryDelay: 30000,
    });

    SSE Wire Protocol

    text
    GET /api/v1/executions/{id}/stream?sessionId={sid}
    Accept: text/event-stream
    Authorization: ApiKey sk-cad-xxxxxxxx
    
    event: textDelta
    data: {"delta":"Hello","seq":1}
    
    event: toolCall
    data: {"name":"search","input":{"q":"AI"},"toolCallId":"tc_1","seq":2}
    
    event: complete
    data: {"execution":{...},"seq":99}