Repository navigation
Replies: 2 comments
|
I built a working prototype of this on my fork to check the shape before asking for approval. Screenshots use a local mock gateway with dummy data. Settings → Providers → Add source → HTTP endpoint. Field paths default to LiteLLM's Usage → Limits shows the source like a CLIProxyAPI account, using the amount shape from #14911: Context Window popover gets a compact budget line (the thread-cost part is tracked in #13073): One compatibility note: today an undecodable Would you approve this direction? If yes, I'll open a PR with only the budget-source commits. The open questions above still stand, especially whether the auth header should be a stored secret only. |
|
+1 to the generic Not every gateway returns one object per user. Inferrail (the gateway I maintain, open source) holds budgets per run, per project or globally, and its spend endpoint returns a list, one entry per budget, with money as decimal strings: GET /v1/local/budgets/spend
Authorization: Bearer <local api token>[
{"budget_id": "project:jdoe:monthly", "limit_usd": "1000", "spent_usd": "42.500000", "has_unpriced_usage": false},
{"budget_id": "work_id:fix-loop-17:per_work", "limit_usd": "25", "spent_usd": "3.120000", "has_unpriced_usage": false}
]Two small additions would make the proposed config map that without a per-gateway adapter:
On the Claude Code side, it routes through this gateway with |



Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem
Many teams run Claude Code (and other agents) through an internal LLM gateway (LiteLLM Proxy, a corporate API platform, etc.) via
ANTHROPIC_BASE_URL. The real limit for those users is a monthly spending budget enforced by the gateway, not a provider subscription window.Today in T3 Code:
get_usage, Codex, …). Behind a gateway, nothing reports the budget that actually applies.As a result, gateway users keep a separate terminal script or status line running just to see "$42 of $1000 used, resets Nov 1".
Proposal
Add a second
UsageLimitSourceConfigkind next tocliproxy.UsageLimitSourceSnapshot.kindalready anticipates more kinds. The new kind is a generic HTTP JSON source with field mapping, so T3 doesn't need per-gateway integrations:Example response from a LiteLLM-style gateway that this config maps:
{ "spend": 42.5, "budget_table": { "soft_budget": 800.0, "max_budget": 1000.0, "budget_duration": "1mo", "budget_reset_at": "2026-11-01T00:00:00Z" } }The source publishes one window (
usedPercent = used / limit, plus amounts andresetsAt). It goes through the existing pipeline: secret storage, poll interval, Refresh button, error state when the probe fails. Amounts would follow the shape #14911 introduces for Claude Enterprisemonthly_spend, so both render the same way.Configured from the UI
The JSON above is only how the source is stored. Users set it up entirely in Settings → Providers → usage hubs, by extending the existing
AddUsageLimitSourceDialog:Test runs the request once on the server and shows the parsed values, or the exact path that failed (for example
budget_table.max_budget not found), before anything is saved. Existing rows keep the current edit, disable and remove actions.Where it shows
Why generic, not per-gateway
PR #10904 (OpenRouter balance as its own kind) was closed pending scope approval. A single mapped HTTP kind covers OpenRouter, LiteLLM, Portkey and in-house gateways without adding a new integration for each.
Open questions for maintainers
ANTHROPIC_AUTH_TOKEN)?windows: [...]array of mappings in a single source?Related: #15043 (per-thread cost in the Context Window popover).
All reactions