# Delete a workspace

Delete a specified workspace. Before deleting it, confirm that it is no longer needed and complete any required data-sharing cleanup. After a successful response, list workspaces to confirm that it no longer appears.

```text
DELETE https://moi.matrixorigin.cn/newmoi/workspaces/{id}
```

## Before you call this API

Identify the workspace to delete. Prepare a personal access token and the workspace ID.

The following example uses:

- `$AI_STUDIO_API_KEY`: Your personal access token, passed in the `X-API-Key` header.
- `$WORKSPACE_ID`: The workspace ID to delete, passed in the URL path.

If the workspace has associated data-sharing cleanup requirements, complete them before deletion.

## Request example

```bash
curl -X DELETE "https://moi.matrixorigin.cn/newmoi/workspaces/$WORKSPACE_ID" \
  -H "X-API-Key: $AI_STUDIO_API_KEY"
```

## Path parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | ID of the workspace to delete. |

## Successful response

On success, the API returns `200`, indicating that the service accepted the deletion. This response does not replace a subsequent list check.

```json
{
  "code": "OK",
  "msg": "OK"
}
```

Response fields:

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |

## Error response

```json
{
  "code": "ErrWorkspaceNotFound",
  "msg": "Workspace not found",
  "data": null
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status
  - Error code
  - Common cause
  - Recommended action
* - `400`
  - `INVALID_ARGUMENT`
  - The workspace ID is invalid.
  - Check the workspace ID in the path and retry.
* - `401`
  - `Unauthorized` or `UNAUTHENTICATED`
  - Credentials are missing or invalid.
  - Check the personal access token.
* - `403`
  - `ErrUserNotSynced` or `PERMISSION_DENIED`
  - The current identity has not been synchronized or cannot delete workspaces.
  - Complete account synchronization, or ask an administrator for access before retrying.
* - `404`
  - `ErrWorkspaceNotFound`
  - The workspace does not exist, or the current identity cannot access it.
  - Check the workspace ID and the current identity's permissions.
* - `409`
  - `data_share_workspace_delete_blocked`
  - The workspace's data-sharing cleanup is incomplete.
  - Complete the data-sharing cleanup, then retry deletion.
* - `503`
  - `data_share_workspace_delete_unavailable` or `UNAVAILABLE`
  - The data-sharing precheck or a dependent service is temporarily unavailable.
  - Retry later.
* - `500`
  - `ErrWorkspaceDeleteFailed`
  - The service could not delete the workspace.
  - Record the request time and error message, then retry.
```

## Next steps

Use the workspace name to [list workspaces](list-workspaces.md). Confirm the deletion only after the workspace no longer appears in the list.
