Skip to content
dhanu docs
Browse pages

API reference

Stream a task

GET /api/pub/v1/tasks/{taskId}/stream, receive completed replies as server-sent events instead of polling.

GEThttps://api.dhanu.ai/api/pub/v1/tasks/{taskId}/stream

A text/event-stream that emits one message event per completed assistant reply arriving after cursor (or after now when omitted), then done when the connection closes. The connection is held for up to 60 seconds; reconnect with the last event’s id as the next cursor. The SDKs do the reconnecting for you.

Request

Path parameterTypeRequiredNotes
taskIdstringYes
ParameterTypeRequiredNotes
cursorstringNoOnly messages after this cursor; omit to start from now.
curl -N "https://api.dhanu.ai/api/pub/v1/tasks/$TASK_ID/stream" \
  -H "Authorization: Bearer $DHANU_API_KEY"
for await (const reply of dhanu.tasks.stream(taskId)) {
  console.log(reply.text);
}
for reply in dhanu.tasks.stream(task_id):
    print(reply.text)

Events

event: message
id: <cursor>
data: {"id":"…","role":"assistant","text":"…","createdAt":"…"}

event: done
data: {}

Errors

CodeStatusMeaning
invalid_api_key401The bearer key is missing or unknown.
api_key_revoked401The key was revoked.
api_key_expired401The key passed its expiry date.
api_key_ip_not_allowed403The caller's IP is outside the key's allowlist.
developer_access_revoked403The key's creator lost developer access in the workspace.
api_key_project_scope403The key covers no active projects, or projectId is outside its scope.
not_found404No such resource in the key's workspace.
invalid_cursor422The cursor was not one this endpoint issued.