# Change a key's role

Makes a key an Admin key or a Member key, at once, its open tokens too.

`PATCH /v1/keys/{id}` on `https://api.eu.vatis.tech`

> **Admin key only.** A Member key gets `403` `admin_only`. Roles: [Authentication and API keys](https://platform.vatis.tech/docs/authentication).

## Path parameters

| parameter | values | default | meaning |
|---|---|---|---|
| `id` | a key id, `key_...` | required | The key. |

## Headers

| header | values | default | meaning |
|---|---|---|---|
| `Authorization` | `Bearer <api key>` | required | An Admin key ([Roles](https://platform.vatis.tech/docs/authentication#roles)). A Member key gets `403` `admin_only`. |

## Body fields (`application/json`)

| field | values | default | meaning |
|---|---|---|---|
| `role` | `admin`, `member` | required | The key's role ([Roles](https://platform.vatis.tech/docs/authentication#roles)). |

## Response fields

| field | when | meaning |
|---|---|---|
| `id` |  | `key_` and 12 hex digits. |
| `name` |  | The key's name. |
| `prefix` |  | The key's first characters, to tell it apart. |
| `role` |  | `admin` or `member` ([Roles](https://platform.vatis.tech/docs/authentication#roles)). |
| `state` |  | `active`, `expired` or `revoked`. |
| `created_at` |  | When it was made: ISO 8601, UTC. |
| `last_used_at` |  | When it last made a request, or `null`: never used. |
| `expires_at` |  | When it stops: the start of the day after its last day, in UTC. `null`: no end. |
| `revoked_at` |  | When it was revoked, or `null`. |

## Responses

`200`: The key as it is now.

```json
{
  "id": "key_3f9c1a2b7d4e",
  "name": "crm-backend",
  "prefix": "vatis_sk_AbCdEf",
  "role": "admin",
  "state": "active",
  "created_at": "2026-11-12T09:14:03Z",
  "last_used_at": "2026-11-12T10:01:44Z",
  "expires_at": null,
  "revoked_at": null
}
```

`400` `missing_parameter`: No `role`.

`400` `invalid_parameter`: A field that is unknown or not valid, or a query parameter. The `param` names it.

`400` `invalid_request`: A body that is not a JSON object.

`401` `unauthorized`: No key, or a wrong, revoked or expired one.

```json
{
  "error": {
    "code": "unauthorized",
    "message": "Invalid, revoked or expired key.",
    "param": null,
    "request_id": "req_bf2fed760ba5437ba0933a57"
  }
}
```

`403` `admin_only`: A Member key.

`404` `not_found`: No key of your workspace has that id.

`409` `last_admin`: The workspace's last active Admin key cannot become a Member from code: make another key Admin first.

```json
{
  "error": {
    "code": "last_admin",
    "message": "This is the last active Admin key: make another key Admin first.",
    "param": null,
    "request_id": "req_bf2fed760ba5437ba0933a57"
  }
}
```

`409` `key_revoked`: The key is revoked.

`413` `request_too_large`: A JSON body over 64 KB.

`503` `unavailable`: The service is busy for a moment. Send the request again after the seconds of the `Retry-After` header.
