feat(console): add go usage endpoint - #16513
Merged
Merged
Conversation
1 task done
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
2 tasks done
|
Hey, any news on merging this? |
Contributor
Author
|
no clue |
|
+++ |
|
I would like to see this implemented |
|
+1 for implementing this. In the meantime I'm using this hacky solution https://pi.dev/packages/pi-go-bars |
|
I would like to see this implemented |
|
Official support would be nice. If you need usage and quota tracking in opencode, https://github.com/slkiser/opencode-quota |
|
up |
|
I'd employ this feature. |
|
+1 |
|
+1 |
|
Did they truly forget about this? |
|
Would really love this for OpenUsage. A lot of users keep asking, and the local SQL is unreliable. |
|
+1 |
|
+1 pls merge this |
|
Adam-Dalloul
added a commit
to Adam-Dalloul/codeg
that referenced
this pull request
Aug 22, 2026
Shipped 2026-08-11 in anomalyco/opencode#16513. percent is used 0-100 across rolling/weekly/monthly. No invented numbers.
JaminYe
pushed a commit
to JaminYe/pane
that referenced
this pull request
Aug 24, 2026
anomalyco/opencode#16513 shipped GET /zen/go/v1/usage (2026-08-11) — the endpoint the code comment said to swap to when it existed. The card now shows Session/Weekly/Monthly percentages and resets counted on OpenCode servers (same numbers as the Zen dashboard, other devices and shared-subscription participants included), authenticated with the Go key Pane already reads from auth.json. The live wire shape differs from the merged PR draft — verified against the deployed endpoint with a real key and pinned in a test: usage.{rolling,weekly,monthly}.{status,percent,resetsAt}. The old local-window computation stays as the fallback when the API is unreachable; dollar spend remains local. README + providers.md drop the "no public usage API yet" story. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
bibhubhatta
pushed a commit
to bibhubhatta/ClaudeBar
that referenced
this pull request
Aug 25, 2026
The local-DB probe only sees this machine's messages and guesses at the server's cost accounting, so its numbers diverged from the opencode.ai dashboard. opencode now exposes GET /zen/go/v1/usage (anomalyco/opencode#16513), which returns the same rolling/weekly/monthly percentages and reset times the dashboard shows. - Add OpenCodeCredentialLoader: reads OPENCODE_API_KEY or the `opencode-go` / `opencode` entry from $XDG_DATA_HOME/opencode/auth.json - Add OpenCodeAPIUsageProbe: calls the endpoint with a bearer key, maps used% -> remaining%, 401 -> sessionExpired, 403 -> subscriptionRequired - Keep OpenCodeUsageProbe (local DB) as a fallback when no key is present Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CdVhUZgY4SKaYkuxdqR3AY
1056674754
added a commit
to 1056674754/opencode
that referenced
this pull request
Aug 31, 2026
Upstream v1.18.16 (a3647eb) -> v1.18.17 (02546df), 32 commits. Functional changes: - fix(compaction): clearer instructions for smaller models like dsv4 flash (anomalyco#42045) - fix(provider): add Merge Gateway reasoning variants (anomalyco#41867) - fix(opencode): cap session retries with jitter (anomalyco#41939) - retry policy gains RETRY_MAX_RETRIES=5 global cap and 25% jitter - fix(opencode): detect Copilot PDF input support (anomalyco#41522) - fix(provider): scope DeepSeek V4 Flash sampling defaults (anomalyco#41620) - fix(session): route all Muse family models to the Meta system prompt (anomalyco#41581) - fix(app): use current default model (anomalyco#38603) - feat(console): add go usage endpoint (anomalyco#16513) and r2 data catalog stats - fix(ui): correct OC-2 weak icon color (anomalyco#41504) - fix(i18n): use widely recognized developer terminology (anomalyco#41532) Conflicts resolved: 30 package.json version bumps (rebranded 1.18.17-sscity), bun.lock (took upstream, rebranded workspace entries via bun install), and session/retry.ts (kept fork per-reason maxAttempts cap alongside upstream RETRY_MAX_RETRIES global cap and jitter).
3 of 4 tasks
This was referenced Sep 11, 2026
3 tasks done
androidand
pushed a commit
to androidand/opencode-skein
that referenced
this pull request
Sep 18, 2026
Co-authored-by: vimtor <vn4varro@gmail.com>
androidand
pushed a commit
to androidand/opencode-skein
that referenced
this pull request
Sep 19, 2026
Co-authored-by: vimtor <vn4varro@gmail.com>
androidand
pushed a commit
to androidand/opencode-skein
that referenced
this pull request
Sep 19, 2026
Co-authored-by: vimtor <vn4varro@gmail.com>
2 tasks done
rldona
pushed a commit
to rldona/FlupCode
that referenced
this pull request
Sep 24, 2026
Co-authored-by: vimtor <vn4varro@gmail.com>
eliahilse
added a commit
to eliahilse/kyora
that referenced
this pull request
Sep 29, 2026
…ows (#25) ## What `kyora-switch` can now save, load, clear and show usage for OpenCode subscription logins, the same way it does for Claude Code and Codex. ```bash kyora-switch opencode save work kyora-switch opencode load private kyora-switch opencode usage # or plain `kyora-switch usage` for every provider ``` ## Usage source OpenCode Go has a real usage endpoint that you call with the Go key. No local estimate is needed. - `GET https://opencode.ai/zen/go/v1/usage` with `Authorization: Bearer <key>`. Source: [`packages/console/app/src/routes/zen/go/v1/usage.ts`](https://github.com/anomalyco/opencode/blob/dev/packages/console/app/src/routes/zen/go/v1/usage.ts), added in anomalyco/opencode#16513. - It returns `{ usage: { rolling, weekly, monthly } }`. Each window has a `status` (`ok` or `rate-limited`), a `percent` (a floored whole number from 0 to 100) and `resetsAt` (an ISO timestamp). The server computes these in `Subscription.analyze{Rolling,Weekly,Monthly}Usage`. - Errors: 401 `AuthError` for a missing or unknown key, 403 `EntitlementError` ("OpenCode Go subscription required."). - The limits are dollar amounts. The Go docs set the 5-hour window at 20% of the monthly limit, the weekly at 50% and the monthly at 100%. The month runs from the subscription date. - Other tools read the same route: oh-my-pi, Orca, CodexBar and OmniRoute. - Zen (`opencode`) is pay-as-you-go. It has no windows and no usage route, so a Zen-only slot shows `quotaHint`. ## Design notes - **A slot holds only the `opencode-go` and `opencode` entries** of `$XDG_DATA_HOME/opencode/auth.json` (default `~/.local/share/opencode/auth.json`). A load merges them back in with `writeFileAtomic` at 0600, as two-space JSON, which is how opencode writes the file itself. Other providers in the file (openai, zai-coding-plan, xai, …) are left alone. `forget()` removes only those two keys and never creates the file. - **When a slot has no entry for one of the two:** load removes the live entry only if it holds the outgoing login's own key. The common case is one key connected as both Go and Zen. If that entry stayed, the old account would still be half signed in, and the next sync would save its key into the slot you just loaded. A Zen key that differs from the outgoing Go key is treated as a separate login and kept. The outgoing entries are backed up first either way. This is documented in the README and in the `mergeSubscriptions` doc comment. - **Identity:** the usage route returns no workspace or account name, so a login is named `key …abcd`. That's the last four characters of the key, which are also the four the OpenCode console shows. The Go key names the login if there is one, otherwise the Zen key does. The plan shows as `Go`, `Zen` or `Go + Zen`. The name stays the same for a given key, so sync matches the right slot. - There's no `refresh` or `credentialExpiry`, because API keys don't expire. - `doctor` warns when `OPENCODE_AUTH_CONTENT` is set, because opencode then reads that variable instead of the file. - **@kyora-sh/usage** now also exports `opencodeKey(authText, "opencode-go" | "opencode")` and `opencodeAuthPath()`. A follow-up can use them to add a `usageProbe` to the review `opencode` engine. This PR doesn't touch `packages/review`. - **Test preload:** `src/test-setup.ts` now points `KYORA_SWITCH_DIR`, `XDG_DATA_HOME`, `CODEX_HOME` and `CLAUDE_CONFIG_DIR` at an empty sandbox before any test runs. A test that forgets to set its own directory can't reach a real login. - The store format is unchanged, so existing claude and codex slots load exactly as before. ## Verification - `bun test`: switch 69 pass, usage 28 pass. Running from the repo root with the root preload gives 97 pass. - `bunx tsc --noEmit` is clean in `packages/switch/cli`, `packages/shared/usage`, `packages/review/cli` and `packages/council/mcp`. - I ran save, load, list, status, usage, clear, load and doctor end to end in a full sandbox, with temp HOME, XDG, CODEX and CLAUDE dirs, the keychain off, fake keys and a mock usage server. - I made one read-only probe of the real Go key with a temp `KYORA_SWITCH_DIR`. It returned `5h 0% used · weekly 0% used · monthly 0% used`. auth.json kept the same mtime, size and mode afterwards, and no slot files were written. The zeros fit the local history: the last opencode-go message in opencode's db was 13 days ago. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Issue for this PR
Closes #16017
Type of change
What does this PR do?
this PR adds an API endpoint at
/zen/go/v1/usagethat will provide the same opencode go usage data as in the zen workspace dashboard.If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!
How did you verify your code works?
unfortunately i don't think this is a change i can verify as an outside contributor. i did try running
bun dev:remotebut met with cloudflare api key error.I did copy the pattern in
/zen/v1/modelsand copied the logic from/workspace/[id]/billing/lite-section.tsxScreenshots / recordings
not a ui change
Checklist
i guess running dev server and building counts as testing? but yea i don't think i can test this feature locally
If you do not follow this template your PR will be automatically rejected.