> ## Documentation Index
> Fetch the complete documentation index at: https://velt-v6-0-0-beta-2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Definition

Use this API to fetch a workflow definition. Returns the full `DefinitionView`. Filters out tombstoned definitions.

# Endpoint

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

# 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](/security/auth-tokens).
</ParamField>

# Body

#### Params

<ParamField body="data" type="object" required>
  <Expandable title="properties">
    <ParamField body="definitionId" type="string" required>
      The definition to fetch.
    </ParamField>

    <ParamField body="organizationId" type="string">
      Required when scoped to an organization or document.
    </ParamField>

    <ParamField body="documentId" type="string">
      Required when scoped to a document.
    </ParamField>
  </Expandable>
</ParamField>

## **Example Requests**

#### Get a definition

```JSON theme={null}
{
  "data": {
    "definitionId": "marketing-copy-approval"
  }
}
```

# 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" } },
      { "nodeId": "human-review", "type": "human", "config": { "reviewers": [{ "userId": "u_reviewer_01", "mandatory": true }] } },
      { "nodeId": "agent-publish", "type": "agent", "config": { "agentId": "publish-agent-v1" } },
      { "nodeId": "agent-rework", "type": "agent", "config": { "agentId": "rework-agent-v1" } }
    ],
    "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 `compiled` block

`compiled` is a read-only block on every `DefinitionView`. The authored `edges` echo `sourceEdges` byte-for-byte; `compiled` is the server-derived runtime view used to drive execution. Both are additive — render a workflow graph directly from `compiled.forwardEdges` instead of re-implementing group expansion client-side.

<ResponseField name="compiled" type="object">
  <Expandable title="properties">
    <ResponseField name="forwardEdges" type="array">
      The runtime forward-edge list. Group endpoints are expanded to per-member compiled edges and `on` roles are compiled to a predicate AST. Each entry:

      | Field         | Type                                                     | Notes                                             |
      | ------------- | -------------------------------------------------------- | ------------------------------------------------- |
      | `from`        | string                                                   | Resolved node id.                                 |
      | `to`          | string                                                   | Resolved node id.                                 |
      | `role`        | `approve` / `reject` / `always` / `exhausted` / `custom` | The authored `on` role.                           |
      | `when`        | `JsonAst \| null`                                        | Deterministic predicate AST; `null` for `always`. |
      | `fromGroupId` | string                                                   | Present when the authored `from` was a group.     |
      | `toGroupId`   | string                                                   | Present when the authored `to` was a group.       |
    </ResponseField>

    <ResponseField name="loops" type="array">
      The server-derived loop regions. Each entry:

      | Field           | Type                                | Notes                                                   |
      | --------------- | ----------------------------------- | ------------------------------------------------------- |
      | `loopId`        | string                              | Stable identifier for the derived loop.                 |
      | `entryNodeId`   | string                              | Node re-entered on each iteration.                      |
      | `bodyNodeIds`   | string\[]                           | Nodes inside the loop's iteration scope.                |
      | `maxIterations` | number                              | Hard cap per execution (from the reject edge's `loop`). |
      | `onExhausted`   | `{ routeToNodeId: string } \| null` | Sibling `on:"exhausted"` target, or `null`.             |
    </ResponseField>
  </Expandable>
</ResponseField>

#### Failure Response

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

**Errors:** `NOT_FOUND` (definition does not exist or is tombstoned) / `INVALID_ARGUMENT`.

<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" } }
      ],
      "edges": [],
      "groups": null,
      "compiled": { "forwardEdges": [], "loops": [] },
      "triggers": null,
      "tags": null,
      "custom": null,
      "createdAt": 1731432000000,
      "updatedAt": 1731432000000,
      "status": "active"
    }
  }
  ```
</ResponseExample>
