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).
Request
curl -sL "https://api.tokenvault.uk/api/agents/credentials?service=github" \
-H "Authorization: Bearer $TVAGENT_KEY"| Parameter | In | Required | Notes |
|---|---|---|---|
service | query | no | Credential name, for example github. Cannot contain / (400 INVALID_SERVICE). Omit it for list mode. |
Authentication
| Identity | How to send it | Notes |
|---|---|---|
Agent key tvagent_... | Authorization: Bearer tvagent_... only | Classic 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_... only | Needs 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
HTTP/1.1 307 Temporary Redirect
Location: https://hook.example.com/v1/credential?ticket=eyJzdWIiOiJ1c2VyXzEyMyIsInN2YyI6ImdpdGh1YiIs...&service=githubticketisbase64url(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,expand a nonce. An agent call addsaid; atvkey_call has none. A creation id (cid) appears only for auto-derived grants on a webhook that advertisesticketConstraints. - Standard clients (curl
-L, Go, Pythonrequests) drop onlyAuthorizationandCookieon a cross-host redirect. So send the key asAuthorization: Bearerand it never reaches your webhook. A customx-agent-keyheader would be sent on to the webhook host, so this endpoint answers any request carrying one with400 AGENT_KEY_HEADER_NOT_ACCEPTEDbefore 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):
{
"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.
{
"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
usesorservers(MCP servers). An MCP-only grant is listed like a value grant, and fetching it returns403 GRANT_TOOLS_ONLY. See access. sourceGroupIdis a legacy field (folders became labels). It isnullfor 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.
- Penalty-box lockout (
429 RATE_LIMITED). - Kill switch (
423 VAULT_LOCKED), then agent status (403 AGENT_INACTIVE). - Key expiry (
401 KEY_EXPIRED) and scope (403 SCOPE_DENIED,missingScope: credentials:read). - Floor and account rate limits (
429 RATE_LIMITED). - Grant: missing (
404 NO_GRANT), lapsed (403 GRANT_EXPIRED), MCP-only (403 GRANT_TOOLS_ONLY). - Policies on the caller, the credential and their labels (
403or429 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.
| HTTP | code | When |
|---|---|---|
| 400 | INVALID_SERVICE | service contains / |
| 401 | MISSING_KEY | No key in the headers |
| 401 | KEY_EXPIRED | The scoped key or agent is past its expiry |
| 401 | INVALID_KEY | A scoped agent or tvkey_ key is revoked or stale |
| 401 | WRONG_RESOURCE | A tvsess_ issued for another resource |
| 403 | INVALID_KEY | Unknown, malformed or rotated-out classic tvagent_ key (kept for existing agents) |
| 403 | AGENT_INACTIVE | Agent is suspended or deleted |
| 403 | KEY_SUSPENDED | A tvkey_ key is suspended |
| 403 | SCOPE_DENIED | A scoped caller lacks credentials:read; missingScope names it |
| 403 | IDENTITY_ONLY_SESSION | The tvsess_ session cannot read credentials |
| 404 | NO_GRANT | No live grant for service. Same answer whether the credential exists or not |
| 403 | GRANT_EXPIRED | The grant lapsed (it is deleted on this request) |
| 403 | GRANT_TOOLS_ONLY | The grant lacks value. Message: "This grant does not allow reading the credential value; it can only be used through MCP access." |
| 403 / 429 | POLICY_DENIED | A policy refused. Top-level body, see Denials |
| 423 | VAULT_LOCKED | You stopped all access |
| 429 | RATE_LIMITED | Floor, penalty box, no-grant miss limit or account ceiling. Top-level body with retryAfter and a Retry-After header |
| 502 | WEBHOOK_NOT_CONFIGURED | No webhook bound |
{ "detail": { "code": "NO_GRANT", "message": "No grant for service 'stripe'" } }{ "error": "Rate limit exceeded", "code": "RATE_LIMITED", "retryAfter": 41 }Rate limiting
Four layers run before the grant check. Numbers: Rate limits.
- 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.
- Floor. 60 requests a minute per agent or key (
agent_credentials). Exceeding it strikes the penalty box. - Account ceiling. One ceiling across all agents, sized from your active agents.
- No-grant miss limit. 10 misses a minute per agent for
NO_GRANTandGRANT_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.
Hardening your webhook
The rate limits Token Vault enforces for you, plus the webhook-side limits, kill switch and Cloudflare rules worth adding.
MCP Endpoint
Reference for POST /api/agents/mcp, Token Vault's own MCP server with five credential tools, tvagent_ or OAuth session auth, and the optional aggregated tool list.