Commit Graph
1 Commits
Author SHA1 Message Date
yetone b3a3e609ed middleware-reserve 0.1.0: routings that fill to a ceiling, or accounts before keys
A routing-strategy gateway plugin (magpie.gateway, exports strategies):
reserve/ceiling fills accounts in listed order up to `ceiling` percent of
their allowance (80 by default), then the next; past it everywhere, the
least used first. reserve/accounts-first puts subscriptions before API
keys, accounts least used first, keys by weight then recent tokens.
Resting seats go last in both. One file, no imports, for moejs.

Run:
- bun test packages/reserve: 12 tests (10 strategies.json cases through
  checkStrategies, exactly two strategies and no hooks, every answer a
  permutation for 2-8 seats). Breaking the resting rule by hand turned
  its case red.
- Sandbox magpie from yetone/magpie origin/main b03031738: `magpie plugin`
  lists "routings reserve/accounts-first, reserve/ceiling". A stub
  OpenAI-compatible provider on 127.0.0.1:3593 recorded the key of each
  request; the provider had key-a, key-b, key-c (weight 5), listed in that
  order. routing=reserve/accounts-first: 3 of 3 went to key-c. With key-c
  answering 429: key-c 429 once, then key-a, key-b, key-a (key-c resting,
  last; equal weights by fewer tokens). routing=reserve/ceiling: 4 of 4
  to key-a (keys' allowance unknown, so listed order).
Not tried: the over-ceiling tier with real subscription accounts; it is
covered by strategies.json only.
2026-10-16 02:57:43 +08:00