Repository navigation
feat(ai-gateway): manage accounts over REST, group them by state - #4999
Merged
Merged
Conversation
An account's quota and its credential were two facts the reader had to put together. `status` said whether the token worked and the windows said how much was spent, but neither said when a spent account could take work again, and the panel drew every window's clock alike, so a session resetting in five minutes beside a spent week read as "back in five minutes". `deriveAccountState` turns a reading and a clock into one of `available`, `limited`, `expired` or `error`, plus `limitedUntil`: the LATEST rollover among the spent session and weekly windows. A per-model cap never limits the account, a rollover already behind the clock stops blocking at once, a spent window with no stated rollover makes the return unknown rather than guessed, and the vendor's own limit flag limits an account no window explains. The account view carries the state, the return and a `blocking` flag per window, and marks a reading stale once a window has rolled over since it was read. Nothing is persisted, so the stored document, and a roll back to an older gateway, are untouched. The service also answers one account (`get`).
The pool could be read and changed only through the panel, which asks nothing
because whatever fronts the gateway decides who reaches it. A script has no
such front door.
`/api/v1` is its own prefix with a guard on every route:
- `GET /accounts` and `GET /accounts/{id}` take the token key, or the admin
key, and answer what the panel shows (state, return time, windows) and
never a credential. `?provider=` and `?state=` narrow the list.
- Starting and completing an authorization, and removing an account, take
`AI_GATEWAY_ADMIN_API_KEY` only and answer 403 `control_disabled` while the
gateway has none. Adding an account puts a subscription into the pool the
platform draws from, which the token key was deliberately never able to do.
Setting both variables to one value runs the gateway with one key.
- A script is never offered a redirect flow: the origin a loopback redirect
is chosen from cannot be sent over this door.
- Every change that went through leaves one log line carrying only ids the
gateway itself vouches for.
The panel's own routes stay keyless and `/api/v1` is never keyless; the e2e
spec and the container test both assert the 401.
Rows sit by vendor, then by what each account is doing (available, limit
reached, needs reauthentication, last call failed) and inside a limit by who
is back soonest. The Status filter and the search know the same four states.
The Status cell says it in words ("Limit reached", "Resets in 3 days") and
the Resets column reads the one window that decides the return in full
strength while the windows that only wait behind it step back. The green
"back soon" tint now belongs to an account's own return inside the hour, not
to any window that happens to reset within it. A limited row is greyed as
before, but its Status and Resets cells are not: they are why it is grey and
when it stops being. A reading that is both stale and on a greyed row is
dimmed once, not twice.
The strip carried the Tale mark, a slash and the name in 14px medium, which made it the one screen whose title looked unlike "Automations" or "Knowledge". The mark goes, since the name already says whose panel this is, and the title is the platform's own `AdaptiveHeaderTitle`, on the `bg-background/80` blur and the `px-4` gutter the table below keeps, so the title and the table start on one edge.
README: the REST section (the two keys, the routes, the `state` vocabulary and how it differs from the token endpoints' `available`), the admin key in the configuration table, the grouped rows and the platform-style strip. Manual layer: boxes ACCT-48 to ACCT-52, the reworded ones (ACCT-2, 13, 27, 28, 35, 47 and SMOKE-9, 11, 15), the pins that say why, the new error codes, the register rows for what the specs own, and the admin key in setup.
yannickmonney
added this pull request to the merge queue
Oct 15, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 15, 2026
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Five asks for the AI gateway panel and API, in one PR:
/api/v1. The token key reads; a separate, optional admin key changes (start and complete an authorization, remove an account).AdaptiveHeaderTitle, the component "Automations" and "Knowledge" are set in.By commit
backend/account-state.ts: a pure derivation ofstate,limitedUntiland ablockingflag per window from a reading and a clock; the view and the stale rule;AccountService.get. Nothing is persisted, so the stored document and a roll back are untouchedbackend/accounts-api.ts,AI_GATEWAY_ADMIN_API_KEY, the e2e and container probesAdaptiveHeaderTitle, platform gutterACCT-48–ACCT-52, rewordedACCT-2/13/27/28/35/47andSMOKE-9/11/15, pins, error codes, setupEach commit typechecks and passes the service's tests on its own.
Decisions worth a second look
AI_GATEWAY_ADMIN_API_KEY; unset, it answers 403control_disabled. Setting both variables to one value runs the gateway with one key./api/v1is never keyless; the panel's own routes stay keyless (whatever fronts the gateway decides who reaches the panel). A script is never offered a redirect flow.stateis not the token endpoints'available. That one answers "may this account take new work" and also distrusts a reading older than 15 minutes and weighs the refresh floor.statedescribes the account as its own latest reading shows it, which is what the panel draws.DataTablehas no group-header rows; real headers would be a shared-component feature.Checked
tsc,oxlint --type-aware,oxfmt,knip,lint:manual,lint:links, opengrep (0 findings), e2e smoke (5)./api/v1over real HTTP.Not done
ACCT-50–ACCT-52.deployments/tale/ai/pr/deployment.yaml): itsopen:list passes only/api/healthand/api/tokens*past Entra, so machines cannot reach/api/v1/*there until it names the new paths; the admin key also needs provisioning if control should work on that host.stateuntil it is reloaded; the client and gateway ship together, so the contract is not made tolerant.