Skip to main content
The Swarms API supports real-time streaming responses, allowing you to receive agent outputs as they’re generated. This provides immediate feedback and a better user experience for long-running tasks.
Streaming is enabled by setting "streaming_on": true in your agent configuration.

Quick Start

Enable streaming by adding the streaming_on parameter to your agent configuration:

Stream Format

The API uses Server-Sent Events (SSE) format. Each frame is a data: line, optionally preceded by an event: line naming the event type. The very first frame (job metadata) is sent without an event: line β€” identify it by "type": "metadata" inside the payload:
On failure, a single error event is sent instead of usage/end/done:

Parsing Streams

Here’s how to parse streaming responses in different languages:

Complete Examples

Event Types

Best Practices

Error Handling

Always handle potential errors in your stream processing:

Timeout Management

Set appropriate timeouts for your use case:

Benefits

  • Real-time Feedback: See results as they’re generated
  • Better UX: Reduced perceived latency
  • Progress Tracking: Monitor long-running operations
  • Error Handling: Immediate error feedback

Troubleshooting

Increase timeout values for long-running tasks. Set appropriate timeouts based on your expected response time.
Handle malformed data gracefully by wrapping JSON parsing in try-catch blocks.
Always check for done or error events to ensure the stream completed successfully.
Process chunks incrementally for large responses to avoid memory issues.

Debug Mode

Enable debug logging to troubleshoot stream issues: