# Delete a workflow version

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Permanently deletes a `draft` version record under the specified workflow. Versions in `published` or `deprecated` status cannot be deleted; to retire a `published` version, call [Deprecate a workflow version](deprecate-workflow-version.md).

```text
DELETE https://api.moi.matrixorigin.cn/v5/workflow/v2/workflow-apps/{workflow_id}/versions/{version_id}
```

## Before you begin

1. Prepare a [personal access token](../../../../../../guides/genesis/api-keys.md#creating-and-managing-personal-access-tokens) with workflow version delete permission and the [target workspace ID](../../../../../../guides/ai-studio/resource-center/workspace.md#copy-the-workspace-id).
2. Call [List workflow versions](list-workflow-versions.md) or [Get workflow version details](get-workflow-version.md) to verify that the target version `Status` is `draft` and confirm that the workflow is not managed by an agent automation task.

## Request parameters

Replace `$AI_STUDIO_API_KEY`, `$WORKSPACE_ID`, `$WORKFLOW_ID`, and `$VERSION_ID` with actual values.

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
curl -X DELETE "https://api.moi.matrixorigin.cn/v5/workflow/v2/workflow-apps/$WORKFLOW_ID/versions/$VERSION_ID" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID"
```

:::::
:::::{tab-item} Parameters

### Path parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `workflow_id` | string | Yes | Target workflow ID, obtained from [List workflows](../list-workflows.md). |
| `version_id` | string | Yes | Draft version ID to delete (`Status` must be `draft`), obtained from [List workflow versions](list-workflow-versions.md). |

:::::
::::::
:::::::

## Successful response

Returns HTTP `200` and confirms that the draft version record has been deleted.

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "deleted": true
  }
}
```

:::::
:::::{tab-item} Fields

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` when the request succeeds. |
| `msg` | string | Result message; `OK` when the request succeeds. |
| `data` | object | Deletion result object. |
| `data.deleted` | boolean | Whether the version record has been deleted; `true` on success. |

:::::
::::::
:::::::

## Error response

Returns `404` (`ErrNotFound`) when the workflow does not exist, the version does not exist (including repeated deletion), or the version does not belong to the target workflow definition, and `409` (`ErrWorkflowUpdateManagedByAutomation`) when the workflow is managed by an agent automation task. Calling this endpoint on a `published` or `deprecated` version fails because only `draft` versions can be deleted.

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": "ErrNotFound",
  "msg": "Not Found"
}
```

:::::
:::::{tab-item} Fields

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | Error code, such as `ErrWorkspaceRequired`, `ErrForbidden`, `ErrNotFound`, `ErrWorkflowUpdateManagedByAutomation`, or `ErrServer`. |
| `msg` | string | Human-readable error message. |

:::::
::::::
:::::::
