Token VaultDocs
Reference

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.

RuleValue
Format^[a-z0-9-]{1,32}$
NormalisationTrimmed, lower-cased, de-duplicated (first occurrence wins)
Maximum per object10

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"
200 OK
{
  "labels": [
    { "label": "ai", "credentials": 2, "agents": 1, "keys": 0, "policyIds": ["3f9c1ae2b7d44e0f8a21c5d6e9b07a13"] },
    { "label": "prod", "credentials": 3, "agents": 0, "keys": 1, "policyIds": [] }
  ]
}
FieldTypeNotes
labelstring
credentials, agents, keysintegerHow many objects carry it. Revoked keys are not counted
policyIdsstring[]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.

PathValues
entityTypecredential, agent or api_key
entityIdThe credential name, the agent id, or the key id (up to 128 characters)
Body fieldTypeRequiredNotes
labelsstring[]yesThe 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"]}'
200 OK
{
  "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:

entityTypeScope
credentialtokens:update
agentagents:manage
api_keykeys: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

HTTPCodeWhen
400INVALID_ENTITY_TYPEentityType is not one of the three
400INVALID_ENTITY_IDentityId empty or over 128 characters
403SCOPE_DENIEDMissing the object's scope, or policies:write when removing a policy-bearing label. missingScope names it
403SELF_CHANGE_FORBIDDENA key or agent removing such a label from itself or a credential it holds
403WEB_CONSOLE_REQUIREDThe label's policy restricts channels
404(bare detail)Token '...' not found., Agent not found, or API key not found
422INVALID_LABELSNot a list, a bad label, or more than 10
423VAULT_LOCKEDYou stopped all access
422 INVALID_LABELS
{
  "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 ls

See 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.

On this page