Token VaultDocs
Reference

Agent Credentials API

Reference for GET /api/agents/credentials, covering accepted keys, the 307 redirect and ticket, list mode, grant checks and the error catalogue.

GET /api/agents/credentials

Fetch a credential the caller holds a value grant on. Token Vault checks the key, the grant and your policies, then answers 307 to your webhook's /v1/credential. The client follows the redirect and the webhook returns the value directly to the caller.

Use a client that follows redirects (curl -L; Python requests does by default).

Loading diagram...

Request

curl -sL "https://api.tokenvault.uk/api/agents/credentials?service=github" \
  -H "Authorization: Bearer $TVAGENT_KEY"
ParameterInRequiredNotes
servicequerynoCredential name, for example github. Cannot contain / (400 INVALID_SERVICE). Omit it for list mode.

Authentication

IdentityHow to send itNotes
Agent key tvagent_...Authorization: Bearer tvagent_... onlyClassic and scoped agents. A scoped agent needs credentials:read. An x-agent-key header on this endpoint is refused (400 AGENT_KEY_HEADER_NOT_ACCEPTED): see the redirect note below.
Scoped API key tvkey_...Authorization: Bearer tvkey_... onlyNeeds credentials:read. Same 307.
OAuth session tvsess_...Authorization: Bearer tvsess_...Issued by the MCP OAuth flow. A session issued for another resource (an MCP server URL, for example) gets 401 WRONG_RESOURCE. An identity-only session gets 403 IDENTITY_ONLY_SESSION.

A ?key= query parameter is not accepted. A key in a URL ends up in every hop's request log and cannot be scrubbed.

The 307 response

307 Temporary Redirect
HTTP/1.1 307 Temporary Redirect
Location: https://hook.example.com/v1/credential?ticket=eyJzdWIiOiJ1c2VyXzEyMyIsInN2YyI6ImdpdGh1YiIs...&service=github
  • ticket is base64url(json).hex_hmac, signed with the webhook's HMAC secret. It lives 60 seconds, and the reference webhook refuses a reused nonce. Details: tickets.
  • The signed JSON holds the user (sub), the service (svc), the purpose (pur: agent_credential), iat, exp and a nonce. An agent call adds aid; a tvkey_ call has none. A creation id (cid) appears only for auto-derived grants on a webhook that advertises ticketConstraints.
  • Standard clients (curl -L, Go, Python requests) drop only Authorization and Cookie on a cross-host redirect. So send the key as Authorization: Bearer and it never reaches your webhook. A custom x-agent-key header would be sent on to the webhook host, so this endpoint answers any request carrying one with 400 AGENT_KEY_HEADER_NOT_ACCEPTED before it looks at the key.
  • The ticket is not a credential. It cannot be exchanged for anything else.

The webhook then answers (this response is not served by Token Vault):

200 OK from your webhook
{
  "token": {
    "accessToken": "ghp_...",
    "serviceName": "github",
    "tokenType": "PlainText",
    "createdAt": "2026-10-01T10:00:00Z"
  }
}

Fields depend on the credential type (JWT, PlainText, Certificate, SSHKey, RawCredential, TOTP, Composite). A TOTP credential returns a current one-time code. See raw credentials and TOTP.

If no webhook is bound you get 502 WEBHOOK_NOT_CONFIGURED.

List mode

Without service, Token Vault answers itself: no redirect and no credential material.

200 OK
{
  "grants": [
    { "serviceName": "github", "grantExpiresAt": null, "refreshPolicy": "none", "sourceGroupId": null },
    { "serviceName": "google", "grantExpiresAt": "2026-11-08T12:00:00+00:00", "refreshPolicy": "none", "sourceGroupId": null }
  ]
}
  • Expired grants are left out.
  • Rows carry no uses or servers (MCP servers). An MCP-only grant is listed like a value grant, and fetching it returns 403 GRANT_TOOLS_ONLY. See access.
  • sourceGroupId is a legacy field (folders became labels). It is null for new grants.
  • List mode runs the same key, scope and rate-limit checks as a fetch, plus the agent's own policies.

