# Update API key

> Replaces the key's name, scopes and spending limit. The secret does not change, so live traffic keeps working.

`PUT /api-key/{id}`

**Auth:** API key or OAuth token

## Path parameters

- `id` (required, string) — The API key to update. Example `"ak_01KE7XWWEQ4MCGWKBQKJ1G47RP"`.

## Request body

- `scopes` (required, string[]) — ≥ 1 items.
- `spendingLimit` (required, number | null)
- `spendingLimitPeriod` (required, string | null) — One of: `"day"`, `"month"`, `"week"`.
- `name` (string | null) — ≥ 1 characters, ≤ 256 characters.

## Response

### 200 — API key updated

- `data` (required, object)
  - `id` (required, string)
  - `name` (required, string | null)
  - `scopes` (required, string[])
  - `spendingLimit` (required, string | null)
  - `spendingLimitPeriod` (required, string | null) — One of: `"day"`, `"month"`, `"week"`.

```json
{
  "data": {
    "id": "string",
    "name": "string",
    "scopes": [
      "generate"
    ],
    "spendingLimit": "string",
    "spendingLimitPeriod": "day"
  }
}
```

## Request samples

### cURL

```bash
curl -X PUT https://api.mynth.io/api-key/ak_01KE7XWWEQ4MCGWKBQKJ1G47RP \
  -H "Authorization: Bearer $MYNTH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "scopes": [
      "generate"
    ],
    "spendingLimit": 0,
    "spendingLimitPeriod": "day"
  }'
```

### JavaScript

```ts
const response = await fetch("https://api.mynth.io/api-key/ak_01KE7XWWEQ4MCGWKBQKJ1G47RP", {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.MYNTH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "scopes": [
      "generate"
    ],
    "spendingLimit": 0,
    "spendingLimitPeriod": "day"
  }),
});

const { data } = await response.json();
```

The full schema for this endpoint is in the [OpenAPI document](https://api.mynth.io/openapi.json).
