Real-time updates via Server-Sent Events (SSE).
Stream Task Updates
GET /tasks/:id/stream
Stream task status updates in real-time.
Headers
code
1Accept: text/event-streamEvent Format
code
1event: update2data: {"id":"task_abc","status":7,"logs":"Processing..."}3 4event: update5data: {"id":"task_abc","status":9,"output":{...}}6 7event: done8data: {}Event Types
| Event | Description |
|---|---|
update | Task state changed |
done | Stream complete |
error | Error occurred |
cURL Example
bash
1curl -N https://api.inference.sh/tasks/task_abc123/stream \2 -H "Authorization: Bearer inf_your_key" \3 -H "Accept: text/event-stream"Stream Chat Messages
GET /chats/:id/messages/stream
Stream agent response in real-time.
Event Format
code
1event: content2data: {"text":"Hello"}3 4event: content5data: {"text":", how"}6 7event: tool_call8data: {"id":"tc_123","name":"search","arguments":{...}}9 10event: done11data: {}Event Types
| Event | Description |
|---|---|
content | Text chunk |
tool_call | Tool invocation |
tool_result | Tool result |
done | Response complete |
error | Error occurred |
Connection Parameters
| Query Param | Description |
|---|---|
last_event_id | Resume from event ID |
Handling Reconnection
SSE supports automatic reconnection. Use the Last-Event-ID header:
bash
1curl -N https://api.inference.sh/tasks/task_abc123/stream \2 -H "Authorization: Bearer inf_your_key" \3 -H "Accept: text/event-stream" \4 -H "Last-Event-ID: evt_xyz"JavaScript Example
javascript
1const eventSource = new EventSource(2 'https://api.inference.sh/tasks/task_abc123/stream',3 {4 headers: {5 'Authorization': 'Bearer inf_your_key'6 }7 }8);9 10eventSource.addEventListener('update', (event) => {11 const data = JSON.parse(event.data);12 console.log('Status:', data.status);13});14 15eventSource.addEventListener('done', () => {16 eventSource.close();17});