> ## 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 Mode

> Permanently delete a mode and all its tokens

# Delete Mode

Permanently deletes a mode and all its associated 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 /tokensets/{id}/modes/{modeId}
```

## Request

### Path Parameters

| Parameter | Type   | Required | Description |
| --------- | ------ | -------- | ----------- |
| `id`      | string | Yes      | Tokenset ID |
| `modeId`  | string | Yes      | Mode ID     |

## Response

**Status:** `200 OK`

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

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X DELETE https://app.tokencraft.dev/api/v1/tokensets/tokenset-123/modes/mode-dark \
    -H "Authorization: Bearer tkc_your_token_here"
  ```

  ```javascript JavaScript theme={null}
  const tokensetId = 'tokenset-123';
  const modeId = 'mode-dark';

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

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

  ```python Python theme={null}
  tokenset_id = 'tokenset-123'
  mode_id = 'mode-dark'

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

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

## Error Responses

### 400 Bad Request

```json theme={null}
{
  "error": "Cannot delete the last mode in a tokenset"
}
```

<Note>
  A tokenset must always have at least one mode. You cannot delete the last remaining mode.
</Note>

### 404 Not Found

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

## Cascade Deletion

When a mode is deleted:

* ✅ All tokens in the mode are deleted

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

## Restrictions

### Cannot Delete Last Mode

```javascript theme={null}
// This will fail if only one mode exists
await deleteMode(tokensetId, lastModeId);
// Error: Cannot delete the last mode in a tokenset
```

**Solution:** Create a new mode before deleting:

```javascript theme={null}
// Create new mode first
const newMode = await createMode(tokensetId, { name: 'New Mode', is_default: true });

// Then delete old mode
await deleteMode(tokensetId, oldModeId);
```

## Best Practices

### Export Before Deletion

```javascript theme={null}
async function safeDeleteMode(tokensetId, modeId) {
  // Export mode first
  await exportMode(tokensetId, modeId, 'json');
  
  // Then delete
  await deleteMode(tokensetId, modeId);
}
```

## Next Steps

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

  <Card title="Create Mode" icon="plus" href="/api-reference/modes/create">
    Create a new mode
  </Card>
</CardGroup>
