Skip to main content
Documentation

SSE Events

Subscribe to real-time events via Server-Sent Events (SSE) to get instant notifications when tasks and processes change.

Connecting

const eventSource = new EventSource('/api/tasks/stream', {
	headers: { Authorization: 'Bearer htk_...' }
});

eventSource.addEventListener('task_created', (e) => {
	const task = JSON.parse(e.data);
	console.log('New task:', task.title);
});

eventSource.addEventListener('task_completed', (e) => {
	const task = JSON.parse(e.data);
	console.log('Task completed:', task.task_id, task.data);
});

Event Types

connected

Sent immediately after connecting. Confirms the stream is active.

{ "type": "connected" }

task_created

A new task was created in your organization.

{
	"type": "task_created",
	"task": {
		"task_id": "uuid",
		"title": "Review document",
		"status": "pending",
		"created_at": "2026-02-24T12:00:00Z"
	}
}

task_completed

An operator completed a task.

{
	"type": "task_completed",
	"task": {
		"task_id": "uuid",
		"status": "completed",
		"data": { "decision": "Approve" },
		"completed_at": "2026-02-24T12:05:00Z"
	}
}

task_cancelled

A task was cancelled.

{
	"type": "task_cancelled",
	"task": {
		"task_id": "uuid",
		"status": "cancelled",
		"cancel_reason": "No longer needed"
	}
}

task_failed

A task failed.

{
	"type": "task_failed",
	"task": {
		"task_id": "uuid",
		"status": "failed",
		"fail_reason": "System error"
	}
}

process_update

A process state changed (step started, completed, progress update, etc.).

{
	"type": "process_update",
	"process": {
		"process_id": "uuid",
		"status": "running",
		"current_step": "deploy"
	}
}

Keepalive

The server sends a ping every 10 seconds to keep the connection alive.

Reconnection

If the connection drops, EventSource automatically reconnects. Events that occurred during the disconnection are not replayed — use the REST API to catch up on missed events.

Organization Filtering

Events are automatically filtered to your organization based on the authentication token. You only receive events for tasks and processes belonging to your org.