API reference
Stream a task
GET /api/pub/v1/tasks/{taskId}/stream, receive completed replies as server-sent events instead of polling.
GET
https://api.dhanu.ai/api/pub/v1/tasks/{taskId}/streamA 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 parameter | Type | Required | Notes |
|---|---|---|---|
taskId | string | Yes |
| Parameter | Type | Required | Notes |
|---|---|---|---|
cursor | string | No | Only 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
| Code | Status | Meaning |
|---|---|---|
invalid_api_key | 401 | The bearer key is missing or unknown. |
api_key_revoked | 401 | The key was revoked. |
api_key_expired | 401 | The key passed its expiry date. |
api_key_ip_not_allowed | 403 | The caller's IP is outside the key's allowlist. |
developer_access_revoked | 403 | The key's creator lost developer access in the workspace. |
api_key_project_scope | 403 | The key covers no active projects, or projectId is outside its scope. |
not_found | 404 | No such resource in the key's workspace. |
invalid_cursor | 422 | The cursor was not one this endpoint issued. |