Skip to content

feat(usage): report OpenCode Go subscription usage - #5

Merged
some-du6e merged 3 commits into
masterfrom
claude/ocg-subscription-feature-877868
Aug 12, 2026
Merged

feat(usage): report OpenCode Go subscription usage#5
some-du6e merged 3 commits into
masterfrom
claude/ocg-subscription-feature-877868

Conversation

@some-du6e

@some-du6e some-du6e commented Aug 12, 2026

Copy link
Copy Markdown
Owner

What

Adds usage/quota reporting for OpenCode Go (ocg), so the dashboard shows its rolling, weekly, and monthly windows alongside Claude Code and Codex.

  • open-sse/services/usage/opencode-go.js (new) — fetches GET /zen/go/v1/usage, maps the three windows to percent-based quotas.
  • open-sse/services/usage.js — registers opencode-go in the dispatcher.
  • open-sse/providers/registry/opencode-go.js — adds transport.usage.url and features.usage / usageApikey; fixes the price in the connect notice.
  • ProviderLimits/utils.jsparseQuotaData case so the dashboard renders the rows.
  • tests/unit/opencode-go-usage.test.js (new) — 9 tests.

Why

OCG has always been a subscription with rolling/weekly/monthly limits, but 10router had no usage reporting for it — the dashboard couldn't show what actually stops the next request. There was no public API for it until now: opencode shipped GET /zen/go/v1/usage on 2026-08-11 (anomalyco/opencode#16513), closing a request open since March. It authenticates with the same Go API key already stored, so no session cookie or workspace id is needed.

Notes for reviewers

The endpoint is undocumented and the obvious references are wrong. It was reshaped by a follow-up commit (d4704347) less than an hour after the PR merged, so the PR description is already stale, and the JSON in upstream issues #16017 / #31084 was only ever a user proposal — none of those shapes shipped. This handler is written against the deployed response, captured live and pinned in the test as the contract:

{"usage":{
  "rolling": {"status":"ok","percent":0,"resetsAt":"2026-08-12T20:23:13.083Z"},
  "weekly":  {"status":"ok","percent":0,"resetsAt":"2026-08-17T00:00:00.083Z"},
  "monthly": {"status":"ok","percent":91,"resetsAt":"2026-08-25T01:33:44.083Z"}}}

category deliberately stays apikey. That field is the auth mechanism, not the billing model — cc/codex are oauth because of how they log in, and there is no subscription value. Go authenticates with a plain key, so features.usageApikey is what lets /api/usage accept the connection.

Quotas are percent-only. The server exposes no dollar amounts (limits are held in micro-cents internally and only the percentage is returned). The handler sets remainingPercentage and leaves remaining unset — the UI reads remaining as a 0-100 percent, the same trap Qoder and grok-cli hit. There's an explicit test that 91% used renders as 9% remaining.

Failure modes are covered. 401, 403 (valid key without a Go subscription — distinct from an auth failure, since re-authorizing can't fix it), 5xx, the SPA 404 HTML you'd get if the endpoint were rolled back, an unexpected 200 shape, a missing key, and a network error. All return a message rather than throwing.

Testing

  • 9 new tests pass; 17 pass across the three ocg-related test files.
  • verify-alias and verify-oauth-urls baselines are byte-for-byte equal. verify-providers shows only the pre-existing tokenrouter.thinkingFormat diff, unrelated and untouched.
  • The 4 failures in translator/golden-url-header.test.js (blackbox, anthropic, cline, kimi) are pre-existing — verified by stashing and re-running on a clean tree.
  • Not verified: the dashboard render in a browser. The full data path is covered by tests through parseQuotaData/getRemainingPercentage, but the live key was disabled before the page could be loaded, so a render would have proved nothing. Worth one look at the usage page with a working Go key.

The price fix is a separate commit so it can be reverted independently — it rests on confirmation from @some-du6e ($5 first month, then $10/mo), not on something read from source. The previous string, "$5/mo (then 0/mo)", had lost the $1 of $10.

Summary by CodeRabbit

  • New Features

    • Added OpenCode Go usage tracking with API-key authentication.
    • Displays rolling, weekly, and monthly quota usage, remaining percentages, reset times, and rate-limit status.
    • Added usage details to the dashboard’s provider limits view.
    • Updated the OpenCode Go subscription notice with corrected pricing information.
  • Bug Fixes

    • Improved handling of authentication failures, missing subscriptions, unavailable endpoints, malformed responses, and network errors.

OCG is a subscription (rolling/weekly/monthly windows) but had no usage
reporting, so the dashboard couldn't show what actually stops the next
request. opencode exposed the windows via GET /zen/go/v1/usage on
2026-08-11 (anomalyco/opencode#16513); it authenticates with the same Go
API key already stored, so no cookie or workspace id is needed.

The endpoint is still undocumented and was reshaped by a follow-up commit
(d4704347) an hour after the PR merged, so the handler is written against
the deployed response, captured live and pinned in the test as the
contract. Note the shapes proposed in the upstream issues never shipped.

category stays "apikey" — that field is the auth mechanism, not the
billing model, and Go authenticates with a key. features.usageApikey is
what lets /api/usage accept a non-OAuth connection.

Quotas are percent-only (the server exposes no dollar amounts): set
remainingPercentage and leave `remaining` unset, which the UI would
otherwise read as a 0-100 percent.
The notice read "$5/mo (then  0/mo)" — a mangled string that lost the "$1"
of "$10" and left a double space, so the ongoing price showed as "0/mo".
Confirmed pricing is $5 for the first month, then $10/mo.
Copilot AI lite review requested due to automatic review settings August 12, 2026 15:40
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@some-du6e, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f4be06a6-894d-4754-b16b-759c995757f4

📥 Commits

Reviewing files that changed from the base of the PR and between 5b89ca1 and c541baf.

📒 Files selected for processing (2)
  • open-sse/services/usage/opencode-go.js
  • tests/unit/opencode-go-usage.test.js
📝 Walkthrough

Walkthrough

OpenCode Go now supports usage retrieval through its /usage endpoint. The integration authenticates with an API key, maps quota windows for the dashboard, handles usage errors, and adds unit coverage.

Changes

OpenCode Go usage support

Layer / File(s) Summary
Provider usage wiring
open-sse/providers/registry/opencode-go.js, open-sse/services/usage.js
The provider defines the usage endpoint and API-key authentication. The usage service registers the OpenCode Go handler.
Usage retrieval and dashboard mapping
open-sse/services/usage/opencode-go.js, src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.js
The handler retrieves rolling, weekly, and monthly quota data, reset times, and rate-limit status. The dashboard parser uses remaining percentages.
Usage behavior validation
tests/unit/opencode-go-usage.test.js
Tests cover authentication, quota conversion, rate limits, subscription errors, malformed responses, missing keys, and network failures.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant UsageService
  participant OpenCodeGoUsage
  participant OpenCodeGoAPI
  participant ProviderLimits
  UsageService->>OpenCodeGoUsage: pass API key and proxy options
  OpenCodeGoUsage->>OpenCodeGoAPI: request /zen/go/v1/usage with bearer authorization
  OpenCodeGoAPI-->>OpenCodeGoUsage: return quota windows and reset times
  OpenCodeGoUsage->>ProviderLimits: provide normalized quota data
  ProviderLimits-->>UsageService: render remaining percentages and limit status
Loading

Suggested reviewers: decolua

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding OpenCode Go subscription usage reporting.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/ocg-subscription-feature-877868

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@open-sse/services/usage/opencode-go.js`:
- Around line 32-42: Update open-sse/services/usage/opencode-go.js:32-42 in
formatWindow to return no quota when window.percent is not finite, rather than
defaulting it to zero; update open-sse/services/usage/opencode-go.js:99-103 to
skip adding the quota when formatWindow rejects the window; update
tests/unit/opencode-go-usage.test.js:127-137 with a response missing percent and
assert the dashboard receives no 100%-remaining quota.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 88a8d36c-405b-4495-b7f0-898a398448dc

📥 Commits

Reviewing files that changed from the base of the PR and between cf6aaf5 and 5b89ca1.

📒 Files selected for processing (5)
  • open-sse/providers/registry/opencode-go.js
  • open-sse/services/usage.js
  • open-sse/services/usage/opencode-go.js
  • src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.js
  • tests/unit/opencode-go-usage.test.js

Comment thread open-sse/services/usage/opencode-go.js

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds OpenCode Go (opencode-go / ocg) usage & quota reporting so the dashboard can display rolling/weekly/monthly windows (percent-based) alongside other supported providers.

Changes:

  • Introduces a new OpenCode Go usage handler that calls GET /zen/go/v1/usage and normalizes the three windows into percent-based quotas.
  • Registers opencode-go in the usage dispatcher and marks the provider registry entry as usage-capable via API key.
  • Extends dashboard quota parsing to render the OpenCode Go usage rows; adds unit tests covering success + failure modes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
open-sse/services/usage/opencode-go.js New usage fetcher for OpenCode Go; maps rolling/weekly/monthly windows into percent-only quotas and handles error cases without throwing.
open-sse/services/usage.js Registers the opencode-go usage handler in the dispatcher.
open-sse/providers/registry/opencode-go.js Adds transport.usage.url and enables features.usage + features.usageApikey; updates the UI notice text.
src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.js Adds an opencode-go case in parseQuotaData so the dashboard renders the quota rows appropriately.
tests/unit/opencode-go-usage.test.js New tests validating endpoint calling, quota mapping, dashboard parsing behavior, and key failure modes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

formatWindow defaulted a missing or non-numeric `percent` to 0, so a
malformed window was published as 100% remaining — malformed data read as
full headroom, the most dangerous direction to be wrong in for a quota
display. Return null instead and skip the window.

Status is checked before the percent gate: "rate-limited" is authoritative
on its own, so discarding an unusable percent must not also discard the
throttling signal.

Parsing still goes through toFiniteNumber, so a numeric string percent is
accepted rather than rejected as malformed.
@some-du6e
some-du6e merged commit 561fa16 into master Aug 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants