This page documents the Workflow Execution API accessible via the POST /workflows/run endpoint. This API enables programmatic invocation of Workflow applications in Dify, designed as stateless, single-run graphs typically used for processing, content generation, or transformation tasks.
We detail request formats, input variable handling including multi-modal files, streaming event generation, and execution tracing for observability and debugging.
POST/workflows/runWorkflowApi class in api/controllers/service_api/app/workflow.py157-180trace_session_id for observability.Sources: api/controllers/service_api/app/workflow.py70-82 api/controllers/service_api/app/workflow.py157-180
The request accepts a JSON payload modeled by WorkflowRunPayload comprising:
| Parameter | Type | Description |
|---|---|---|
inputs | dict | Key-value pairs defining variable inputs to the workflow |
response_mode | string enum | "blocking" or "streaming", controls response streaming mode |
user | string | User identifier (e.g., end user ID) |
files | list of dicts | Optional global file input array, for multi-modal support |
trace_session_id | string or null | Optional external trace session id for observability |
These inputs flow into the AppGenerateService which launches the workflow execution using WorkflowAppGenerateTaskPipeline.
inputs against the workflow's variable schema.files argument is used for multi-modal inputs such as documents or images, each file object requires:
type: one of document, image, audio, video, or custom.transfer_method: either remote_url or local_file.remote_url: url field is mandatory.local_file: upload_file_id referencing a previously uploaded file.This file input validation is implemented in service API completion request validation api/controllers/service_api/app/completion.py75-82 and workflow runtime initialization api/core/workflow/workflow_entry.py163-178
Sources: api/controllers/service_api/app/workflow.py70-82 api/core/app/apps/workflow/generate_task_pipeline.py77-131 api/services/app_generate_service.py48-60
workflow_run_id, execution status, and output variables as a dictionary.WorkflowRun model data.workflow_started, node_started, node_finished, and workflow_finished.AppQueueManager for event dispatching internally.Sources: api/controllers/service_api/app/workflow.py40 api/controllers/service_api/app/workflow.py70-82 api/core/app/apps/workflow/generate_task_pipeline.py77-131
| Event Name | Description | Typical Fields / Data | Code Entity References |
|---|---|---|---|
workflow_started | Workflow execution initiated | workflow_run_id, workflow_id, inputs, created_at | WorkflowRun (models/workflow.py), QueueWorkflowStartedEvent |
node_started | A workflow node starts execution | node_id, node_type, inputs | GraphNodeEventBase, QueueNodeStartedEvent |
node_finished | Node execution completed | outputs, elapsed_time, status | QueueNodeSucceededEvent |
workflow_paused | Workflow pauses (e.g., for user input) | Cleared outputs, paused nodes, pause reasons | WorkflowPauseStreamResponse._clear_paused_outputs |
workflow_finished | Workflow run completes | status, outputs, total_tokens, elapsed_time | WorkflowRunResponse |
node_failed | Node execution failure event | Exception info | QueueNodeFailedEvent |
The events are serialized as specific stream responses derived from StreamResponse, such as WorkflowStartStreamResponse, WorkflowFinishStreamResponse, and others in api/core/app/entities/task_entities.py
WorkflowRun database entries.WorkflowLogQuery.Sources: api/controllers/service_api/app/workflow.py83-106 api/core/workflow/workflow_entry.py38 api/core/app/entities/task_entities.py51-300
Dify supports distributed tracing for workflow executions by accepting an external trace session ID to correlate spans across services.
trace_session_id from the run payload (WorkflowRunPayload) api/controllers/service_api/app/workflow.py78-80AppGenerateService and into GraphEngine components.OpsTraceManager and WorkflowAppRunnerHandler attach tracing spans to workflow execution operations api/core/workflow/workflow_entry.py12Sources: api/controllers/service_api/app/workflow.py47 api/controllers/service_api/app/workflow.py78-80 api/core/workflow/workflow_entry.py10-30
| Component | Role and Responsibility | File Reference |
|---|---|---|
WorkflowApi | REST endpoint handler for /workflows/run, validation, authentication, streaming response setup | api/controllers/service_api/app/workflow.py150-183 |
AppGenerateService | Business logic to run workflow, load workflow models, manage workflow runs and users | api/services/app_generate_service.py30-80 (referenced) |
WorkflowAppGenerateTaskPipeline | Task pipeline coordinating graph execution, state, streaming event generation | api/core/app/apps/workflow/generate_task_pipeline.py77-190 |
AppQueueManager | Manages event sending, queueing, and streaming to clients | api/core/app/apps/base_app_queue_manager.py (general) |
WorkflowBasedAppRunner | Core graph execution runner, linking graph engine to the queue manager | api/core/app/apps/workflow_app_runner.py90-150 |
GraphEngine | Executes workflow graph nodes, handles node events and lifecycle | (Part of graphon.graph_engine) |
OpsTraceManager | Tracing provider integration, manages spans | core/ops/ops_trace_manager.py |
The workflow execution API can return various HTTP errors mapped from backend exceptions:
| Exception | HTTP Status | Description | Source |
|---|---|---|---|
WorkflowNotFoundError | 404 | Workflow ID does not exist | api/services/errors/app.py |
IsDraftWorkflowError | 400 | Trying to run an unpublished draft | api/services/errors/app.py |
InvokeRateLimitError | 429 | Too many concurrent requests for the app | api/services/errors/llm.py |
ProviderQuotaExceededError | 400 | Model provider quota exhausted | api/controllers/service_api/app/error.py |
AppUnavailableError | 400 | App is disabled or misconfigured | api/controllers/service_api/app/error.py |
Sources: api/controllers/service_api/app/workflow.py25-32 api/services/errors/app.py
The Workflow Execution API enables clients to invoke published workflow graphs as single stateless executions with controlled inputs. Detailed streaming responses provide live insight into execution progress, leveraging event queue management. Built-in distributed tracing supports observability, connecting API requests to backend execution spans. The backend architecture separates REST routing, service logic, execution pipelines, runtime graph engines, and event dispatching layers to deliver robust workflow runs.
This API is essential for users integrating Dify workflows into external systems and for building custom UI or automation layers atop Dify's workflow engine.
api/controllers/service_api/app/workflow.py:1-180api/core/app/apps/workflow/generate_task_pipeline.py:77-190api/core/app/apps/workflow_app_runner.py:90-150api/core/app/apps/base_app_queue_manager.pyapi/core/app/entities/task_entities.pyapi/services/app_generate_service.py:30-80api/core/workflow/workflow_entry.py:163-178api/controllers/service_api/app/completion.py:75-82core/ops/ops_trace_manager.pyapi/controllers/service_api/app/error.pyRefresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.