Skip to main content

POST /v1/agents/{agent_id}/stream

Stream agent responses using Server-Sent Events (SSE) for real-time output.

Request

Path Parameters

agent_id
string
required
The unique identifier of the agent

Request Body

Same as the invoke endpoint:
query
string
required
The input query for the agent
parameters
object
Additional parameters
session_id
string
Session ID for context

Response Format

Server-Sent Events stream with the following event types:

Event Types

start

Sent when streaming begins

chunk

Content chunks as they’re generated

error

Error during streaming

done

Stream completion with metadata

Examples

JavaScript (Browser)

Python

Node.js

Handling Stream Interruptions

Client-Side Reconnection

Resume from Position

Stream Control

Abort Stream

Close the connection to stop streaming:

Rate Control

Control streaming speed with parameters:

Error Handling

Network Errors

Stream Errors

Best Practices

  1. Implement Reconnection Logic for network interruptions
  2. Handle Partial Responses gracefully
  3. Set Appropriate Timeouts for long-running streams
  4. Monitor Memory Usage when buffering responses
  5. Provide User Feedback during streaming

Performance Tips

  • Use compression when available
  • Process chunks as they arrive
  • Implement backpressure handling
  • Consider chunking large responses

See Also