Overview
Shannon provides real-time event streaming through Server-Sent Events (SSE) and WebSocket protocols. Use streaming to monitor task execution, display progress, and receive results as they’re generated.Streaming Limits:
- Timeout: Streams automatically close after 5 minutes of inactivity
- Buffer Size: Maximum 1MB buffered data per connection
- Usage Metadata: Token counts and costs now available for all LLM providers (OpenAI, Anthropic, Google, Groq, xAI)
Endpoints
Unified Submit + Stream (Recommended)
POST /api/v1/tasks/stream
The easiest way to submit a task and immediately start streaming its events. This endpoint combines task submission with streaming setup in one call.Authentication
Required: YesRequest Body
Response
Status:201 Created
Body:
Response Fields
Example: JavaScript/TypeScript
Example: React Hook
Example: Vue 3 Composition API
Example: Python
Why use this endpoint? The unified endpoint ensures you start streaming immediately after submission, preventing any missed events that could occur if you submit and then connect separately.
Server-Sent Events (SSE)
GET /api/v1/stream/sse
Real-time event streaming using Server-Sent Events.Authentication
Required: YesQuery Parameters
Event Format
Each event follows SSE specification:Example Request
Example Response
WebSocket
GET /api/v1/stream/ws
Bidirectional streaming via WebSocket.Authentication
The gateway authenticates WebSocket connections via headers only (X-API-Key or Authorization). Browsers cannot set custom headers during the WebSocket handshake. For browser usage:
- Run locally with
GATEWAY_SKIP_AUTH=1, or - Use a reverse proxy that injects the header before forwarding to the gateway.
Passing the API key in the query string or via an “auth” message after connect is not supported by the gateway.
Message Types
Client → Server:OpenAI-Compatible Streaming
Shannon also provides an OpenAI-compatible streaming endpoint at/v1/chat/completions that translates Shannon events into the standard OpenAI chat.completion.chunk format. This allows you to use OpenAI SDKs directly with Shannon.
For complete documentation on the OpenAI-compatible API, including request/response schemas, available models, Shannon-specific extensions (shannon_events), and SDK usage examples, see the OpenAI-Compatible API Reference.
Event Types
Core Events
Agent Events
Tool Events
LLM Events
Progress & System Events
Stream Lifecycle Events
Over SSE, the
STREAM_END lifecycle event is delivered as an SSE event named done with data: [DONE] (plain text, not JSON). Over WebSocket, it appears as a normal JSON event with "type": "STREAM_END".Team & Approvals
Code Examples
Python with httpx (SSE)
Python - Stream with Event Filtering
JavaScript/Node.js (SSE)
JavaScript/Node.js - WebSocket (ws)
Go (SSE)
Bash/curl (SSE)
Use Cases
1. Real-Time Progress Display
2. Log All Events to File
3. Collect Tool Usage Metrics
4. React UI Integration
Deep Research Streaming
Deep Research tasks take 2-10 minutes. Usecontext.force_research to trigger Deep Research through the Task API:
context.research_strategy:
Heartbeat
The server sends a: ping SSE comment every 10 seconds to keep connections alive through proxies and load balancers:
Reconnection
SSE connections may drop due to network issues, proxy timeouts, or platform limits (e.g., Vercel hobby plan: 5-minute connection limit). Shannon supports resuming from where you left off. How it works:- Track the
idfield of each received SSE event - When disconnected, reconnect with
last_event_idparameter - The server replays all events after that ID (buffered ~256 events, 24h TTL)
Proactive Reconnection (Recommended)
For platforms with connection time limits, proactively disconnect before the limit:Page Refresh / Fallback
If the user refreshes the page and you still have theworkflow_id:
- Check task status:
GET /api/v1/tasks/{workflow_id} - If
TASK_STATUS_RUNNING→ reconnect to SSE - If
TASK_STATUS_COMPLETED→ display the result from the response - If
TASK_STATUS_FAILED→ display the error
Python with Reconnection
Best Practices
2. Implement Timeout
3. Filter Events Client-Side
4. Resume from Last Event
last_event_id accepts either a Redis stream ID (e.g., 1700000000000-0) or a numeric sequence (e.g., 42). When numeric, replay includes events with seq > last_event_id.
Comparison: SSE vs WebSocket vs Polling
When to Use Each
- SSE: Most use cases, real-time monitoring, progress display
- WebSocket: Interactive applications, bidirectional communication needed
- Polling (GET /api/v1/tasks/): Legacy systems, no streaming support
Related Endpoints
Submit Task
POST /api/v1/tasks
Get Status
GET /api/v1/tasks/
Python SDK
Use client.stream()