> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Human Input API Integration Flow

> End-to-end sequence for handling a paused Human Input form via the API

When a workflow reaches a [Human Input node](https://docs.dify.ai/en/cloud/use-dify/nodes/human-input.md), it pauses and emits a `human_input_required` event in the streaming response. The event carries a `form_token` that your integration uses to drive the form lifecycle until the workflow resumes.

For per-endpoint reference, see the [Human Input API](https://docs.dify.ai/en/api-reference/human-input/get-human-input-form.md).

## Which Forms the API Can Reach

To handle a form in your app, the Human Input node must send it to the end user who started the run:

* **Old Human Input node**: web app delivery is enabled.
* **New Human Input node**: **Initiator** is among the recipients.

For any other form, `form_token` is `null`. Tokens sent to a form's other recipients return 404 `not_found`.

## Steps

The sequence below applies to both Workflow and Chatflow apps. Only the entry endpoint in Step 1 differs between the two.

**1. Start the app in streaming mode**

1. Call [Run Workflow](https://docs.dify.ai/en/api-reference/workflow-runs/run-workflow.md) (Workflow apps) or [Send Chat Message](https://docs.dify.ai/en/api-reference/chat-messages/send-chat-message.md) (Chatflow apps), passing your end user's `user` identifier.
2. Watch the SSE stream for the `human_input_required` event. Capture its `form_token`, and its `workflow_run_id` in case you need to resume listening in Step 5.

   If `form_token` is `null`, the node doesn't [send the form to your end user](#which-forms-the-api-can-reach): its other recipients answer it by email, in IM, or in the Dify console. Skip to Step 5 to wait for their answer, or [stop the run](#stop-a-paused-run).

   If the stream drops before you capture `form_token`, reopen it with [Stream Workflow Events](https://docs.dify.ai/en/api-reference/workflow-runs/stream-workflow-events.md), passing the `workflow_run_id` from the run's earlier `workflow_started` event, the same `user`, and `include_state_snapshot=true`. The new stream replays the `human_input_required` event of each form still waiting, with the same `form_token`.

**2. Get the form definition**

Call [Get Human Input Form](https://docs.dify.ai/en/api-reference/human-input/get-human-input-form.md) with `form_token`, then render the form for the recipient: `form_content` is its Markdown body, `inputs` its fields, and `user_actions` its buttons. Place each field where its placeholder, `{{#$output.<output_variable_name>#}}`, appears in the body.

To pre-fill a `paragraph` field, check its `default`:

* **`default` is `null`**: leave the field empty.
* **`default.type` is `constant`**: pre-fill `default.value`.
* **`default.type` is `variable`**: pre-fill `resolved_default_values[output_variable_name]`, the value Dify resolved for this run. If it's empty or missing, leave the field empty.

For a `select` field, offer the options in `option_source.value`; Dify has already resolved any that come from a variable.

Ignore `default.selector` and `option_source.selector`: both are deprecated.

If the form isn't submitted by `expiration_time`, the paused run follows the node's configured timeout behavior. A resumed stream then carries `human_input_form_timeout` instead of `human_input_form_filled`.

**3. (File inputs only) Upload local files**

If the recipient attaches a local file to a `file` or `file-list` input, upload it first with [Upload File](https://docs.dify.ai/en/api-reference/files/upload-file.md). It returns an `id` you reference as `upload_file_id` in the submit payload. Use one consistent `user` across the run, upload, and submit calls (see [End User Identity](https://docs.dify.ai/en/api-reference/guides/end-user-identity.md) for details).

A remote file needs no upload step: attach it inline in the submit as a `{transfer_method: remote_url, url}` mapping.

**4. Submit the response**

Call [Submit Human Input Form](https://docs.dify.ai/en/api-reference/human-input/submit-human-input-form.md) with the recipient's input values, the selected `action`, and your `user`. The `action` must be one of the actions from the form definition in Step 2.

File inputs accept either a `{transfer_method: local_file, upload_file_id}` mapping (from Step 3) or an inline `{transfer_method: remote_url, url}` mapping. See [Upload First vs. Inline Remote URL](#upload-first-vs-inline-remote-url) for the trade-off.

A successful submit is final: it closes the form and resumes the run along the matching action branch, so the same `form_token` can't be submitted again.

A rejected submit (an invalid action, a missing required input, or a failed remote-file fetch) leaves the form unchanged—fix the inputs and resubmit with the same `form_token`.

**5. Resume listening to the workflow**

If the original SSE stream closed, reopen it via [Stream Workflow Events](https://docs.dify.ai/en/api-reference/workflow-runs/stream-workflow-events.md) with the `workflow_run_id` from Step 1 and the same `user` that started the run—a different `user` gets a 404.

The resumed stream includes `human_input_form_filled` confirming the submission (or `human_input_form_timeout` if the form expired), then the remaining node events through to completion, like a run that never paused.

If the workflow has more than one Human Input node in sequence, the stream closes at each pause by default; pass `continue_on_pause=true` to keep one stream open across all of them.

## Stop a Paused Run

To end a paused run instead of answering its form, call [Stop Workflow Task](https://docs.dify.ai/en/api-reference/workflow-runs/stop-workflow-task.md) (Workflow apps) or [Stop Chat Message Generation](https://docs.dify.ai/en/api-reference/chat-messages/stop-chat-message-generation.md) (Chatflow apps) with the run's `task_id`, which the stream's events carry. For a Chatflow app, pass the same `user` that started the run: with a different one, nothing stops, though the call still returns success.

The run ends as `stopped`. Its form expires, so the `form_token` no longer works. A client listening on [Stream Workflow Events](https://docs.dify.ai/en/api-reference/workflow-runs/stream-workflow-events.md) receives `workflow_finished` with status `stopped`.

## Upload First vs. Inline Remote URL

Both patterns work for file inputs:

* **Pre-upload, then reference `upload_file_id`** (recommended)

  [Upload File](https://docs.dify.ai/en/api-reference/files/upload-file.md) enforces the file size limits at upload time, so the recipient gets immediate feedback and can retry before committing the whole submission.

* **Submit inline with `transfer_method: remote_url`**

  The backend fetches the file at submit time. Faster to integrate, but any size, type, or fetch failure rejects the entire submission, forcing the recipient to redo other fields.

> [!TIP]
>
> For interactive forms with recipient feedback, prefer the pre-upload pattern. The trade-off only pays off when the integration is fully programmatic and no human is waiting to retype anything.

## Example: File-Attached Submission

This example uses a form with a `feedback` paragraph input, an `attachments` file-list input, and `approve` / `reject` actions.

1. Call [Get Human Input Form](https://docs.dify.ai/en/api-reference/human-input/get-human-input-form.md) to get the form definition:

   ```http theme={null}
   GET /form/human_input/<form_token>
   Authorization: Bearer {api-key}
   ```

   Returns the form definition:

   ```json theme={null}
   {
     "form_content": "Please review the draft and confirm or request changes.\n\n{{#$output.feedback#}}\n\nAttach any supporting files:\n\n{{#$output.attachments#}}",
     "inputs": [
       {
         "type": "paragraph",
         "output_variable_name": "feedback",
         "default": {
           "type": "constant",
           "selector": [],
           "value": ""
         }
       },
       {
         "type": "file-list",
         "output_variable_name": "attachments",
         "allowed_file_types": [
           "image",
           "document"
         ],
         "allowed_file_extensions": [],
         "allowed_file_upload_methods": [
           "local_file",
           "remote_url"
         ],
         "number_limits": 5
       }
     ],
     "resolved_default_values": {},
     "user_actions": [
       {
         "id": "approve",
         "title": "Approve",
         "button_style": "primary"
       },
       {
         "id": "reject",
         "title": "Request changes",
         "button_style": "default"
       }
     ],
     "expiration_time": 1745510400
   }
   ```

2. For each local file, call [Upload File](https://docs.dify.ai/en/api-reference/files/upload-file.md):

   ```http theme={null}
   POST /files/upload
   Authorization: Bearer {api-key}
   Content-Type: multipart/form-data

   file=<binary>
   user=abc-123
   ```

   Returns `{"id": "1a77f0df-...", ...}`.

3. Call [Submit Human Input Form](https://docs.dify.ai/en/api-reference/human-input/submit-human-input-form.md) with the recipient's input and selected action:

   ```http theme={null}
   POST /form/human_input/<form_token>
   Authorization: Bearer {api-key}
   Content-Type: application/json

   {
     "inputs": {
       "feedback": "Looks good to ship",
       "attachments": [
         {"transfer_method": "local_file", "upload_file_id": "1a77f0df-..."}
       ]
     },
     "action": "approve",
     "user": "abc-123"
   }
   ```

   Returns `{}`. The workflow resumes along the `approve` branch.

4. Reconnect to the run's stream with [Stream Workflow Events](https://docs.dify.ai/en/api-reference/workflow-runs/stream-workflow-events.md) to follow it through to completion, as in Step 5 of the sequence above.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.