# Update a key

`PATCH https://api.llm.buzz/api/v1/keys/{hash}`

Changes a key's `name`, `disabled`, `limit` or `limit_reset`. A body that sets none of them answers 400 `invalid_request`; `include_byok_in_limit` and unknown fields are ignored.

Authentication: a management key, created on the console's Keys page, as `Authorization: Bearer KEY`; the samples read it from `$LLM_BUZZ_MANAGEMENT_KEY`.

## Parameters

- `hash` (path string, required): The key's `hash`, as `GET /api/v1/keys` lists it.

## Body

- `name` (string): 1 to 64 characters.
- `disabled` (boolean): `true` disables the key, `false` enables it again.
- `limit` (number): A spending limit in US dollars, at most nine decimal places; `null` for none.
- `limit_reset` (string, one of `daily`, `weekly`, `monthly`): The limit's period in UTC, a week starting on Monday; `null` counts the key's whole life.

## Responses

- 200: The changed key, as `{"data": ...}`.
- 400: The body is not JSON (`invalid_json`), a field or query value is invalid (`invalid_parameter`, with `metadata.param`), or a `PATCH` sets no field (`invalid_request`).
- 401: No `Authorization` header (`missing_authentication`), or the key is unknown, expired, revoked or disabled (`invalid_key`).
- 403: An inference key called a route that takes a management key. Create one on the console's Keys page.
- 404: The hash names none of your inference keys.

## Example (curl)

```bash
curl -X PATCH https://api.llm.buzz/api/v1/keys/{hash} \
  -H "Authorization: Bearer $LLM_BUZZ_MANAGEMENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "limit": 10,
  "limit_reset": "weekly"
}'
```

## Example response

```json
{
  "data": {
    "hash": "...",
    "name": "CI key",
    "label": "CI key",
    "disabled": false,
    "created_at": "...",
    "updated_at": null,
    "expires_at": null,
    "last_used_at": null,
    "limit": 5,
    "limit_remaining": 5,
    "limit_reset": "monthly",
    "include_byok_in_limit": false,
    "usage": 0,
    "usage_daily": 0,
    "usage_weekly": 0,
    "usage_monthly": 0,
    "byok_usage": 0,
    "byok_usage_daily": 0,
    "byok_usage_weekly": 0,
    "byok_usage_monthly": 0,
    "creator_user_id": "...",
    "external_user": null,
    "workspace_id": "default"
  }
}
```
