Skip to content

[Request]: bearer quota follow-ups: per-key budget override and RateLimit fields on allowed responses #703

Closed

Description

@jimhoyd

Problem or use case

#572 added a per-credential quota to auth bearer routes: auth: {bearer: {scopes, quota: {requests, window}}}. Two gaps remain:

  1. Budgets are per route, not per key. Hosted-API evidence in [Request]: throttle partition keyed by credential, with a shared or durable counter store #572 described per-token quotas, where different tokens get different plans. Today every key on a route gets the same budget. The workaround is to issue keys against separate routes with different budgets, which does not fit plan tiers well.
  2. Allowed responses carry no credential RateLimit fields. An extension authorize() hook can only refuse, so a client learns its remaining credential budget only when it gets the 429. Core throttle adds RateLimit to every response.

Proposed behavior and alternatives

  1. An optional quota on the issued key record (issueApiKey({name, scopes, quota}), CLI JSON on stdin), stored in auth_api_keys. The route budget and the key budget would apply independently (both counted, either can refuse), or the key budget would replace the route's. This needs a decision.
  2. Implement auth's middleware() hook on bearer routes so allowed responses get RateLimit: "credential";r=..;t=... Check how this interacts with cache on protected routes, and with [Bug]: core throttle's response phase overwrites RateLimit fields on an extension's 429 #701 (throttle replaces RateLimit fields).

Not implemented in the #572 PR, to keep that change small.

Activity

  1. added
    enhancement
    on Sep 25, 2026
  2. added
    needs-decision
    on Sep 25, 2026
  3. jimhoyd commented on Sep 25, 2026

    @jimhoyd
    CollaboratorAuthor

    Decision (owner, 2026-09-25):

    1. Per-key budget replaces the route budget. When an issued key carries its own quota, that key is counted against its own budget only, and the route's auth.bearer.quota applies to keys without one. A server-wide ceiling remains available through core policies.throttle, which is independent of the auth quota and still applies to every request.
    2. Allowed responses carry the credential RateLimit fields. Implement auth's middleware() hook on bearer routes so allowed responses get RateLimit: "credential";r=..;t=.. (and RateLimit-Policy). These values are per credential, so they must never be stored in or served from a shared cache. [Bug]: core throttle's response phase overwrites RateLimit fields on an extension's 429 #701 is fixed in fix(core): name the failing field in validation errors and keep extension RateLimit policies (#702, #696, #701) #720, so throttle's "default" member now sits alongside the credential one.

    Ready to implement. Removing needs-decision.


    Generated by Claude Code

  4. removed
    needs-decision
    on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions