# 刪除單一檔案

此 API 用於刪除指定的檔案（File）。  
透過提供檔案的 `file_id`，你可以將該檔案從系統中移除。不過，**若該檔案仍被包含於任何 Fileset 中，系統將阻止刪除操作，並回傳錯誤** `FILE_004`**。**  
請先透過「更新知識版本」API 將該檔案從所有 Fileset 中移除，或以「刪除知識版本」API 刪除相關 Fileset，才能成功執行刪除。狀態為 `queued`、`processing`、`completed` 的 Fileset 無法更換檔案清單，只能刪除該 Fileset。  
檔案刪除後將無法復原，也無法再被檢索或用於問答。

```bash
curl -X 'DELETE' \
  'http://127.0.0.1:8000/v1/files/{file_id}' \
  -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 |
| --- | --- | --- | --- |
| file_id | string | uuid | true |

#### Response Body

```json
{
  "id": "b0d1bdbc-4f94-40b0-9358-68c579c99e8c",
  "object": "file",
  "deleted": true
}
```

**Field Explanation**

| Field | Detail |
| --- | --- |
| id | 刪除之檔案 ID |
| object | 固定為 `file`（與 OpenAI 相容而保留） |
| deleted | 是否已刪除 |

#### 常見錯誤代碼

| Error Code | HTTP Status | 情境 |
| --- | --- | --- |
| FILE_002 | 404 | 指定的檔案不存在 |
| FILE_004 | 409 | 檔案仍被 Fileset 使用，回應中的 `fileset_ids` 列出使用中的 Fileset |

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