Repository navigation
Commit f19f132
committed
feat: per-key request accounting and upstream signal capture
Asked whether remaining quota could be read from the responses. Measured
against the live endpoint: it cannot. A successful 200 carries no rate-limit
headers at all, and the console exposes no usage/balance/limits route.
What a 200 actually carries (whole header list, 2026-10-18):
CF-RAY, Cache-Control, Cf-Placement, Connection, Content-Type, Date,
Server, Transfer-Encoding, x-opencode-log-id, x-zen-model
No x-ratelimit-limit / -remaining / -reset, no retry-after, no quota. Console
probes: /api/user is the only authenticated route (id, email, role); /api/usage,
/api/zen/balance, /api/credits, /api/limits, /zen/v1/usage and the rest all 404.
Upstream has an open feature request for precisely this
(anomalyco/opencode#55816, 2026-10-15).
So the router keeps its own per-key counters, which is the practical stand-in:
- requests_since_reset - requests sent since that key last answered 429. This
is the number you actually want when deciding whether to park a key, since
upstream exposes no remaining figure. Rolls to 0 on every 429.
- requests_total - lifetime count for the connection. Keeps climbing on a 429,
because that request was still sent upstream.
- last_status, last_ok_in, last_429_in with the last Retry-After value.
- Captures the two headers upstream does send: x-opencode-log-id (the trace id
support asks for) and x-zen-model (the model upstream actually served, which
makes a silent substitution visible).
Shown on the provider page per connection, alongside the cooling badge, with a
note that these are local counters rather than upstream quota. /admin/api/
providers/<id> gained a usage array next to cooling.
Tests: 104 passing (was 101).1 parent dcbc4aa commit f19f132
4 files changed
Lines changed: 214 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
188 | 196 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
503 | 595 | | |
504 | 596 | | |
505 | 597 | | |
| |||
3254 | 3346 | | |
3255 | 3347 | | |
3256 | 3348 | | |
| 3349 | + | |
3257 | 3350 | | |
3258 | 3351 | | |
3259 | 3352 | | |
| |||
3269 | 3362 | | |
3270 | 3363 | | |
3271 | 3364 | | |
| 3365 | + | |
3272 | 3366 | | |
3273 | 3367 | | |
3274 | 3368 | | |
| |||
3277 | 3371 | | |
3278 | 3372 | | |
3279 | 3373 | | |
| 3374 | + | |
3280 | 3375 | | |
3281 | 3376 | | |
3282 | 3377 | | |
3283 | 3378 | | |
| 3379 | + | |
3284 | 3380 | | |
3285 | 3381 | | |
3286 | 3382 | | |
| |||
3289 | 3385 | | |
3290 | 3386 | | |
3291 | 3387 | | |
| 3388 | + | |
3292 | 3389 | | |
3293 | 3390 | | |
3294 | 3391 | | |
| |||
3812 | 3909 | | |
3813 | 3910 | | |
3814 | 3911 | | |
| 3912 | + | |
3815 | 3913 | | |
3816 | 3914 | | |
3817 | 3915 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
| 252 | + | |
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
264 | | - | |
| 264 | + | |
265 | 265 | | |
| 266 | + | |
266 | 267 | | |
267 | 268 | | |
268 | 269 | | |
| |||
275 | 276 | | |
276 | 277 | | |
277 | 278 | | |
278 | | - | |
| 279 | + | |
279 | 280 | | |
280 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
281 | 290 | | |
282 | | - | |
| 291 | + | |
283 | 292 | | |
284 | 293 | | |
285 | 294 | | |
| |||
288 | 297 | | |
289 | 298 | | |
290 | 299 | | |
| 300 | + | |
291 | 301 | | |
292 | 302 | | |
293 | 303 | | |
| |||
296 | 306 | | |
297 | 307 | | |
298 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
299 | 312 | | |
300 | 313 | | |
301 | 314 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1702 | 1702 | | |
1703 | 1703 | | |
1704 | 1704 | | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
1705 | 1796 | | |
1706 | 1797 | | |
1707 | 1798 | | |
| |||
0 commit comments