GeezerVison is showing github.com — Feature Request: Add Zen balance API endpoint · Issue #10448 · anomalyco/opencode
Feature Request: Add Zen balance API endpoint #10448DescriptionSummary
Add a public API endpoint to query the current Zen account balance programmatically.
Use Case
I'd like to display my Zen balance in my system status bar (waybar on Linux). Currently, the only way to check balance is through the web dashboard, which makes automation impossible.
A simple endpoint like GET /zen/v1/balance (authenticated with the existing API key) would enable:
- Status bar widgets showing remaining credits
- Alerts when balance drops below a threshold
- Integration with budgeting/monitoring tools
- CI pipelines that check balance before expensive runs
Proposed API
GET https://opencode.ai/zen/v1/balance
Authorization: Bearer <api-key>
Response:
{
"balance": 42.50,
"currency": "USD",
"auto_reload": {
"enabled": true,
"threshold": 5.00,
"amount": 20.00
}
}
Workaround
Currently using opencode stats to track local spending, but this doesn't reflect the actual account balance.
Additional Context
The auto-reload feature suggests the infrastructure to query balance already exists server-side. Exposing it via API would be a small addition with high utility for power users.
Thanks for building such a great tool! 🙏 Reacted by Emmanuel Oh, Ivan Delgado, Matheus Richard, Samuel François, hyperpuncher, Gene Hand, Arif Rahman (Bolt), Alejandro Estornell, Stephan Meijer, Josh Klar and 28 more Reacted by Sebastian Atlántico, Iván Hernández Cazorla, emil, zxcslo, Fabio Mazarotto, Luis Alejandro Martínez and libfridge Activitygithub-actions commented on Jan 24, 2026 This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if this doesn't address your specific case. emmaneugene commented on Feb 14, 2026 +1, I'm also trying to build a centralized monitoring tool for model usage across different subscription/API providers, and this would be very helpful aaesalamanca commented on Mar 4, 2026 Same need here. I'm trying to build a macOS menu bar app to display the current balance so I don't have to navigate to the web dashboard. Reacted by Richard Glen Domingo and Abhishek Divekar mderazon commented on May 22, 2026 adivekar-utexas commented on Jun 14, 2026 Cross-linking a downstream integration affected by the missing Zen/Go quota API: OmniRoute issue cheaper-inference/OmniRoute#3844 and diagnostic PR cheaper-inference/OmniRoute#3838 . We verified that a real OpenCode Go key works for chat completions, but quota-style endpoints return either 404 or non-JSON fallback responses. OmniRoute can only show diagnostics until OpenCode exposes a supported public endpoint. rossigee commented on Jul 12, 2026 Is there a better place to report this upstream? Seems to be quite a common and obvious requirement, needed by a lot of people, but it would need to be implemented server-side by the Anomaly team, not here in this repo. vmvarela commented on Aug 12, 2026 Extending this request: monthly window + last top-up anchor
#41981 (closed as dup of this) asked for balance + monthly usage/limit + reset timestamps on the usage API. Folding that scope in here:
The existing GET /zen/go/v1/usage (#16513) returns plan-window percentages only — no monetary amounts. For Zen balance-billing workspaces, quota tools (opencode-quota, etc.) still scrape the billing page HTML. Proposal: sibling endpoint GET /zen/v1/workspace/usage returning:
{
"generatedAt": "...",
"currency": "USD",
"balance": {
"amount": 12.34,
"updatedAt": "...",
"percentOfLastTopUp": 61.7,
"lastTopUp": { "amount": 20.00, "at": "..." }
},
"usage": {
"monthly": {
"status": "ok",
"used": 42.10,
"limit": 100.00,
"remaining": 57.90,
"percent": 42.1,
"resetsAt": "..."
}
}
}
Key points:
percentOfLastTopUp = balance / lastTopUp.amount * 100 — "of what I last paid, X% remains"; server-computed, null when no anchor
- Monthly window mirrors the go endpoint's shape but with absolute USD values (server owns the math, kills the 100M-units conversion clients hardcode)
status server-derived: ok / near_limit / rate_limited / blocked
Reacted by Shawn Kiser and Stefan Schwarzer joeskeen commented on Sep 20, 2026 Use case: at-a-glance usage in a status bar
+1 from a waybar integration. I'm hitting the same problem as several people above — I want a small status-bar widget that shows me my rolling / weekly / monthly usage percentages and my Zen balance, so I know whether I'm on track for the month without opening the dashboard.
A GET /zen/v1/workspace/usage (or equivalent Bearer-friendly endpoint) that returns the workspace's balance in USD plus the existing plan-window percentages would unblock this and the other status-bar / menu-bar / monitoring-tool integrations people have mentioned (OmniRoute, OpenChamber, etc.).
Concrete fields that would cover the common case:
{
"currency": "USD",
"balance": { "amount": 12.34, "updatedAt": "..." },
"usage": {
"rolling": { "used": 0.43, "limit": 12.00, "percent": 4, "resetsAt": "..." },
"weekly": { "used": 6.74, "limit": 30.00, "percent": 22, "resetsAt": "..." },
"monthly": { "used": 11.24, "limit": 60.00, "percent": 19, "resetsAt": "..." }
}
}
I've already wrapped /console/api/go/status (it works for a service-account key) and it returns the three windows in roughly this shape. The blocker on my side is just the balance — /console/api/billing/status returns 403 for service-account Bearer tokens, so the balance is only reachable via browser session cookies, which doesn't fit a long-running status-bar poll. If billing returned the same shape as the proposed endpoint above but rejected service-account keys by design, that's fine to know — I can fall back to omitting balance from the widget until a non-cookie path exists.
This isn't a complaint, just a data point: every status-bar / monitoring / dashboard integration I've seen wants the same small surface, and consolidating it into a single Bearer-friendly endpoint would save us all from scraping /console HTML. opencodejr commented on Oct 29, 2026 Thanks for the clear write-up, @uwagz!
To restate the request: you'd like a public API endpoint, authenticated with your existing Zen API key (e.g. GET /zen/v1/balance), that returns your current Zen balance and auto-reload settings. That way you could show the balance in a status bar like waybar, get low-balance alerts, or check it from CI before expensive runs.
Right now the balance is only available in the web console. This needs a new endpoint on the Zen service, so it can't be added with an OpenCode plugin. The maintainers will consider it. If anyone else would find this useful, a 👍 on the issue helps show demand.
Reacted by Ryan, infinitecontext.com, Roger Senna, inknofs, libfridge, 開源 lib < and Loránd Biró s8z7yymynr-sudo commented on Nov 22, 2026 Balance of an OpenCode Console workspace is not readable outside the web UI
Context: OpenCode Desktop 2.3.2 on macOS, with a local GUI plugin that shows provider usage in a status bar. ChatGPT/Codex windows, OpenRouter credit and Synthetic quotas all work. The OpenCode prepaid balance does not.
What I observe:
- GET /api/experimental/usage/limits returns the workspace and its budgets, but no balance. Budgets are empty on this account.
- The balance is only visible in the Console UI, through GET /console/api/billing/status with an x-org-id header and a console session cookie.
- The plugin process cannot reach that browser session: it enumerates two windows and none is the Console page.
- Calling billing/status with the opencode credential stored in opencode.db returns 403 as a Bearer token, and 403 again when sent as a __Host-console_session or auth cookie.
Request: please document a supported way to read the prepaid workspace balance without a browser session, authenticated by an API key or the console credential stored by opencode auth login. Returning it from the local API, or adding it to GET /zen/go/v1/usage, would both work for a monitor. If a console session cookie is the only supported mechanism, saying so explicitly would also help, so plugins can report the limitation instead of retrying.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|