Skip to content

Users, Invite Codes & Weekly Token Quotas ​

Managing Users (users Collection) ​

users is an admin-managed PocketBase auth collection (all public CRUD API rules are locked to nil; clients interact solely via auth endpoints and /v1/*).

FieldTypeDescription
emailemail (unique)Login identity
passwordpasswordBcrypt hash (8–71 bytes)
verifiedboolEmail verification status
nametext(255)Optional display name
allowed_modelsrelation → upstream_modelsModels this user is permitted to route through
weekly_token_quotaint (>= 0)Maximum total tokens per UTC week (resets Monday 00:00 UTC); 0 means unlimited
settingsJSON (1 MiB)Per-user session and blacklist policy

Example users.settings:

json
{
  "session": {
    "max_sessions": 10,
    "compaction": {
      "keep_tokens": 20000,
      "trigger_ratio": 0.85
    }
  },
  "blacklist": ["rm -rf /", "mkfs *", "shutdown", "reboot"]
}

Revoking User Sessions ​

PocketBase auth tokens are stateless JWTs signed with users.tokenKey + collectionSecret (default 7-day duration):

  • Revoke a single user: Change the user's password or email in /_/ (rotates that user's tokenKey), or delete the user record.
  • Revoke all users: In /_/ → users → Edit collection → Options → Token options, click Invalidate all previously issued tokens.

Invite Codes & New-User Templates (invite_codes) ​

A single invite_codes collection controls both registration admission and initial account provisioning when users sign up at /register (POST /v1/register):

FieldTypeDescription
codetext(4..64), uniqueInvite code string (leave blank in Admin UI to auto-generate an 8-character uppercase alphanumeric code, or set a custom code like TEAM-SRE-2026)
enabledboolToggle code availability anytime
max_usesint (>= 0)Total redemptions allowed (0 = unlimited)
used_countint (>= 0)Atomically incremented inside the registration transaction
expires_atdate (UTC)Optional expiration timestamp (empty = never expires)
allowed_modelsrelation → upstream_modelsCopied onto newly registered users.allowed_models
weekly_token_quotaint (>= 0)Copied onto newly registered users.weekly_token_quota
settingsJSONCopied onto newly registered users.settings
notetext(255)Admin memo (e.g. campaign or team name)

Share prefilled registration URLs directly with teammates or testers:

text
https://aist.example.com/register?code=TEAM-SRE-2026

Daily Usage Metering & Weekly Quota Enforcement ​

Every successful 2xx upstream completion extracts token counts from usage (falling back to prompt_tokens + completion_tokens if total_tokens is omitted) and atomically upserts daily_model_usage:

FieldDescription
userRelation to users (cascade delete)
provider / modelPlain-text snapshots so deleting or renaming an upstream model never corrupts historical billing or active weekly quota totals
dateUTC date (YYYY-MM-DD)
requestsSuccessful completion count
prompt_tokens / completion_tokens / total_tokensCumulative token counts

Before forwarding a proxy request, if user.weekly_token_quota > 0, the server sums total_tokens in daily_model_usage for that user from Monday 00:00:00 UTC of the current week through today. Once reached, requests return HTTP 429 (code: "quota_exceeded") with retry_at set to next Monday 00:00:00 UTC (displayed in the user's local terminal timezone).

Licensed under AGPL-3.0 (Commercial licensing available: contact@aistrun.cc)