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

> Permanently delete a token

# Delete Token

Permanently deletes a design token. 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}/tokens/{tokenId}
```

## Request

### Path Parameters

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

## Response

**Status:** `200 OK`

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

## Examples

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

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

  const response = await fetch(
    `https://app.tokencraft.dev/api/v1/tokensets/${tokensetId}/modes/${modeId}/tokens/${tokenId}`,
    {
      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-light'
  token_id = 'token-123'

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

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

## Error Responses

### 404 Not Found

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

<Warning>
  This operation is **irreversible**. The token will be permanently deleted. Consider exporting your tokens before deletion.
</Warning>

## Considerations

### 1. Alias Dependencies

If other tokens reference this token as an alias, they will break. Check for dependencies first:

```javascript theme={null}
async function safeDeleteToken(tokensetId, modeId, tokenId, tokenName) {
  // Get all tokens
  const { tokens } = await getTokens(tokensetId, modeId);
  
  // Check for aliases
  const aliases = tokens.filter(t => t.alias_to === tokenName);
  
  if (aliases.length > 0) {
    console.warn(`Warning: ${aliases.length} tokens reference this token`);
    console.log('Aliases:', aliases.map(t => t.name));
    
    // Option 1: Delete aliases first
    for (const alias of aliases) {
      await deleteToken(tokensetId, modeId, alias.id);
    }
  }
  
  // Then delete the token
  await deleteToken(tokensetId, modeId, tokenId);
}
```

### 2. Batch Deletion

Delete multiple tokens:

```javascript theme={null}
async function deleteTokens(tokensetId, modeId, tokenIds) {
  for (const tokenId of tokenIds) {
    await deleteToken(tokensetId, modeId, tokenId);
  }
}

// Usage
await deleteTokens('tokenset-123', 'mode-light', [
  'token-1',
  'token-2',
  'token-3'
]);
```

### 3. Export Before Deletion

```javascript theme={null}
async function exportAndDelete(tokensetId, modeId, tokenId) {
  // Get token details first
  const token = await getToken(tokensetId, modeId, tokenId);
  
  // Save to backup
  fs.writeFileSync(
    `backup-${token.name}.json`,
    JSON.stringify(token, null, 2)
  );
  
  // Then delete
  await deleteToken(tokensetId, modeId, tokenId);
}
```

## Recovery

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

## Next Steps

<CardGroup cols={2}>
  <Card title="Create Token" icon="plus" href="/api-reference/tokens/create">
    Create a new token
  </Card>

  <Card title="Export Tokens" icon="download" href="/api-reference/export/mode">
    Export before deletion
  </Card>
</CardGroup>
