> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokencraft.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete Workspace

> Permanently delete a workspace and all its data

# Delete Workspace

Permanently deletes a workspace and all its associated tokensets, modes, and tokens. This action cannot be undone.

<Note>
  **Write access policy** - This endpoint requires the `write:tokens` scope.

  * TEAM-owned workspace: `owner`, `admin`, `editor` can write; `viewer` is blocked (`403`).
  * Non-TEAM workspace: only the workspace owner can write.
  * If the workspace owner plan has no API write access (for example FREE), write is blocked.
</Note>

## Endpoint

```
DELETE /workspaces/{id}
```

## Authentication

Requires a valid API token in the Authorization header.

## Request

### Headers

| Header          | Value        | Required |
| --------------- | ------------ | -------- |
| `Authorization` | Bearer token | Yes      |

### Path Parameters

| Parameter | Type   | Required | Description  |
| --------- | ------ | -------- | ------------ |
| `id`      | string | Yes      | Workspace ID |

## Response

### Success Response

**Status:** `200 OK`

```json theme={null}
{
  "message": "Workspace deleted successfully"
}
```

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X DELETE https://app.tokencraft.dev/api/v1/workspaces/550e8400-e29b-41d4-a716-446655440000 \
    -H "Authorization: Bearer tkc_your_token_here"
  ```

  ```javascript JavaScript theme={null}
  const workspaceId = '550e8400-e29b-41d4-a716-446655440000';

  const response = await fetch(
    `https://app.tokencraft.dev/api/v1/workspaces/${workspaceId}`,
    {
      method: 'DELETE',
      headers: {
        'Authorization': 'Bearer tkc_your_token_here'
      }
    }
  );

  const result = await response.json();
  console.log(result.message);
  ```

  ```python Python theme={null}
  workspace_id = '550e8400-e29b-41d4-a716-446655440000'

  response = requests.delete(
      f'https://app.tokencraft.dev/api/v1/workspaces/{workspace_id}',
      headers={'Authorization': 'Bearer tkc_your_token_here'}
  )

  result = response.json()
  print(result['message'])
  ```
</CodeGroup>

## Error Responses

### 401 Unauthorized

```json theme={null}
{
  "error": "Invalid API token"
}
```

### 404 Not Found

```json theme={null}
{
  "error": "Workspace not found"
}
```

**Causes:**

* Workspace ID doesn't exist
* You do not have access to this workspace

### 500 Internal Server Error

```json theme={null}
{
  "error": "Failed to delete workspace"
}
```

## Cascade Deletion

When a workspace is deleted, the following are also deleted:

* ✅ All tokensets in the workspace
* ✅ All modes in those tokensets
* ✅ All tokens in those modes

<Warning>
  This operation is **irreversible**. All data will be permanently deleted. Make sure to export your tokens before deletion if you need a backup.
</Warning>

## Best Practices

### 1. Confirmation

Always confirm with the user before deletion:

```javascript theme={null}
async function deleteWorkspaceWithConfirmation(id) {
  const confirmed = confirm(
    'Are you sure? This will delete all tokensets and tokens. This action cannot be undone.'
  );
  
  if (!confirmed) return;
  
  await deleteWorkspace(id);
}
```

### 2. Export Before Deletion

Download all data before deletion:

```javascript theme={null}
async function safeDeleteWorkspace(id) {
  // Export all tokensets first
  const tokensets = await getWorkspaceTokensets(id);
  
  for (const tokenset of tokensets) {
    await exportTokenset(tokenset.id, 'json');
  }
  
  // Then delete
  await deleteWorkspace(id);
}
```

### 3. Archive Instead

Consider archiving instead of deleting:

```javascript theme={null}
// Update workspace name to indicate archived status
await updateWorkspace(id, {
  name: `[ARCHIVED] ${workspace.name}`
});
```

## Recovery

<Warning>
  **Deleted workspaces cannot be recovered.** There is no undo or trash bin. Make sure you have backups of important data.
</Warning>

## Next Steps

<CardGroup cols={2}>
  <Card title="Export Workspace Data" icon="download" href="/api-reference/export/tokenset">
    Export before deletion
  </Card>

  <Card title="List Workspaces" icon="list" href="/api-reference/workspaces/list">
    View all workspaces
  </Card>
</CardGroup>
