Labels API
Reference for GET /api/labels and PUT /api/labels/{entityType}/{entityId}, the endpoints that tag credentials, agents and API keys so policies can attach to the tag.
A label is a short tag on a credential, an agent or an API key. A policy attached to a label applies to every object that carries it, now and later.
A label never grants access. Grants stay explicit. For the concept and the web app, see Labels.
| Rule | Value |
|---|---|
| Format | ^[a-z0-9-]{1,32}$ |
| Normalisation | Trimmed, lower-cased, de-duplicated (first occurrence wins) |
| Maximum per object | 10 |
Labels are metadata in Token Vault's control plane. No credential value is read or written.
GET /api/labels
Every label in use. Scope: policies:read.
curl -s https://api.tokenvault.uk/api/labels -H "Authorization: Bearer $TVKEY"{
"labels": [
{ "label": "ai", "credentials": 2, "agents": 1, "keys": 0, "policyIds": ["3f9c1ae2b7d44e0f8a21c5d6e9b07a13"] },
{ "label": "prod", "credentials": 3, "agents": 0, "keys": 1, "policyIds": [] }
]
}| Field | Type | Notes |
|---|---|---|
label | string | |
credentials, agents, keys | integer | How many objects carry it. Revoked keys are not counted |
policyIds | string[] | Policies attached to the label, sorted |
A label that only has a policy attached (no objects yet) is listed with zero counts. Sorted by label.
PUT /api/labels/{entityType}/{entityId}
Replace one object's whole label set.
| Path | Values |
|---|---|
entityType | credential, agent or api_key |
entityId | The credential name, the agent id, or the key id (up to 128 characters) |
| Body field | Type | Required | Notes |
|---|---|---|---|
labels | string[] | yes | The new full set. [] clears the labels |
curl -s -X PUT https://api.tokenvault.uk/api/labels/credential/github \
-H "Authorization: Bearer $TVKEY" -H "Content-Type: application/json" \
-d '{"labels":["prod","ai"]}'{
"entityType": "credential",
"entityId": "github",
"labels": ["prod", "ai"],
"policies": [
{ "id": "3f9c1ae2b7d44e0f8a21c5d6e9b07a13", "label": "ai", "enabled": true, "name": "burst-60" }
]
}policies lists the policies that now apply to the object through its labels. name is included only when the caller holds policies:read.
Scopes
The route needs the kill switch off and one of tokens:update, agents:manage or keys:manage. The object's own kind needs its matching scope:
entityType | Scope |
|---|---|
credential | tokens:update |
agent | agents:manage |
api_key | keys:manage |
Removing a label that has a policy attached loosens that policy, so it also needs policies:write. Without it: 403 SCOPE_DENIED. A key or agent can never strip a policy-bearing label from itself or from a credential it holds a grant on (403 SELF_CHANGE_FORBIDDEN). If the policy has a Who can read rule, removing the label is web-app only (403 WEB_CONSOLE_REQUIRED).
Adding a label only tightens access, so it needs no policy scope.
Errors
| HTTP | Code | When |
|---|---|---|
| 400 | INVALID_ENTITY_TYPE | entityType is not one of the three |
| 400 | INVALID_ENTITY_ID | entityId empty or over 128 characters |
| 403 | SCOPE_DENIED | Missing the object's scope, or policies:write when removing a policy-bearing label. missingScope names it |
| 403 | SELF_CHANGE_FORBIDDEN | A key or agent removing such a label from itself or a credential it holds |
| 403 | WEB_CONSOLE_REQUIRED | The label's policy restricts channels |
| 404 | (bare detail) | Token '...' not found., Agent not found, or API key not found |
| 422 | INVALID_LABELS | Not a list, a bad label, or more than 10 |
| 423 | VAULT_LOCKED | You stopped all access |
{
"detail": {
"code": "INVALID_LABELS",
"message": "Invalid label 'Prod Env': use 1-32 lowercase letters, digits or hyphens.",
"missingScope": null
}
}A change records a LABELS_UPDATED event in Activity.
Attach a policy to a label
Policies are created in the web app. To attach one to a label use POST /api/policies/{policyId}/attach with an entityType of label:
curl -s -X POST https://api.tokenvault.uk/api/policies/3f9c1ae2b7d44e0f8a21c5d6e9b07a13/attach \
-H "Authorization: Bearer $TVKEY" -H "Content-Type: application/json" \
-d '{"attachments":[{"entityType":"label","entityId":"ai"}]}'Scope: policies:write.
CLI
tvault label set credential github prod ai
tvault label lsSee tvault CLI.
Ready to try it?
Sign in with Google or email. Your credentials stay on your own webhook, and the quickstart gets Claude Code making its first MCP tool call in about 15 minutes.
Grants API
Reference for the access endpoints that give agents and keys a credential, covering uses, MCP servers, expiry, find-or-create connect, revoke-all and the account-wide grants list.
MCP Servers API
Reference for the endpoints that attach MCP servers to a credential, refresh their cached tool lists, and list the built-in presets.