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

# Use `difyctl` as an External SSO User

> Sign in to difyctl through single sign-on without a Dify account, then find and run the apps open to external users, stop their runs, and answer their Human Input forms

> [!TIP]
>
> To hand the work over to your coding agent, [set it up with the `difyctl` skill](https://enterprise-docs.dify.ai/en/3.14.x/develop/cli/get-started#set-up-your-coding-agent) and point it to this page.

External SSO users are people who open Dify web apps through single sign-on (SSO) and have no Dify account.

If you have a Dify account, follow [Get Started](https://enterprise-docs.dify.ai/en/3.14.x/develop/cli/get-started.md) instead.

## Sign In

1. [Install `difyctl`](https://enterprise-docs.dify.ai/en/3.14.x/develop/cli/get-started#install).
2. Sign in with the address of the Dify console. A web app's address won't work.

   ```bash theme={null}
   difyctl login --server https://dify.example.com
   ```

   If no browser opens, for example over SSH, open the URL `difyctl` prints on any device.
3. On the **Authorize difyctl** page, enter the code `difyctl` printed and click **Continue**.
4. Choose **Sign in with SSO**, and sign in the same way you do for your web apps.
5. When the page shows your email, click **Authorize**.

Your sign-in lasts 14 days. After that, every command fails with `auth_expired` until you sign in again.

When you're done with a machine, run `difyctl logout` to delete your sign-in from it.

> [!NOTE]
>
> When you sign out or sign in again, `difyctl` reports `server revoke failed: …`. That's expected for an SSO sign-in, and the command still works.

## Find the Apps You Can Run

Run `difyctl get console_app external` to list the apps you can run. Only web apps with Service API access turned on are listed.

```bash theme={null}
difyctl get console_app external

# narrow by part of the name, by mode, or both
difyctl get console_app external --name report --mode workflow
```

Use an app's `id` as `--app-id` in other commands. Its `mode` is the app's type, which decides the command that runs it:

| `mode` | App type | Run it with |
| :- | :- | :- |
| `workflow` | Workflow | `run console_app workflow` |
| `advanced-chat` | Chatflow | `run console_app advanced_chat` |
| `chat` | Chatbot | `run console_app chat` |
| `agent-chat` | Legacy Agent | `run console_app chat` |
| `completion` | Text Generator | `run console_app completion` |
| `agent` | Agent | Can't be run with `difyctl` |

## Check an App's Inputs

Run `difyctl describe console_app external` to show an app's variables: their names, their types, and which are required.

```bash theme={null}
difyctl describe console_app external --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b
```

## Run a Workflow

Pass the app's variables to `difyctl run console_app workflow` in `--inputs`, as JSON keyed by name. The answer is the result's `outputs`.

```bash theme={null}
difyctl run console_app workflow --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --inputs '{"topic": "quarterly report"}'

# read the variables from a file
difyctl run console_app workflow --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --inputs @inputs.json
```

> [!NOTE]
>
> A misspelled required variable fails the run with an error such as `topic is required in input form`. A misspelled optional one is silently left out. Check the variable names with [`describe console_app external`](#check-an-apps-inputs).

## Send a Message or Generate Text

Use the `run console_app` command that matches the app's type in [Find the Apps You Can Run](#find-the-apps-you-can-run). Put the message in `--query` and any variables in `--inputs`. A Text Generator app usually takes only `--inputs`. The response is the result's `text.answer`.

```bash theme={null}
# a Chatbot or legacy Agent app
difyctl run console_app chat --app-id 0a1b2c3d-4e5f-6789-abcd-ef0123456789 --query "What are your business hours?"

# a Chatflow app with one variable
difyctl run console_app advanced_chat --app-id 3c4d5e6f-7a8b-4c9d-8e0f-1a2b3c4d5e6f --query "What changed this quarter?" --inputs '{"topic": "quarterly report"}'

# a Text Generator app
difyctl run console_app completion --app-id 5e6f7a8b-9c0d-4e1f-a2b3-c4d5e6f7a8b9 --inputs '{"topic": "quarterly report"}'
```

> [!NOTE]
>
> With an SSO sign-in, every message starts a new conversation, so put everything the app needs into each message. A run with `--conversation-id` fails, even when it follows a result's hint to reply in the same conversation.

## Send Files

With any run command, map each file variable to a local path in `--files`. A file-list variable takes a list of paths. A file on the web goes in `--inputs` instead. Pass each file variable in either `--files` or `--inputs`, not both.

```bash theme={null}
difyctl run console_app workflow --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --inputs '{"topic": "quarterly report"}' --files '{"document": "./report.pdf", "appendices": ["./q1.pdf", "./q2.pdf"]}'

# a file on the web
difyctl run console_app workflow --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --inputs '{"document": {"transfer_method": "remote_url", "url": "https://example.com/report.pdf", "type": "document"}}'
```

## Follow a Long Run

To watch a run as it goes, add `--stream`. It prints each event as it happens, one JSON object per line. In a Workflow run, the last event, `workflow_finished`, carries the result in `data.outputs`. To print only the events you want, name each one with `--only`.

```bash theme={null}
difyctl run console_app workflow --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --inputs '{"topic": "quarterly report"}' --stream

# print only the last event
difyctl run console_app workflow --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --inputs '{"topic": "quarterly report"}' --stream --only workflow_finished
```

## Stop a Run

To stop a Workflow or Chatflow run that's still going or paused at a Human Input form, pass its run ID to `difyctl stop run`. Pressing Ctrl+C stops only `difyctl`, not the run on the server.

The run ID is the `run_id` in a `suspended` or `incomplete` result, such as the one you get after Ctrl+C. With `--stream`, take `workflow_run_id` from the `workflow_started` event.

For a Chatbot, legacy Agent, or Text Generator reply, use [`stop task`](#stop-a-chatbot-legacy-agent-or-text-generator-reply) instead.

```bash theme={null}
difyctl stop run --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --run-id 4b5c6d7e-8f90-4a1b-b2c3-d4e5f6a7b8c9
```

To see how a run ends instead of stopping it, pass its run ID to `difyctl get run event` with `--include-state-snapshot`. The command follows the run until it ends or pauses at a form, then prints its result. For a Chatflow, the reply is in `outputs.answer`, not `text.answer`.

```bash theme={null}
difyctl get run event --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --run-id 4b5c6d7e-8f90-4a1b-b2c3-d4e5f6a7b8c9 --include-state-snapshot
```

> [!NOTE]
>
> Keep the run ID. Without it you can't find the run again, because listing runs needs a Dify account.

## Stop a Chatbot, Legacy Agent, or Text Generator Reply

To be able to stop a reply, start it with `--stream`. Then pass the `task_id` from its first event to `difyctl stop task`.

```bash theme={null}
difyctl stop task --app-id 0a1b2c3d-4e5f-6789-abcd-ef0123456789 --task-id 26992456-d005-4add-a26d-8dff91d5f13d
```

> [!NOTE]
>
> A stopped reply looks finished: its stream ends with `message_end`, and the command that started it exits with code 0. The answer holds only what arrived before the stop. If your script uses the answer, have it record that it called `stop task`.

## Answer a Human Input Form

A run that pauses at a form returns a result whose `status` is `suspended`. When you can answer the form, the result has one hint per action button, each a `submit run form` command with the form token filled in. When the form went only to other recipients, `hints` is `[]`, and the run resumes once one of them answers.

To answer, [run the hint](https://enterprise-docs.dify.ai/en/3.14.x/develop/cli/find-and-run-commands.md#follow-hints) for your action, replacing each `null` in its `inputs` with your answer. To see the form's fields first, take `form_token` from any hint and run `difyctl describe run form`.

Whoever answers, follow the resumed run with `get run event`, passing the paused result's `run_id` as `--run-id`. Keep `--include-state-snapshot`, or the command can sit silent for up to 5 minutes.

```bash theme={null}
# show the form's fields
difyctl describe run form --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --form-token Xq7Lm2RtPz9KcV4bN8wJdE

# submit with an action; use --inputs '{}' when the form has no fields
difyctl submit run form --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --form-token Xq7Lm2RtPz9KcV4bN8wJdE --action approve --inputs '{"comment": "Looks good"}'

# follow the resumed run
difyctl get run event --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --run-id 4b5c6d7e-8f90-4a1b-b2c3-d4e5f6a7b8c9 --include-state-snapshot

# keep following if the run can pause at another form later
difyctl get run event --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --run-id 4b5c6d7e-8f90-4a1b-b2c3-d4e5f6a7b8c9 --include-state-snapshot --continue-on-pause
```

## Find Why a Run Failed

A failed run's result has `status: failed`, and its `error.message` says why. `difyctl` exits with code 1. A Workflow or Chatflow run that was stopped shows as `failed` too.

To see which node of a Workflow or Chatflow run failed, run the app again with `--stream`. Each `node_finished` event carries that node's `status` and `error`. A run's nodes can't be inspected after it ends, because run history needs a Dify account.

```bash theme={null}
difyctl run console_app workflow --app-id 7f3e9a2b-1c4d-4e8f-9a0b-2d5c8e1f4a7b --inputs '{"topic": "quarterly report"}' --stream
```

## Troubleshooting

| Message | What to do |
| :- | :- |
| No **Sign in with SSO** on the sign-in page | [SSO for web apps](https://enterprise-docs.dify.ai/en/3.14.x/administer/authentication/webapp-external-user-auth.md) must be set up in the Enterprise Dashboard, under **Authentication** > **Web App**. |
| `This identity is linked to a Dify account. Use “Sign in with Dify account” instead.` | Your email belongs to a Dify account. Follow [Get Started](https://enterprise-docs.dify.ai/en/3.14.x/develop/cli/get-started.md#sign-in) instead, and choose **Sign in with Dify account**. |
| `unauthorized: invalid bearer` (code `auth_expired`) | Your sign-in expired after 14 days. [Sign in again](#sign-in). |
| `input_invalid: invalid input for "get console_app"`, with `--workspace-id: required` | Run `get console_app external` instead. |
| `forbidden: unsupported_token_type` (code `access_denied`) | The command needs a Dify account, even when an error's hint suggested it. In place of `describe console_app`, run `describe console_app external`. In place of `describe run`, pass the run ID to `get run event`. In place of `get run node`, follow [Find Why a Run Failed](#find-why-a-run-failed). |
| `forbidden: subject_not_allowed_for_access_mode` | The app's web app access doesn't admit external users. It needs to be set to [**Authenticated external users**](https://enterprise-docs.dify.ai/en/3.14.x/use/publish/webapp/web-app-access.md#authenticated-external-users) or **Anyone with the link**. |
| `service_api_disabled` | The app needs its Service API access turned on. The `set service_api` command in the hint needs a Dify account. |
| `app_mode_mismatch` | The command doesn't match the app's `mode`. Check the `mode` with `describe console_app external`, and pick the command from the [`mode` table](#find-the-apps-you-can-run). An app whose `mode` is `agent` can't be run with `difyctl`. |
| `Conversation Not Exists.`, or a Chatflow run that ends `failed` with an empty `error.message`, after `--conversation-id` | Every message starts a new conversation with an SSO sign-in. Run it again without `--conversation-id`, with everything the app needs in the message. |
| `run_not_found` from `stop run` | Pass the `run_id` of a run you started, not a `task_id`, with the `--app-id` of its app. |
| `Task not found` from `stop task` | Check that the `task_id` comes from the first event of a reply you started. If the reply has already ended, there's nothing to stop. |
| `Workflow run not found` from `get run event` | Pass the `run_id` of a run you started. You can't follow someone else's run. |
| `form_not_found` | Check that the form token is the `form_token` from the paused result's `hints`, and that `--app-id` is the app the run belongs to. |
| `human_input_form_submitted` | The form already has an answer: from another recipient, from your email copy of the request, or from an earlier submit. The run goes on with that first answer. Follow it with `get run event`. |
| `human_input_form_expired` | The form waited past its timeout, or the run was stopped. Run `get run event` with the run's ID to see how the run ended or carried on. |

For other sign-in errors, see [Troubleshooting](https://enterprise-docs.dify.ai/en/3.14.x/develop/cli/get-started.md#troubleshooting) on Get Started. For errors any command can raise, see [Troubleshooting](https://enterprise-docs.dify.ai/en/3.14.x/develop/cli/reference/results-errors-and-exit-codes.md#troubleshooting) on Results, Errors, and Exit Codes.


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