langflow/docs/docs/guidelines/async-api.mdx
Gabriel Luiz Freitas Almeida 84bf3c83e3 📝 docs(guidelines): add async-api.mdx to provide documentation on asynchronous processing feature
📝 docs(guides): add async-tasks.mdx to provide a guide on using the Async API implementation

📝 docs(sidebars.js): update sidebar to include async-api.mdx and async-tasks.mdx in the appropriate sections
2023-09-26 17:18:13 -03:00

57 lines
1.8 KiB
Text

import Admonition from "@theme/Admonition";
# 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.
<Admonition type="warning" caption="Experimental Feature">
This is an experimental feature. The default behavior of the API is still
synchronous processing. The API may change in the future.
</Admonition>
## 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
```bash
curl -X POST \
http://localhost:3000/api/v1/process/<your_flow_id> \
-H 'Content-Type: application/json' \
-H 'x-api-key: <your_api_key>' \
-d '{"inputs": {"text": ""}, "tweaks": {}, "sync": false}'
```
## Checking Task Status
You can check the status of an asynchronous task by making a GET request to the `/task/{task_id}/status` endpoint.
```bash
curl -X GET \
http://localhost:3000/api/v1/task/<task_id>/status \
-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:
```json
{
"status": "SUCCESS",
"result": {
"output": "..."
}
}
```