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

# Sub-Workflow Node

> Run another workflow as a step — the sub_workflow handler class and how to reference or bundle the workflow it runs

A sub-workflow node (`"type": "sub_workflow"`) runs another workflow as a single step. It has a single handler class, `sub_workflow`, and takes **no `process`** — the workflow it runs is named by the node's `handler_id` and `handler_version_id`.

Use this page when building `nodes` for [Create a Workflow](https://developer.opus.com/api-reference/v1-workflow-generation/create-workflow.md) or [Update a Workflow](https://developer.opus.com/api-reference/v1-workflow-generation/update-workflow.md).

## Node Fields

**type** `string` *required*

Always `sub_workflow`.

**handler\_class** `string` *required*

Always `sub_workflow`.

**handler\_id** `string` *required*

The `workflowId` of the workflow this step runs.

**handler\_version\_id** `string`

The `workflowVersionId` of the sub-workflow to run. The workflow saves without it, but the node can't run until it is set, and the pinned version must be active.

`input_schema`, `output_schema` and `mappings` work as on any other step — see [Variable Schemas](https://developer.opus.com/api-reference/v1-workflow-generation/variable-schemas.md). Match them to the sub-workflow's own input and output variables.

## Example

```json sub-workflow node theme={null}
{
  "id": "{NODE_ID}",
  "name": "Archive Invoice",
  "type": "sub_workflow",
  "handler_class": "sub_workflow",
  "handler_id": "{SUB_WORKFLOW_ID}",
  "handler_version_id": "{SUB_WORKFLOW_VERSION_ID}"
}
```

## Referencing An Existing Workflow

On both [Create](https://developer.opus.com/api-reference/v1-workflow-generation/create-workflow.md) and [Update](https://developer.opus.com/api-reference/v1-workflow-generation/update-workflow.md), a sub-workflow node can point at a workflow that already exists. Set `handler_id` (and optionally `handler_version_id`) to its IDs and the node is saved as is.

## Creating Sub-Workflows In The Same Call

[Create a Workflow](https://developer.opus.com/api-reference/v1-workflow-generation/create-workflow.md) also accepts a `subWorkflows` map, which creates the sub-workflows together with the workflow that runs them. This is how you copy a workflow and everything it runs into another workspace:

**1. Read the workflow with its sub-workflows**

Call [Get Workflow Details](https://developer.opus.com/api-reference/v1-workflow-generation/get-workflow-details.md) with `include=subWorkflows`. The response carries a `subWorkflows` map of every nested sub-workflow, keyed `<workflowId>:<versionId>` (`latest` when the node pins no version).

**2. Post it back**

Send that response to Create a Workflow with a different `x-workspace-id`. Opus creates each sub-workflow first, deepest first, then points every sub-workflow node at the new IDs.

**3. Read the new IDs**

The create response's `subWorkflows` map gives the new `workflowId` and `workflowVersionId` of each sub-workflow, under the same key you sent.

When you send `subWorkflows`, **every** sub-workflow node — in the workflow and in each sub-workflow — must have an entry under its `<handler_id>:<handler_version_id>` key. A missing entry, or a sub-workflow that contains itself, is rejected with `400` before anything is created.

```json subWorkflows theme={null}
{
  "name": "Invoice Intake",
  "nodes": {
    "{NODE_ID}": {
      "id": "{NODE_ID}",
      "name": "Archive Invoice",
      "type": "sub_workflow",
      "handler_class": "sub_workflow",
      "handler_id": "{SUB_WORKFLOW_ID}",
      "handler_version_id": "{SUB_WORKFLOW_VERSION_ID}"
    }
  },
  "subWorkflows": {
    "{SUB_WORKFLOW_ID}:{SUB_WORKFLOW_VERSION_ID}": {
      "name": "Archive Invoice",
      "nodes": { },
      "edges": { }
    }
  }
}
```

> [!NOTE]
>
> Update a Workflow does not take `subWorkflows`. To change a sub-workflow, update it directly with its own `workflowId`.


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