Run Robots workflows automatically with Directives | Mux
Run Robots workflows automatically with Directives
Directives run multiple Mux Robots workflows on an asset in the correct order. Use them when you want workflows to start automatically, with no glue code or webhook listeners.
Network Error
A network error caused the media download to fail.
Directives are the orchestration layer for Mux Robots. A single Robots job runs one workflow on one asset. A Directive runs several workflows in the right order, and can trigger them automatically the moment an asset is ready.
Reach for a Directive when you want to:
- Run a few Robots workflows on the same asset (say, generate chapters and a summary and translate the captions).
- Guarantee the prerequisites exist before a workflow runs (auto-generate captions before chapter detection, for example).
- Trigger everything automatically when an asset is created, with no glue code, no webhook listeners, and no manual dispatch.
You could wire this up yourself: subscribe to the Mux Video and Robots webhooks, dispatch each workflow, encode the ordering between them, and babysit the retries. A Directive trades all of that for a single declaration. You say what you want once, attach it to your assets, and Mux handles the rest.
See the Directives API referenceAPI for the full endpoint specification. See Mux Robots pricing for unit costs. Directives themselves are free; you pay only for the workflow runs they trigger.
What you can do
A Directive can run any Robots workflow, and each one takes the same parameters you'd set for a one-off Robots job. For the full list of workflows, see What you can do in the Robots guide.
How it works
A Directive has two parts:
- Workflows: what to run.
- Resources: what those workflows depend on.
You define both once, when you create the Directive. Every run after that uses the same configuration, whether you trigger it by hand or it fires automatically. When a run starts, the engine checks that each workflow has the resources it needs, resolves anything that's missing according to the resource's source policy, and then runs the workflows in the correct order.
A Directive's configuration is locked in once you create it. You can delete a Directive, but to change what it runs, duplicate an existing Directive or create a new one and re-attach your assets. Deleting a Directive doesn't cancel runs already in progress; it just prevents new ones from starting.
Create a Directive
You can create a Directive from the Mux Dashboard or via the API.
From the Dashboard
In the Directives section, click Create Directive. You can start from scratch, or pick one of the prebuilt templates for common setups (like generating captions and then translating them) and customize it from there. Either way, give it a name, pick the workflows you want to run, set each workflow's parameters, and declare any resource dependencies.
From the API
POST /robots/v0/directives with a Directive configuration:
The response is a 201 with the new Directive, including its id:
Validation errors return a 422 with every problem collected into one message, so you can fix the config in a single pass.
Configure resources and dependencies
Some workflows need a specific resource on the asset before they can run. Generate chapters, for instance, reads from a caption text track. No captions, no chapter markers.
Resource types
type |
Describes | Selector fields |
|---|---|---|
video.asset.track |
A caption (subtitles) or audio track on the asset. | kind: "caption" or "audio" (required). language: BCP 47 code (optional; when omitted, any language of that kind matches). |
video.asset.shots |
The asset's shot-detection output. | None. Singleton per asset. |
Source policies
source |
What it does |
|---|---|
{ "via": "external" } |
Wait for the resource to appear and become ready on the asset. |
{ "via": "required" } |
The resource must already be ready when the run starts. |
{ "via": "workflow", "binding": "<reference_id>" } |
Produced by another workflow binding in this Directive. |
{ "via": "mux_api", "action": "<action>", "params"?: {…} } |
The engine calls Mux Video to create the resource on demand. |
Workflow inputs
Each workflow binding can declare inputs: a flat array of resource reference_ids the workflow depends on. Every referenced resource must be declared in the same Directive.
Chain workflows together
To chain workflows, declare a resource whose source is another binding in the same Directive. The engine dispatches the first binding, waits for it to complete, and then dispatches the next. If an error occurs, the subsequent workflows fast-fail.
Replace existing tracks
Set replace_existing_tracks in a binding's params. A binding that replaces tracks can delete a track another binding reads.
Run a Directive
By hand, from the Dashboard
Open a saved Directive and click Run on asset. Pick an asset and the run starts immediately.
By hand, from the API
POST /robots/v0/directives/{DIRECTIVE_ID}/runs with the target asset ID:
If a run for the same Directive and asset is already in progress, the API returns a 409 Conflict. Only one active run per pair.
Automatically, by attaching to an asset
When you create an asset, set the Directives field in the Settings step of the asset creation dialog. Any Directives you attach run automatically as soon as the asset is ready.
Track a run
Webhooks
Every directive-run lifecycle transition fires a webhook event. Subscribing is the recommended way to react to runs without polling.
Retrieve a run
If webhooks aren't an option, poll the run endpoint:
Runs are retained for 30 days after they reach a terminal state. The response includes the current status and a node_states array with one entry per workflow binding.
Managing Directives
Retrieve a Directive:
List Directives in the current environment, newest first.
List runs for a Directive, newest first, within the 30-day retention window.
Delete a Directive (soft-delete; the row stops appearing in GETs and can't start new runs, but any in-flight runs continue to completion).
Frequently asked questions
Who can use Directives?
Directives are available to all Mux Video customers, including accounts on the free plan, with Mux Robots enabled.
How much do Directives cost?
Directives themselves are free. You only pay for the workflow runs they trigger.
What happens if a workflow errors partway through a run?
Other workflows continue if they don't depend on the failed binding. The run's own top-level status becomes partial if some workflows completed and others errored, or errored if none succeeded.