# 取消 Commit 知識版本

此 API 用於取消提交指定的 Fileset，一旦執行取消，系統會將 Fileset 的狀態改變為 `cancelled`，並停止後續的處理。取消後的 Fileset 可以修改檔案清單或重新 Commit。  
**限制條件：**

- 僅能在 Fileset 狀態為 `queued` 或 `processing` 時取消。

- 對已經是 `cancelled` 的 Fileset 再次呼叫，會直接回傳成功（可重複呼叫）。

- 狀態為 `draft`、`completed`、`failed`、`partial_failed` 時呼叫，會回傳 `FILESET_009`（409）。

- 若 commit 在取消送達前就已處理完成，也會回傳 `FILESET_009`，回應中的 `state` 為該 Fileset 的最新狀態（例如 `completed`）。

- 取消 commit 不會發送 Commit 時設定的 Webhook 通知。

```bash
curl -X 'DELETE' \
  'http://127.0.0.1:8000/v1/filesets/{fileset_id}/commit' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $PRIVAI_API_KEY"
```

#### Request Headers

| Key | Value |
| --- | --- |
| Request Method | DELETE |
| accept | application/json |
| Authorization | `Bearer $PRIVAI_API_KEY` |

#### Path Parameters

| Field | Type | Note | Required |
| --- | --- | --- | --- |
| fileset_id | string | uuid | true |

#### Response Body

```json
{
  "detail": "Successfully cancelled fileset with ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
```

#### 常見錯誤代碼

| Error Code | HTTP Status | 情境 |
| --- | --- | --- |
| FILESET_001 | 404 | 指定的 Fileset 不存在 |
| FILESET_009 | 409 | Fileset 狀態不允許取消（非 `queued`／`processing`／`cancelled`），回應中帶 `state` |

身份驗證錯誤（`AUTH_001`～`AUTH_003`）詳見「錯誤代碼說明-身份驗證類」章節；知識版本相關錯誤碼完整說明請參考 [錯誤代碼說明-知識版本管理類](https://privstation-docs.apmic.ai/latest/privai-400/錯誤代碼說明-知識版本管理類.md)。
