Skip to content

feat(ai-gateway): manage accounts over REST, group them by state - #4999

Merged
yannickmonney merged 5 commits into
mainfrom
feat/ai-gateway-accounts-api
Oct 15, 2026
Merged

yannickmonney merged 5 commits into
mainfrom
feat/ai-gateway-accounts-api

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

What

Five asks for the AI gateway panel and API, in one PR:

  1. Read and control accounts over REST — /api/v1. The token key reads; a separate, optional admin key changes (start and complete an authorization, remove an account).
  2. No Tale logo in the title strip.
  3. Platform header styling — the title is AdaptiveHeaderTitle, the component "Automations" and "Knowledge" are set in.
  4. A clear reset indicator — an account that hit its limit is back when its last spent window rolls over. A session back in 5 minutes beside a spent week reads "Resets in 3 days", and only that window's clock is read in full strength.
  5. Grouping — by vendor, then by state: available, limit reached (soonest back first, unknown last), needs reauthentication, last call failed. The Status filter and the search know the same states.

By commit

Commit Holds
say what state an account is in and when it is back backend/account-state.ts: a pure derivation of state, limitedUntil and a blocking flag 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 untouched
manage accounts over REST backend/accounts-api.ts, AI_GATEWAY_ADMIN_API_KEY, the e2e and container probes
group accounts by state and say when a limit lifts ordering, Status and Resets cells, filter facet, en/de/fr
set the panel title like a platform page title logo and slash out, AdaptiveHeaderTitle, platform gutter
describe the accounts API, the states and the header README; manual boxes ACCT-48–ACCT-52, reworded ACCT-2/13/27/28/35/47 and SMOKE-9/11/15, pins, error codes, setup

Each commit typechecks and passes the service's tests on its own.

Decisions worth a second look

  • Two keys. The README already said the token key deliberately cannot add or remove an account, and adding one puts someone else's subscription into the pool the platform draws from. So changing needs AI_GATEWAY_ADMIN_API_KEY; unset, it answers 403 control_disabled. Setting both variables to one value runs the gateway with one key.
  • /api/v1 is 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.
  • state is 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. state describes the account as its own latest reading shows it, which is what the panel draws.
  • "Grouped" means adjacent rows. DataTable has no group-header rows; real headers would be a shared-component feature.
  • The tab icon (favicon) is still the Tale one; only the header logo went.

Checked

  • Service: 467 tests, tsc, oxlint --type-aware, oxfmt, knip, lint:manual, lint:links, opengrep (0 findings), e2e smoke (5).
  • The production bundle served by the Bun server, and every key/route combination of /api/v1 over real HTTP.
  • Mutation runs on the guards (control opening to the token key, a redirect flow offered to a script, filters ignored), the state rules (soonest instead of latest rollover, a per-model cap limiting the account, a passed rollover still blocking), the ordering, the header and the double dim: each was caught by a test.
  • A read-only review with fresh context probed about 60 path, method and key variants and found no way past the keys; its smaller findings are fixed.
  • Layout in light, dark, German, French, a phone width and the Status filter, against a synthetic pool.

Not done

  • The real OAuth round trip through the REST door needs a person at the vendor's consent screen: manual boxes ACCT-50–ACCT-52.
  • Ops (deployments/tale/ai/pr/deployment.yaml): its open: list passes only /api/health and /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.
  • A panel tab opened before a roll back to an older gateway throws on the missing state until it is reloaded; the client and gateway ship together, so the contract is not made tolerant.

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
yannickmonney added this pull request to the merge queue Oct 15, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 15, 2026
@yannickmonney
yannickmonney merged commit a72ceb7 into main Oct 15, 2026
@yannickmonney
yannickmonney deleted the feat/ai-gateway-accounts-api branch October 15, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant