This document covers the webhook integration system in Langflow, which enables flows to be triggered via external HTTP POST requests. Webhooks provide a fire-and-forget execution pattern with optional real-time event streaming for UI feedback.
The webhook system consists of four primary components:
/api/v1/webhook/{flow_id_or_name}) - Accepts HTTP POST requests and triggers asynchronous flow execution src/backend/tests/unit/test_webhook.py20-31/api/v1/webhook-events/{flow_id_or_name}) - Streams real-time execution updates to connected UI clients. This endpoint requires proper authentication (API key or session cookie) src/backend/tests/unit/test_webhook_sse_regression.py1-22get_all_webhook_components_in_flow src/backend/base/langflow/services/database/models/flow/utils.py73WebhookEventManager) - Manages the delivery of tokens and build updates during execution src/backend/base/langflow/services/event_manager.py7The following diagram illustrates the interaction between the FastAPI router, the authentication service, and the background task execution.
Sources: src/backend/base/langflow/api/v1/chat.py114-115 src/backend/base/langflow/api/build.py19-28 src/backend/base/langflow/services/event_manager.py85 src/backend/tests/unit/test_webhook.py20-31
The main webhook endpoint is defined at /api/v1/webhook/{flow_id_or_name} and returns 202 ACCEPTED immediately without waiting for flow completion src/backend/tests/unit/test_webhook.py20-31
The flow_id_or_name parameter accepts either:
get_flow_by_id_or_endpoint_name src/backend/base/langflow/helpers/flow.py56Sources: src/backend/tests/unit/test_webhook.py20-42 src/backend/base/langflow/helpers/flow.py56
The sequence diagram below details the internal logic of the webhook execution and its delegation to background tasks.
The endpoint processes requests through the following steps:
get_flow_by_id_or_endpoint_name src/backend/base/langflow/helpers/flow.py56api_key_security src/backend/base/langflow/services/auth/utils.py61parse_input_request_from_body, which supports both application/json and multipart/form-data src/backend/base/langflow/api/v1/chat.py400-430start_flow_build to initiate the flow execution as a background job src/backend/base/langflow/api/v1/chat.py432 This function registers the job owner with the JobQueueService src/backend/base/langflow/api/v1/chat.py95-111202 ACCEPTED with status "in progress" src/backend/tests/unit/test_webhook.py28-30Sources: src/backend/base/langflow/api/v1/chat.py95-111 src/backend/base/langflow/api/v1/chat.py400-430 src/backend/base/langflow/api/v1/chat.py432 src/backend/base/langflow/services/auth/utils.py61 src/backend/tests/unit/test_webhook.py20-31 src/backend/base/langflow/helpers/flow.py56
Webhook authentication is controlled by the WEBHOOK_AUTH_ENABLE setting. This setting defaults to True for "secure-by-default" behavior src/backend/tests/unit/test_webhook.py168-171
| Mode | WEBHOOK_AUTH_ENABLE | Behavior |
|---|---|---|
| Owner Mode | false | Executes without requiring an API key src/backend/tests/unit/test_webhook.py145-164 |
| API Key Mode | true (Default) | Requires a valid API key; otherwise returns 403 Forbidden src/backend/tests/unit/test_webhook.py60-81 |
Sources: src/backend/tests/unit/test_webhook.py60-81 src/backend/tests/unit/test_webhook.py145-171
To enable real-time UI updates for background webhook tasks, the system provides an SSE endpoint at /api/v1/webhook-events/{flow_id}.
get_current_user_for_sse src/backend/base/langflow/services/auth/utils.py63emit_vertex_build_event to push updates to the webhook_event_manager src/lfx/src/lfx/graph/utils.py123-202build_start and end_vertex, providing duration, build results, outputs, and artifacts serialized via serialize_for_json src/lfx/src/lfx/graph/utils.py151-202Sources: src/lfx/src/lfx/graph/utils.py123-228 src/backend/base/langflow/services/auth/utils.py63
| Variable | Default | Description |
|---|---|---|
LANGFLOW_WEBHOOK_AUTH_ENABLE | true | Enable API key authentication for webhook endpoints src/backend/tests/unit/test_webhook.py168-171 |
SSE_HEARTBEAT_TIMEOUT_SECONDS | 10.0 | Interval (seconds) at which the streaming response's heartbeat refreshes the polling-watchdog activity key src/backend/base/langflow/api/build.py56 |
Sources: src/backend/tests/unit/test_webhook.py168-171 src/backend/base/langflow/api/build.py56
Refresh this wiki
This wiki was recently refreshed. Please wait 5 days to refresh again.