# API keys

> List, make, rename, rescope, extend, revoke and read usage for the API keys on your account.

API reference · Reference · https://wxalerts.org/docs/api/api-keys/

Base URL: `https://api.wxalerts.org`

These routes manage the keys you send to the [`/v1` routes](/docs/api/rest/).
The how-to is [Make, send and revoke an API key](/docs/developers/api-keys/),
and how a key is sent and limited is under
[Authentication](/docs/developers/authentication/).

They are account routes: a signed-in session or the phone's Bearer token, with
the CSRF header on a cookie request that changes something. See
[Sessions, Bearer and CSRF](/docs/api/sign-in/#sessions-bearer-and-csrf) for the
shared rules and errors. An API key can never call these routes, so a leaked
key cannot make more keys or keep itself alive.

Every response here is `Cache-Control: no-store`.

## Scopes

| Scope | Opens | Who may hold it |
| --- | --- | --- |
| `alerts:read` | active and ended alerts, alert pages and the stats summary | any account |
| `weather:read` | forecasts, conditions, stations, soundings and the sky outlook | any account |
| `outlooks:read` | SPC outlooks, tropical cyclones and WPC winter products | any account |
| `storms:read` | storm cells, tracks, cones and lightning | any account |
| `reports:read` | local storm reports | any account |
| `locations:read` | place search | any account |
| `placefile:read` | the full spotter report placefile | meteorologist accounts only |

A key made without `scopes` gets every scope except `placefile:read`. Scopes
are stored in the order above.

## `GET /account/api-keys`

Your keys, the scopes you may use, and the limit. Session or Bearer. A meteorologist's personal
placefile keys are listed here too, because they are API keys that hold only
`placefile:read`.

| Field | Type | Description |
| --- | --- | --- |
| `keys` | array | every key on the account, revoked ones included |
| `keys[].id` | integer | key id, used in the other routes |
| `keys[].prefix` | string | the first 12 characters of the key, for recognising it. The rest is never shown again |
| `keys[].label` | string or null | name you gave it |
| `keys[].scopes` | array of string | what the key can read |
| `keys[].created_at` | string | |
| `keys[].expires_at` | string or null | `null` means it never expires |
| `keys[].last_used_at` | string or null | updated at most about once a minute |
| `keys[].revoked_at` | string or null | set once revoked |
| `keys[].requests_30d` | integer | requests in the last 30 days (today and the 29 days before). Counts trail by up to a minute |
| `scopes` | array | every scope with `scope`, `description` and `allowed`, whether this account may put it on a key |
| `max_live_keys` | integer | 10 |

```json
{
  "keys": [
    { "id": 41, "prefix": "wx_live_Qp7a", "label": "dashboard", "scopes": ["alerts:read", "weather:read"],
      "created_at": "2026-11-01T12:00:00Z", "expires_at": "2026-12-01T12:00:00Z",
      "last_used_at": "2026-11-23T16:58:00Z", "revoked_at": null, "requests_30d": 8123 }
  ],
  "scopes": [ { "scope": "alerts:read", "description": "Active and ended alerts, alert pages and the stats summary", "allowed": true },
              { "scope": "placefile:read", "description": "The full spotter report placefile, for meteorologists", "allowed": false } ],
  "max_live_keys": 10
}
```

## `POST /account/api-keys`

Makes a key. Session or Bearer. Answers `201`. The response is the only time the key is shown.
It is stored only as a hash and cannot be recovered, so a lost key is revoked
and replaced.

Body (JSON, every field optional):

| Field | Type | Default | Bounds |
| --- | --- | --- | --- |
| `label` | string or null | `null` | at most 80 characters. Labels that start with `ADMIN::` (any case) are reserved for staff |
| `scopes` | array of string or null | every scope except `placefile:read` | at most 16 entries, each one of the scopes above. Names that are not scopes are refused |
| `expires_in_days` | integer or null | 30 | 1 to 3650. An explicit `null` makes a key that never expires |

Response `201`: the key object from the list, with `requests_30d` of `0`, plus:

| Field | Type | Description |
| --- | --- | --- |
| `key` | string | the clear key, `wx_live_` then 43 characters (`wx_test_` outside production) |

```json
{ "id": 42, "prefix": "wx_live_Zk3m", "label": "script", "scopes": ["alerts:read"],
  "created_at": "2026-11-23T17:00:00Z", "expires_at": "2026-12-23T17:00:00Z",
  "last_used_at": null, "revoked_at": null, "requests_30d": 0,
  "key": "wx_live_Zk3m..." }
```

| Status | Body | When |
| --- | --- | --- |
| `409` | `{"detail": {"code": "too_many_keys", "message": "Revoke a key first: 10 is the most at once."}}` | 10 live keys already |
| `422` | `{"detail": {"code": "scope_not_allowed", "message": "...", "scopes": ["placefile:read"]}}` | a scope that is unknown or that this account may not hold |
| `422` | `{"detail": {"code": "label_reserved", "message": "..."}}` | a label starting `ADMIN::` |
| `422` | default list | `label` too long, `expires_in_days` out of range, more than 16 scopes |

## `PATCH /account/api-keys/{key_id}`

Renames, rescopes or extends a live key. Session or Bearer. The key value never changes. A change
reaches every server within about a minute.

| Name | In | Type | Bounds |
| --- | --- | --- | --- |
| `key_id` | path | integer | 1 to 9223372036854775807 |

Body: `label` (string or null, at most 80) and `scopes` (array or null, at most
16). A field that is omitted or `null` is left as it is. Sending `scopes: []`
sets a key with no scopes.

To extend a key, send `expires_in_days` (integer 1 to 3650, or `null`). The new
expiry is that many days from now, not from the old expiry; `null` makes the key
never expire. Unlike `label` and `scopes`, an explicit `null` here is a change:
leave the field out to keep the expiry as it is. Extending also re-arms the
[expiry email](#expiry-email) for the new date.

```json
{ "expires_in_days": 90 }
```

Response `200` is the key object. Errors as for creating, plus:

| Status | Body | When |
| --- | --- | --- |
| `404` | `{"detail": "No such live key."}` | not your key, already revoked, or (when `expires_in_days` is sent) already expired. An expired key cannot be brought back: make a new one |

## Expiry email

Seven days before a key expires, the account's email address gets one message
naming the key (its label and prefix) and the expiry time, with a link to
Credentials on your account page, where **Extend** sets a new expiry. Keys of one
account that are due together share one message. A key gets one email per
expiry date; extending it means another before the new date. No email goes out
in a key's first day, and revoked keys and keys that never expire get none.

## `DELETE /account/api-keys/{key_id}`

Revokes a key. Session or Bearer. Answers `204`. Revoking twice is fine. It stops working within about a
minute everywhere.

| Status | Body | When |
| --- | --- | --- |
| `404` | `{"detail": "No such key."}` | not your key |

## `GET /account/api-keys/{key_id}/usage`

Daily request counts for one key. Session or Bearer.

| Name | In | Type | Default | Bounds |
| --- | --- | --- | --- | --- |
| `key_id` | path | integer | | 1 to 9223372036854775807 |
| `days` | query | integer | 30 | 1 to 400. Today counts as day one |

Response `200`: an array with one row per day and route group.

| Field | Type | Description |
| --- | --- | --- |
| `day` | string | `YYYY-MM-DD`, UTC |
| `route_group` | string | the kind of route called, for example `alerts` or `weather` |
| `requests` | integer | requests that day |
| `throttled` | integer | of those, how many were refused with `429` |

```json
[ { "day": "2026-11-22", "route_group": "alerts", "requests": 1420, "throttled": 0 } ]
```

| Status | Body | When |
| --- | --- | --- |
| `404` | `{"detail": "No such key."}` | not your key |
| `422` | default list | `days` out of range |
