# Sub-Workflow

> Put a whole workflow inside another as one node with typed inputs and outputs. Create a new one in place or reuse an existing workflow, up to 5 levels deep.

Source: https://nodaro.ai/docs/nodes/automate/sub-workflow

The **Sub-Workflow** node puts a whole workflow inside another one as a single node. From the outside it looks like any other node, with inputs, outputs and a status. Click its expand icon to edit the inner workflow in place, and a breadcrumb at the top of the editor shows where you are. Use it to reuse one pipeline in many workflows, or to keep a large workflow easy to read.

- Found in: Automate › Workflows
- Output: data
- API type: `sub-workflow`

## When to use it
- You use the same video composition pipeline in several content workflows.
- You want a processing chain, such as [Remove Background](https://nodaro.ai/docs/nodes/image/remove-background) followed by [Upscale Image](https://nodaro.ai/docs/nodes/image/upscale-image), as one reusable node.
- Your workflow has grown large, and you want to split it into modules.
- You want each scene of a film, with its image, animation, speech and lip sync, packed into one node.

## Quick start
### Add the node

Press Tab on the canvas and choose **Automate › Workflows › Sub-Workflow**.

### Create or choose the inner workflow

To start fresh, save your workflow, then click **Create empty sub-workflow** in the settings panel. Nodaro creates a child workflow with one [Sub-Workflow Input](https://nodaro.ai/docs/nodes/automate/sub-workflow-input) and one [Sub-Workflow Output](https://nodaro.ai/docs/nodes/automate/sub-workflow-output), and opens it for editing. To reuse a workflow you already have, choose it under **Workflow** instead, then choose a **Route**.

### Build or check the inner workflow

Inside the child workflow, connect the nodes between the Sub-Workflow Input and the Sub-Workflow Output, and set their ports. Click the parent's name in the breadcrumb to return.

### Connect it and run

The ports of the route appear as inputs and outputs on the Sub-Workflow node. Connect them like any other node's, for example an [Upload Image](https://nodaro.ai/docs/nodes/image/upload-image) into an input and an output into [Generate Video](https://nodaro.ai/docs/nodes/video/generate-video). Click **Run**.

Workflow: In the parent workflow, one Sub-Workflow node represents a whole cleanup pipeline between the upload and the video.

- Upload Image → Sub-Workflow (Product photo)
- Sub-Workflow → Generate Video (Clean shot)

Workflow: Inside the Sub-Workflow, the input port feeds Remove Background and Upscale Image, and the output port returns the clean shot.

- Sub-Workflow Input → Remove Background
- Remove Background → Upscale Image
- Upscale Image → Sub-Workflow Output

## Inputs and outputs
The node's inputs and outputs come from the chosen route. Each port of the route's [Sub-Workflow Input](https://nodaro.ai/docs/nodes/automate/sub-workflow-input) becomes an input, and each port of its [Sub-Workflow Output](https://nodaro.ai/docs/nodes/automate/sub-workflow-output) becomes an output. Every port is colored by its type: text, image, video, audio or any.

A route is one Sub-Workflow Input paired with one Sub-Workflow Output through the same route ID. A workflow can have several routes, and each route is a separate path through it.

## Settings
| Setting | What it does |
| --- | --- |
| **Label** | The node's name in this workflow. |
| **Create empty sub-workflow** | Creates a new child workflow with one input node and one output node, under this workflow, and opens it for editing. It is disabled until the parent workflow has been saved. |
| **Workflow** | Reuses an existing workflow. The list shows every workflow that has at least one route, with its number of routes. Child workflows that belong to other nodes are hidden. |
| **All projects** | Off by default, so the list shows the current project only. Enable it to see workflows from every project. |
| **Route** | The route to use, when the workflow has more than one. Each route shows its number of inputs and outputs. |
| **Interface** | The inputs and outputs of the chosen route. **Refresh** reloads them after you change the inner workflow. |
| **View Workflow** | Opens the inner workflow in a read-only viewer, without leaving the page. |
| **Open Workflow** | Opens the inner workflow for editing, like the expand icon on the node. |
| **View mode** | How the node looks on the canvas. **Ports** shows the inputs, the outputs, the status and a preview of the result. |

## Edit the inner workflow in place

Click the expand icon on the node, labeled **Edit referenced workflow**, or click **Open Workflow** in the settings panel. The editor opens the inner workflow, and a breadcrumb at the top shows the path, for example **Launch video › Clean product shot**. Click any part of the breadcrumb to jump to that level. The breadcrumb disappears when you return to the first workflow.

If the current workflow has unsaved changes, the editor asks whether to save or discard them before it opens the inner workflow.

## Rules for callable workflows

When you save a workflow that contains Sub-Workflow Input or Sub-Workflow Output nodes, Nodaro checks three rules:

- Every Sub-Workflow Input has a Sub-Workflow Output with the same route ID.
- Every Sub-Workflow Output has at least one port.
- No two Sub-Workflow Input nodes, and no two Sub-Workflow Output nodes, share a route ID.

A save that breaks a rule is refused, and each problem is listed.

## How it runs

- **Only the route runs.** The nodes connected downstream of the route's Sub-Workflow Input run. Other nodes in the inner workflow do not.
- **Up to 5 levels deep.** A sub-workflow can contain sub-workflows, down to 5 levels.
- **No loops.** A workflow cannot call itself through the same route, directly or through other workflows. The same workflow can still be called through a different route.

## Credits
The Sub-Workflow node is free. Every node that runs inside it is charged at its usual price.

## Tips
- **Keep nesting shallow.** The limit is 5 levels, and deeply nested workflows are harder to debug.
- **Create empty for one-off modules.** A child made with **Create empty sub-workflow** stays private to its parent and does not clutter the project's workflow list.
- **Choose an existing workflow for shared building blocks.** A normal workflow stays in the list, and any parent can reuse it.
- **Refresh after changes.** When you add, remove or retype ports in the inner workflow, click **Refresh** in the parent.
- **Name each node for its job.** A label such as "Clean product shot" explains the node's role in the parent.
- **Publish instead of share.** To offer a pipeline to other people as a versioned node, publish it as a [Component](https://nodaro.ai/docs/nodes/automate/component).

## Frequently asked questions

### How do I make a workflow usable as a Sub-Workflow?

Add a Sub-Workflow Input and a Sub-Workflow Output to it, pair them with the same route, and give them ports. A workflow with at least one pair appears in the Workflow list of the Sub-Workflow node.

### What is the difference between Create empty sub-workflow and choosing an existing workflow?

Create empty sub-workflow makes a new child workflow that belongs to this node. It is hidden from the project's workflow list and opens only from this node. An existing workflow stays a normal workflow that any other workflow can reuse.

### How deep can sub-workflows be nested?

Up to 5 levels. A workflow cannot call itself through the same route, directly or through other workflows, but it can call itself through a different route.

### Does a Sub-Workflow cost extra credits?

No. The Sub-Workflow node itself is free. You pay for the nodes that run inside it, at their usual prices, and only the nodes that the chosen route reaches run.

### Why does the node show old ports after I changed the inner workflow?

The node keeps a copy of the route's inputs and outputs. Click Refresh next to Interface in the settings panel to load the new ports.
