Asynchronous Processing
Introduction
Starting from version 0.5, Langflow introduces a new feature to its API: the sync
flag. This flag allows users to opt for asynchronous processing of their flows, freeing up resources and enabling better control over long-running tasks.
This feature supports running tasks in a Celery worker queue and AnyIO task groups for now.
This is an experimental feature. The default behavior of the API is still synchronous processing. The API may change in the future.
The sync
Flag
The sync
flag can be included in the payload of your POST request to the /api/v1/process/<your_flow_id>
endpoint.
When set to false
, the API will initiate an asynchronous task instead of processing the flow synchronously.
API Request with sync
flag
_10curl -X POST \_10 http://localhost:3000/api/v1/process/<your_flow_id> \_10 -H 'Content-Type: application/json' \_10 -H 'x-api-key: <your_api_key>' \_10 -d '{"inputs": {"text": ""}, "tweaks": {}, "sync": false}'
Response:
_11{_11 "result": {_11 "output": "..."_11 },_11 "task": {_11 "id": "...",_11 "href": "api/v1/task/<task_id>"_11 },_11 "session_id": "...",_11 "backend": "..." // celery or anyio_11}
Checking Task Status
You can check the status of an asynchronous task by making a GET request to the /task/{task_id}
endpoint.
_10curl -X GET \_10 http://localhost:3000/api/v1/task/<task_id> \_10 -H 'x-api-key: <your_api_key>'
Response
The endpoint will return the current status of the task and, if completed, the result of the task. Possible statuses include:
PENDING
: The task is waiting for execution.SUCCESS
: The task has completed successfully.FAILURE
: The task has failed.
Example response for a completed task:
_10{_10 "status": "SUCCESS",_10 "result": {_10 "output": "..."_10 }_10}