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

# Enable or Disable API Key

> Temporarily disable an API key or re-enable a disabled one.

## Authentication

Requires an API key in the `Authorization` header.

```bash theme={"dark"}
Authorization: Bearer YOUR_API_KEY
```

## Request

<ParamField query="id" type="string" required>
  The ID of the API key to enable or disable.
</ParamField>

<ParamField query="action" type="string" required>
  The action to perform. One of `disable` or `enable`.
</ParamField>

### Disable a key

```bash theme={"dark"}
curl -X PATCH "https://encrata.com/api/agent/keys?id=key_abc123&action=disable" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

### Re-enable a key

```bash theme={"dark"}
curl -X PATCH "https://encrata.com/api/agent/keys?id=key_abc123&action=enable" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Response

```json theme={"dark"}
{
  "message": "API key disabled"
}
```

<Note>
  Disabling is reversible re-enable the same key with `action=enable`. A disabled
  key immediately returns 401 on any request. Requires a non-`readonly` role in the
  active workspace.
</Note>

<ResponseExample>
  ```json 200 theme={"dark"}
  {
    "message": "API key disabled"
  }
  ```

  ```json 400 theme={"dark"}
  {
    "error": "Key ID and action (disable|enable) are required"
  }
  ```

  ```json 401 theme={"dark"}
  {
    "error": "Unauthorized"
  }
  ```

  ```json 403 theme={"dark"}
  {
    "error": "Insufficient permissions"
  }
  ```

  ```json 404 theme={"dark"}
  {
    "error": "API key not found"
  }
  ```
</ResponseExample>
