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

# Create Definition

Use this API to register a new workflow definition (the static blueprint of nodes, edges, and optional parallel groups). Definitions are validated at write time: schema errors, `compileGraph` edge-contract errors, and linter graph-shape errors are rejected with explicit validation keys.

# Endpoint

`POST https://api.velt.dev/v2/workflow/definitions/create`

# Headers

<ParamField header="x-velt-api-key" type="string" required>
  Your API key.
</ParamField>

<ParamField header="x-velt-auth-token" type="string" required>
  Your [Auth Token](/docs/security/auth-tokens).
</ParamField>

# Body

#### Params

<ParamField body="data" type="object" required>
  <Expandable title="properties">
    <ParamField body="definitionId" type="string" required>
      `^[a-z0-9][a-z0-9-]{2,63}$`. Stable identifier for this definition.
    </ParamField>

    <ParamField body="name" type="string" required>
      1–200 chars. Human-readable label.
    </ParamField>

    <ParamField body="description" type="string">
      0–2000 chars.
    </ParamField>

    <ParamField body="scope" type="object">
      Defaults to `{ level: "apiKey" }`. Options:

      * `{ level: "apiKey" }`: workspace-wide.
      * `{ level: "organization", organizationId: "<id>" }`: bound to one organization. `organizationId` is required (returns `INVALID_ARGUMENT` if omitted).
      * `{ level: "document", organizationId: "<id>", documentId: "<id>" }`: bound to one document under an organization. Both fields required.

      The response echoes back the same `organizationId` / `documentId` you sent. The engine keeps its own internal namespaced copies for storage, but they are never returned, so a definition read round-trips safely into a create or update call. See [Duplicating a workflow](/docs/ai/approval-engine/patterns#duplicating-a-workflow).
    </ParamField>

    <ParamField body="nodes" type="array" required>
      1–100 nodes. Each node has `nodeId` (1–64 chars), a `type`, and a `config` block validated strictly against that type.

      | `type`         | What it does                                                     | `config` essentials                                                               |
      | -------------- | ---------------------------------------------------------------- | --------------------------------------------------------------------------------- |
      | `agent`        | Runs a Velt agent against a URL.                                 | `agentId` plus `url` or `urlPath` (at least one required).                        |
      | `human`        | Waits for reviewers to approve or reject.                        | `reviewers[]` or legacy `reviewerIds[]`.                                          |
      | `notification` | Sends an email or Slack message from the workflow.               | `channel` and `bodyTemplate`, plus `recipients` (email) or `slackTarget` (slack). |
      | `webhook`      | Calls your HTTPS endpoint. `async` mode waits for your callback. | `url`, optional `mode`, `authMode`, `timeoutMs`.                                  |

      Each node also accepts an optional `slaMs` (integer ms, up to 7 days) and optional cosmetic `name` (1–200 chars) and `description` (≤ 2000 chars) labels echoed verbatim in the response. Full field tables: [Node configuration](/docs/ai/approval-engine/customize-behavior#node-configuration).
    </ParamField>

    <ParamField body="edges" type="array" required>
      0–500 edges. Each edge: `{ from, to, on?, when?, loop? }`. `from` / `to` are `EdgeEndpoint`s: a bare node-id string, `{ kind: "node", nodeId }`, or `{ kind: "group", groupId }`.

      | Field  | Type                | Required                           | Notes                                                                                                                                                              |
      | ------ | ------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
      | `from` | `EdgeEndpoint`      | yes                                | Source node or group.                                                                                                                                              |
      | `to`   | `EdgeEndpoint`      | yes                                | Target node or group.                                                                                                                                              |
      | `on`   | enum                | no (default `"always"`)            | `approve` / `reject` / `always` / `exhausted` / `custom`. `approve` and `reject` auto-compile their predicates.                                                    |
      | `when` | JSON-AST string     | only when `on:"custom"`            | Custom predicate over the source step's output. Invalid on any other `on` role. See [custom predicates](/docs/ai/approval-engine/customize-behavior#custom-predicates). |
      | `loop` | `{ maxIterations }` | only on an `on:"reject"` back-edge | `maxIterations` 1–20. Marks the reject edge as a loop-back; the server derives the loop region. A sibling `on:"exhausted"` edge handles cap exhaustion.            |

      A `human` node must have an outgoing `on:"reject"` edge or the definition is rejected with `APPROVAL_HUMAN_NODE_REQUIRES_REJECT_PATH`. See [the edge model](/docs/ai/approval-engine/customize-behavior#edge-model) for the full role and loop semantics.
    </ParamField>

    <ParamField body="groups" type="array">
      0–100 parallel-group definitions. See [parallel groups and quorum policies](/docs/ai/approval-engine/customize-behavior#parallel-groups-and-quorum-policies).

      A group can be an edge source (`from: { kind: "group", groupId }`): a `waitAll` group fans out a collective approve/reject decision by unanimity (every member approved → approve, else reject), and a `cancelOnQuorum` group fans out a collective approve successor on quorum. A forward `on:"reject"` from a `joinOnQuorum` / `cancelOnQuorum` group is a rejected dead edge. Edge-to-group fan-out (`to: { kind: "group", groupId }`) is accepted for all quorum policies.
    </ParamField>

    <ParamField body="triggers" type="array">
      0–50 trigger declarations. A trigger starts executions for you, with no dispatch call.

      | Field            | Type   | Required | Description                                                                                                                          |
      | ---------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
      | `triggerId`      | string | yes      | 1–128 chars. Stable identifier, also the idempotency-key prefix.                                                                     |
      | `eventName`      | string | no       | ≤ 128 chars. Optional label.                                                                                                         |
      | `filters`        | object | no       | Free-form match filters.                                                                                                             |
      | `inboundWebhook` | object | no       | External systems POST to start a run. See [Inbound webhook trigger](/docs/ai/approval-engine/customize-behavior#inbound-webhook-trigger). |
      | `schedule`       | object | no       | Cron cadence starts runs. See [Scheduled trigger](/docs/ai/approval-engine/customize-behavior#scheduled-cron-trigger).                    |
      | `appTrigger`     | object | no       | A connected GitHub App or Vercel Integration routes events. See [App trigger](/docs/ai/approval-engine/customize-behavior#app-trigger).   |

      `inboundWebhook`, `schedule`, and `appTrigger` are mutually exclusive on a single trigger entry (`APPROVAL_APP_TRIGGER_EXCLUSIVE`). A definition may declare several entries, each using a different mechanism. A triggered run always inherits the definition's `scope`.
    </ParamField>

    <ParamField body="webhookConfig" type="object">
      Default webhook receiver for every execution of this definition: `{ url, secret, eventTypes? }`. `url` is `https`-only and SSRF-guarded; `secret` is 16–512 chars; optional `eventTypes` limits delivery to up to 50 event types. A per-execution `webhookUrl` / `webhookSecret` on [Dispatch Execution](/docs/api-reference/rest-apis/v2/approval-engine/executions/dispatch-execution) overrides this.
    </ParamField>

    <ParamField body="tags" type="string[]">
      0–20 tags, each ≤ 64 chars.
    </ParamField>

    <ParamField body="custom" type="object">
      Free-form metadata.
    </ParamField>

    <ParamField body="organizationId" type="string">
      Required when `scope.level` is `organization` or `document`.
    </ParamField>

    <ParamField body="documentId" type="string">
      Required when `scope.level` is `document`.
    </ParamField>
  </Expandable>
</ParamField>

#### Node object examples

```JSON theme={null}
{
  "nodeId": "brand-check",
  "type": "agent",
  "name": "Brand check",
  "description": "Verifies copy against brand guidelines.",
  "config": { "agentId": "brand-agent-v1", "urlPath": "documentUrl", "requireNonEmptyOutput": true },
  "slaMs": 3600000
}
```

```JSON theme={null}
{
  "nodeId": "notify-stakeholders",
  "type": "notification",
  "config": {
    "channel": "email",
    "recipients": ["lead@acme.dev"],
    "subjectTemplate": "Approval {{input.decision}}",
    "bodyTemplate": "Findings: {{input.agentResultsSummary.summary}}"
  }
}
```

<Warning>
  An `agent` node must set `url` or `urlPath`, or the definition is rejected with `APPROVAL_AGENT_NODE_REQUIRES_URL_OR_URLPATH`. `blocking: true` requires a sibling `resolutionPolicy` to pass schema validation, and the pair is then rejected at run time with `agent-blocking-not-supported`; place a `human` node downstream of the agent instead.
</Warning>

#### Edge object examples

```JSON theme={null}
{ "from": "brand-check", "to": "legal-review", "on": "approve" }
{ "from": "human-review", "to": "rework-notice", "on": "reject" }
{ "from": "human-review", "to": "agent-draft", "on": "reject", "loop": { "maxIterations": 3 } }
{ "from": "human-review", "to": "escalate", "on": "exhausted" }
{ "from": "brand-check", "to": "legal-review", "on": "custom", "when": "{\"op\":\"eq\",\"args\":[{\"var\":\"output.passesBrandCheck\"},true]}" }
```

## **Example Requests**

#### Create a marketing-copy approval workflow

```JSON theme={null}
{
  "data": {
    "definitionId": "marketing-copy-approval",
    "name": "Marketing copy approval",
    "scope": { "level": "apiKey" },
    "nodes": [
      { "nodeId": "agent-draft",   "type": "agent", "config": { "agentId": "copy-agent-v1",    "urlPath": "documentUrl" } },
      { "nodeId": "human-review",  "type": "human", "config": { "reviewers": [{ "userId": "u_reviewer_01", "mandatory": true }] } },
      { "nodeId": "agent-publish", "type": "agent", "config": { "agentId": "publish-agent-v1", "urlPath": "documentUrl" } },
      { "nodeId": "agent-rework",  "type": "agent", "config": { "agentId": "rework-agent-v1",  "urlPath": "documentUrl" } }
    ],
    "edges": [
      { "from": "agent-draft", "to": "human-review" },
      { "from": "human-review", "to": "agent-publish", "on": "approve" },
      { "from": "human-review", "to": "agent-rework", "on": "reject" }
    ]
  }
}
```

#### Start runs from a nightly cron schedule

```JSON theme={null}
{
  "data": {
    "definitionId": "nightly-content-audit",
    "name": "Nightly content audit",
    "nodes": [
      { "nodeId": "audit", "type": "agent", "config": { "agentId": "broken-links", "url": "https://acme.com" } }
    ],
    "edges": [],
    "triggers": [
      {
        "triggerId": "nightly-audit",
        "schedule": { "cron": "0 2 * * *", "timezone": "America/Los_Angeles", "enabled": true }
      }
    ]
  }
}
```

# Response

#### Success Response

```JSON theme={null}
{
  "result": {
    "definitionId": "marketing-copy-approval",
    "name": "Marketing copy approval",
    "description": null,
    "version": 1,
    "scope": { "level": "apiKey", "organizationId": null, "documentId": null },
    "nodes": [
      { "nodeId": "agent-draft", "type": "agent", "config": { "agentId": "copy-agent-v1", "urlPath": "documentUrl" } },
      { "nodeId": "human-review", "type": "human", "config": { "reviewers": [{ "userId": "u_reviewer_01", "mandatory": true }] } },
      { "nodeId": "agent-publish", "type": "agent", "config": { "agentId": "publish-agent-v1", "urlPath": "documentUrl" } },
      { "nodeId": "agent-rework", "type": "agent", "config": { "agentId": "rework-agent-v1", "urlPath": "documentUrl" } }
    ],
    "edges": [
      { "from": "agent-draft", "to": "human-review" },
      { "from": "human-review", "to": "agent-publish", "on": "approve" },
      { "from": "human-review", "to": "agent-rework", "on": "reject" }
    ],
    "groups": null,
    "compiled": {
      "forwardEdges": [
        { "from": "agent-draft", "to": "human-review", "role": "always", "when": null },
        { "from": "human-review", "to": "agent-publish", "role": "approve", "when": { "op": "eq", "args": [{ "var": "output.decision" }, "approve"] } },
        { "from": "human-review", "to": "agent-rework", "role": "reject", "when": { "op": "eq", "args": [{ "var": "output.decision" }, "reject"] } }
      ],
      "loops": []
    },
    "triggers": null,
    "tags": null,
    "custom": null,
    "createdAt": 1731432000000,
    "updatedAt": 1731432000000,
    "status": "active"
  }
}
```

The read-only `compiled` block is added to every `DefinitionView` (create / get / list). `compiled.forwardEdges` is the runtime forward-edge list the engine drives execution from; `compiled.loops` is the derived loop region list. The authored `edges` still echo `sourceEdges` byte-for-byte. See [Get Definition](/docs/api-reference/rest-apis/v2/approval-engine/definitions/get-definition) for the full `compiled` schema.

#### Failure Response

```JSON theme={null}
{
  "error": {
    "message": "ERROR_MESSAGE",
    "status": "INVALID_ARGUMENT"
  }
}
```

**Errors:** `INVALID_ARGUMENT` (schema, `compileGraph`, or linter failure; message includes the validation key) / `ALREADY_EXISTS` (definitionId already in use).

<ResponseExample>
  ```js theme={null}
  {
    "result": {
      "definitionId": "marketing-copy-approval",
      "name": "Marketing copy approval",
      "description": null,
      "version": 1,
      "scope": { "level": "apiKey", "organizationId": null, "documentId": null },
      "nodes": [
        { "nodeId": "agent-draft", "type": "agent", "config": { "agentId": "copy-agent-v1", "urlPath": "documentUrl" } }
      ],
      "edges": [],
      "groups": null,
      "compiled": { "forwardEdges": [], "loops": [] },
      "triggers": null,
      "tags": null,
      "custom": null,
      "createdAt": 1731432000000,
      "updatedAt": 1731432000000,
      "status": "active"
    }
  }
  ```
</ResponseExample>
