Integration API
API keys: expiry, rotation, editing
Keys are minted, listed, revoked and edited by a signed-in person (a session token), never by a key. The one thing a key may do to itself is rotate its secret.
Minting with an expiry#
POST /v1/graphs/{id}/keys
Authorization: Bearer <session token>
{"label": "Nightly sync",
"scope": {"groups": ["<group id>"],
"tools": ["stats", "search", "node", "neighbors", "subgraph",
"paths", "search_prose", "list_nodes", "list_edges",
"changes"],
"level": "full"},
"expiresAt": 1798761600}
{"keyId": "...", "token": "glk_...", "graphId": "...", "expiresAt": 1798761600}
token is the secret and is shown this once. expiresAt is optional: epoch
seconds, after now and at most ten years out, else 400 bad_expiry. After
that time every call with the key answers 401 key_expired. A revoked key
answers 403 revoked, whether or not it has also expired.
GET /v1/graphs/{id}/keys lists a graph's keys. Each row has keyId,
label, scope, createdAt, revokedAt, lastUsedAt, useCount,
expiresAt, rotatedAt, mintedBy (the account that created it, null for
a key older than this field) and principal
({"type": "user" | "service", "id", "name"?}: whose role and groups bound
the key). Fields with no value are null.
Rotation#
Rotating gives a key a new secret. Its id, scope and expiry do not change.
| Route | Caller | Overlap |
|---|---|---|
POST/v1/graphs/{id}/keys/{keyId}/rotate |
a session that may manage the key | default 0 s, at most a week |
POST/v1/keys/rotate |
the key itself, holding the rotate_key tool |
default 3600 s, at least 60 s, at most a week |
Body: {"overlapSeconds": n} (optional). Answer:
{"keyId": "...", "token": "glk_...", "graphId": "...",
"previousValidUntil": 1790003600}
The previous secret keeps working until previousValidUntil. A second
rotation inside that time ends the oldest secret at once.
Only the current secret may call /v1/keys/rotate:
- The previous secret answers
403 previous_secret, even while it still reads. Someone holding a leaked old secret cannot take the key over. - A session token, an OAuth token and an unknown token answer
401 unauthorizedthere. - A key without
rotate_keyanswers403 forbidden. - If the answer to a rotation is lost, the old secret still reads for the overlap, but it can no longer rotate. Have a person rotate the key from a session to get a new secret.
- If a person rotates the key while a self-rotation is still in flight, the self-rotation is refused.
Editing a key#
PATCH /v1/graphs/{id}/keys/{keyId} (session only) with any of:
| Field | Meaning |
|---|---|
label |
a new label |
expiresAt |
a new expiry; 0 clears it |
addTools |
names from list_nodes, list_edges, changes, export, extract, webhooks, rotate_key. Anything else answers 400 scope_too_wide, as does a tool the key's principal could not hold on an organisation graph |
Tools are only added, and nothing else in the scope changes. The answer is the key as the list shows it. This is how an existing key gains listing or the change feed without being replaced.
Who may rotate or edit#
- Personal graph: its owner.
- Organisation graph: an owner, for any key. An admin, for a key that is
their own. An admin, for another key, only when they hold every group that
key reaches; otherwise
409 scope_exceeds_yours. A key that names no groups follows its principal's groups, and while that person is not a member of the organisation only an owner may rotate or edit it.
Revoking (DELETE /v1/graphs/{id}/keys/{keyId}) is open to any owner or
admin.