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

# Set API Key Credit Limit

> Cap how many credits an API key can spend, or remove the cap.

## Authentication

Requires an API key in the `Authorization` header.

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

## Request

<ParamField body="id" type="string" required>
  The ID of the API key to update.
</ParamField>

<ParamField body="credit_limit" type="integer">
  The maximum number of credits this key may spend. Must be `>= 0`. Send `null`
  to remove the cap (unlimited usage).
</ParamField>

### Set a limit

```bash theme={"dark"}
curl -X POST https://encrata.com/api/agent/keys/limit \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"id": "key_abc123", "credit_limit": 5000}'
```

### Remove the limit (unlimited)

```bash theme={"dark"}
curl -X POST https://encrata.com/api/agent/keys/limit \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"id": "key_abc123", "credit_limit": null}'
```

## Response

<ResponseField name="message" type="string">
  Confirmation message.
</ResponseField>

<ResponseField name="credit_limit" type="integer">
  The newly-applied credit cap, or `null` when the cap was removed.
</ResponseField>

```json theme={"dark"}
{
  "message": "Credit limit updated",
  "credit_limit": 5000
}
```

<Note>
  Setting a limit requires a non-`readonly` role in the active workspace.
</Note>

<ResponseExample>
  ```json 200 theme={"dark"}
  {
    "message": "Credit limit updated",
    "credit_limit": 5000
  }
  ```

  ```json 400 theme={"dark"}
  {
    "error": "Credit limit must be a positive number"
  }
  ```

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

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

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