Docs Sign in Get a key

Docs / Guides

Live updates

Follow a Hapti task step by step as it happens with Server-Sent Events, or every task of your organisation at once.

Hapti streams what happens with Server-Sent Events. It is the fastest way to show progress in your app, and the libraries use it to return as soon as a task ends.

Follow one task

JavaScript
for await (const e of hapti.tasks.stream('tsk_...')) {
  if (e.event === 'step') console.log(e.data.summary);
  if (e.event === 'task') console.log('status', e.data.status);
}
EventDataWhen
taskThe full taskFirst, then each time its status, question, result or price changes
stepOne action of the agent, with a summaryEach time the agent acts
screenshotn and the url of the imageEach time a screenshot is saved
doneid and final statusOnce, at the end. The stream then closes
reconnectreasonAfter 30 minutes: connect again

Each step carries an id. If the connection drops, connect again with the header Last-Event-ID set to the last id you received, and the stream resumes right after it, without gaps or repeats. The libraries do this for you.

A comment line : ping is sent every 15 seconds so proxies keep the connection open.

Wait for the end with the libraries

tasks.wait and tasks.run follow the stream and return the moment the task is over. They fall back to asking for the task at intervals when a stream cannot be opened.

JavaScript
const task = await hapti.tasks.run(
  { url: 'https://portal.example.com', goal: 'Download my last statement.' },
  { onStep: (s) => progress(s.summary) },
);

Follow every task

GET /v1/stream sends a task event each time any task of the key mode changes state. Use it to keep a dashboard up to date.

Terminal
curl -N https://api.hapti.dev/v1/stream -H "Authorization: Bearer $HAPTI_KEY"