Skip to main content

Stream API

Stream API

Path

POST /workflows/<TASK_NAME>/stream

Request Body

{
"params" : {} // your task command
}

Response Body

Stream API returns the response in text/event-stream, using the following structure

data: {"type" : "", ....}
data: {"type" : "", ....}
data: {"type" : "", ....}

Custom Events

Events emitted by the tasks start with event. prefix

{
"type" : "event.<example-action>",
"someField" : "someValue"
}

task.completed

Fired when the task is completed successfully.

{
"type" : "task.completed",
"result" : {}, // task result, can be null if the task did not return final result
"usage": { // Details of the used credits, if any
"credits": 10
}
}

task.failed

Fired when the task is failed.

{
"type" : "task.failed",
"result" : {
"status" : "error",
"statusCode" : 500,
"reason" : "<err_reason>",
"message" : "<Err message>"
}
}

task.progress

Fired on progress metrics update

{
"type" : "task.progress",
"percent" : 64,
"estimatedSecondsLeft" : 110
}

task.partial-result

Fired when a partial task result is emitted

{
"type" : "task.partial-result",
"result" : {}
}

cURL Example

curl --location '{BASE_URL}/workflows/<TASK_NAME>/stream' \
--header 'Authorization: Bearer <USER_TOKEN>' \
--header 'x-app-authorization: Bearer <CLIENT_TOKEN>' \
--header 'platform: website' \
--header 'x-touchpoint: <touchpoint>' \
--data '{
"params": {},
}'