Revoke an API key
POST /v1/api-keys/{key_id}/revoke
| Property | Value |
|---|---|
| Operation | revoke_api_key |
| Group | API keys |
| Scope | api_keys:write |
| Route class | control |
| Idempotency | Idempotency-Key accepted: a retry with the same key replays the first answer |
| Audit | Audited identity.api_key.revoke (mutation) |
| Released in | 1.19.0 |
| Phase 0 host | Served (the hosted api pins 1.65.0) |
Revokes an API key of the caller's Organization. Every api instance refuses the key within 5 seconds (target), because the verified-key cache lives at most 3 seconds, and the key stays readable with status: revoked and revoked_at for the audit trail. Revoking a key that is already revoked or expired changes nothing and answers it as it stands. Session only (api.md section 2): the api refuses the route to every API key; Phase 0 accepts a Member ID token, so a Member signed in to the cockpit with api_keys:write makes the write.
Request
Set VOCAL_API to the base URL of your API and VOCAL_API_KEY to an API key with the api_keys:write scope (Authentication and keys). Replace each placeholder, such as agt_... or <name>, with your own value.
curl -X POST "$VOCAL_API/v1/api-keys/key_.../revoke" \
-H "Authorization: Bearer $VOCAL_API_KEY" \
-H "Idempotency-Key: $(uuidgen)"const response = await fetch(`${process.env.VOCAL_API}/v1/api-keys/key_.../revoke`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VOCAL_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(),
},
});
console.log(response.status, await response.text());import os
import uuid
import requests
response = requests.post(
f"{os.environ['VOCAL_API']}/v1/api-keys/key_.../revoke",
headers={
"Authorization": f"Bearer {os.environ['VOCAL_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
)
print(response.status_code, response.text)Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
key_id | path | ApiKeyId | yes | The id of an API key: key_ and the row's UUIDv7 in 26 Crockford base32 characters. Opaque and safe to log. |
idempotency-key | header | string | no | A client-chosen key, kept 24 hours per Organization, environment and route. A replay returns the stored response. |
Responses
| Status | Content type | Shape | Error codes |
|---|---|---|---|
200 | application/json | ApiKey | |
400 | application/json | ErrorEnvelope | invalid_request |
401 | application/json | ErrorEnvelope | unauthenticated |
403 | application/json | ErrorEnvelope | forbidden, org_suspended |
404 | application/json | ErrorEnvelope | not_found |
409 | application/json | ErrorEnvelope | idempotency_in_progress, idempotency_key_reused |
429 | application/json | ErrorEnvelope | rate_limited |
500 | application/json | ErrorEnvelope | internal_error |
Fields of the 200 answer
The shape is ApiKey.
| Field | Type | Required | Description |
|---|---|---|---|
created_at | Timestamp | yes | |
created_by | ActorRef or null | no | Who made the key (1.52.0): {type: member, id} for a key created through POST /v1/api-keys, {type: operator, id} for one the seed or an operator command made when the api records it, and null when it does not. Absent from an api before 1.52.0. A removed Member keeps its id here; the keys it made stay. |
environment | Environment | yes | |
expires_at | Timestamp or null | yes | |
id | ApiKeyId | yes | |
last_used_at | Timestamp or null | yes | |
name | string | yes | |
object | "api_key" | yes | |
prefix | string | yes | The non-secret start of the key, vk_<env>_<lookup>; the full key is vk_<env>_<lookup>_<secret>. |
revoked_at | Timestamp or null | yes | |
scopes | array of ApiKeyScope | yes | |
status | ApiKeyStatus | yes |