Skip to content

feat(web): carry a key's request limits in the Add to ThinkWatch Lite link - #115

Merged
fylorn merged 1 commit into
devfrom
feat/add-to-lite-limits
Oct 20, 2026
Merged

fylorn merged 1 commit into
devfrom
feat/add-to-lite-limits

Conversation

@fylorn

@fylorn fylorn commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

The rotated-key dialog's Add to ThinkWatch Lite link now carries the key's own request limits in ThinkWatch Lite's limits import-link parameter (Lite 2026.10.26+), where they mean the same limit there.

Mapping

  • Only the key's own enabled, unexpired ai_gateway rules with metric: requests.
  • Sliding windows of whole minutes up to 60 become Lite's rolling minute window with every = minutes; whole hours up to 24 become hour with every = hours (60 s → minute, 300 s → minute|…|5, 3600 s → hour, 18000 s → hour|…|5, 86400 s → hour|…|24). Other windows, including the sliding 7 days, are left out: Lite's day/week/month are calendar periods.
  • Token rules are left out. The gateway adds weighted tokens to a token window (crates/gateway/src/proxy/accounting.rs, weighted_tokens fed to sliding::record; weights in crates/common/src/limits/weight.rs: per-model input/output weights, cache reads at 0.1x input and cache writes at 1.25x/2x by default), while Lite counts plain tokens with cache reads either fully in or out. No cache_reads setting gives the same number.
  • Budgets (weighted tokens per calendar period), MCP rules and the owner's/team's limits are not included.
  • Two rules on one window keep the smaller count. Above 16 windows, the 16 with the lowest requests-per-second rate stay (a looser rate is the likelier to be implied by a tighter one). Entries are ordered shortest window first, and every is omitted when it is 1.
  • No mapped rule: the parameter is omitted, and the link still works with Lite 2026.10.16.

UI

  • AddToLite takes an optional keyId. With it and rate_limits:read, it reads GET /api/admin/limits/api_key/{id}/rules (cached under the key-limits query key, so edits refresh it). Until the answer arrives, and on 403 or any error, the link is built without limits; the button is never held back.
  • When the link carries limits, a line under the button (also its accessible description) says the link includes the key's request-count limits and opens in ThinkWatch Lite 2026.10.26 or later, and the "Install first" link names 2026.10.26.
  • The rotate dialog passes the new key's id (limits belong to the key lineage, so they carry over). The create dialog and first-run setup pass none: a new key has no limits of its own yet.

Tests

  • lite-link.test.ts: each console window, other whole-minute/hour windows, unmapped windows, token rules, disabled/expired/MCP rules, out-of-range counts, duplicate windows, more than 16 windows, none, and the encoding (| → %7C, ; → %3B).
  • api-keys.test.tsx: rotated-key dialog with mapped limits (link, description, install version), with no mapped rule, with a 403, and without rate_limits:read.
  • Locally: pnpm check:i18n, pnpm lint, pnpm test, pnpm build all pass. No Rust changes.

🤖 Generated with Claude Code

… link

The rotated-key dialog reads the key's own rate-limit rules and puts the
ones Lite can hold exactly into the link's `limits` parameter: enabled,
unexpired AI-gateway request rules over whole minutes up to 60 or whole
hours up to 24 become Lite's rolling minute/hour windows. Token rules are
left out (the gateway counts weighted tokens, Lite plain ones), as are
sliding 7-day rules, budgets, MCP rules and the owner's limits. Duplicate
windows keep the smaller count; at most 16 windows, the lowest rates.

A link with limits needs Lite 2026.10.26, which the dialog states. When
the rules cannot be read the link is built without them, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn merged commit ff8ccf4 into dev Oct 20, 2026
7 checks passed
@fylorn
fylorn deleted the feat/add-to-lite-limits branch October 20, 2026 13:30
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant