Packs / token-management-public
issue-scoped-api-tokens
Issue, scope, verify, rotate and revoke per-user/team API tokens (hashed at rest, shown once, admin-gated)
Install
logicpacks pack use token-management-public/issue-scoped-api-tokensget_pack token-management-public/issue-scoped-api-tokensThe second line is the MCP tool call for the LogicPacks connector (Claude Code, Codex, Claude.ai and others). The first run of a pack someone else wrote asks for your yes.
Keys it needs (names only)
- TOKENS_ADMIN_SECRET
Playbooks included
- Spec:
spec/SPEC.md(goal, steps, edge cases, don’ts) - Routes:
stdlib-sqlitelitellm-virtual-keys - Checks: 3 in
outcome/checks.yaml - Code:
tokens.py - Tools: python3
Usage, last 8 weeks
New: no recorded use yet.
Purpose (from spec/SPEC.md)
Issue, scope, verify, rotate and revoke per-user/team API tokens (hashed at rest, shown once, admin-gated)
Goal
A user or team gets an API token with only the scopes it needs; the token can be verified, rotated and revoked, and the raw value is never stored.
Steps
- Set TOKENS_ADMIN_SECRET (vault) on the server; only the admin path can issue/rotate/revoke.
- Issue:
tokens.py --db tokens.db issue <user> --team <team> --scopes read,llm [--ttl-min 120] [--cap-usd 5] [--rpm 60]; hand the raw token over once. - Verify on every request:
verify(raw, scope)-> ok / unknown / revoked / expired / scope / quota / rate. - Rotate:
rotate <id>issues a replacement with the same scopes and revokes the old one; Revoke:revoke <id>(idempotent). - Export:
list(no raw values) andusage-csvfor dashboards.
Edge cases
- Short-lived tokens: cap the TTL (24 h in our DSM pattern).
- Clock skew on expiry: compare server time only.
- A leaked token: revoke + rotate; the hash table makes lookups O(1) without storing secrets.
Don'ts
- Don't store or log raw tokens; don't accept a minted token on the admin path.
- Don't put tokens in URLs in production (headers only).