Grant check order

After the key resolves, Token Vault runs these checks in order. The first failure wins.

  1. Penalty-box lockout (429 RATE_LIMITED).
  2. Kill switch (423 VAULT_LOCKED), then agent status (403 AGENT_INACTIVE).
  3. Key expiry (401 KEY_EXPIRED) and scope (403 SCOPE_DENIED, missingScope: credentials:read).
  4. Floor and account rate limits (429 RATE_LIMITED).
  5. Grant: missing (404 NO_GRANT), lapsed (403 GRANT_EXPIRED), MCP-only (403 GRANT_TOOLS_ONLY).
  6. Policies on the caller, the credential and their labels (403 or 429 POLICY_DENIED).

A tvkey_ call resolves the key first (401 INVALID_KEY, 401 KEY_EXPIRED, 423 VAULT_LOCKED, 403 KEY_SUSPENDED, in that order), then checks the scope, then runs steps 1, 4, 5 and 6 against the key's own grants and policies.

A failed check that is the owner's doing (kill switch, suspended agent, MCP-only grant) never records a penalty-box strike.

Errors

Every code below uses the {"detail": {"code", "message"}} envelope except where marked. The full contract, including policy denial bodies for agents and humans, is on Denials. All HTTP codes are on Errors and exit codes.

HTTPcodeWhen
400INVALID_SERVICEservice contains /
401MISSING_KEYNo key in the headers
401KEY_EXPIREDThe scoped key or agent is past its expiry
401INVALID_KEYA scoped agent or tvkey_ key is revoked or stale
401WRONG_RESOURCEA tvsess_ issued for another resource
403INVALID_KEYUnknown, malformed or rotated-out classic tvagent_ key (kept for existing agents)
403AGENT_INACTIVEAgent is suspended or deleted
403KEY_SUSPENDEDA tvkey_ key is suspended
403SCOPE_DENIEDA scoped caller lacks credentials:read; missingScope names it
403IDENTITY_ONLY_SESSIONThe tvsess_ session cannot read credentials
404NO_GRANTNo live grant for service. Same answer whether the credential exists or not
403GRANT_EXPIREDThe grant lapsed (it is deleted on this request)
403GRANT_TOOLS_ONLYThe grant lacks value. Message: "This grant does not allow reading the credential value; it can only be used through MCP access."
403 / 429POLICY_DENIEDA policy refused. Top-level body, see Denials
423VAULT_LOCKEDYou stopped all access
429RATE_LIMITEDFloor, penalty box, no-grant miss limit or account ceiling. Top-level body with retryAfter and a Retry-After header
502WEBHOOK_NOT_CONFIGUREDNo webhook bound
404 NO_GRANT
{ "detail": { "code": "NO_GRANT", "message": "No grant for service 'stripe'" } }
429 RATE_LIMITED (top-level body, not the detail envelope)
{ "error": "Rate limit exceeded", "code": "RATE_LIMITED", "retryAfter": 41 }

Rate limiting

Four layers run before the grant check. Numbers: Rate limits.

  1. Penalty box. An agent that keeps tripping the floor gets an escalating lockout (1 s, 2 s, 4 s, capped at 15 minutes). A lockout blocks every credential request from that agent, not just one service.
  2. Floor. 60 requests a minute per agent or key (agent_credentials). Exceeding it strikes the penalty box.
  3. Account ceiling. One ceiling across all agents, sized from your active agents.
  4. No-grant miss limit. 10 misses a minute per agent for NO_GRANT and GRANT_EXPIRED. A miss is never a strike, so a typo cannot lock an agent out of services it does hold.

This endpoint and /api/agents/mcp share one counter per agent.

If your webhook is offline the agent's redirect fetch fails at the webhook. That is the kill switch working as designed.

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