Skip to content

[Feature] Add OpenCode Go (opencode.ai/zen/go) provider with live quota windows #22

Closed

Description

@Luna161

Add OpenCode Go (opencode.ai/zen/go) provider with live quota windows

TL;DR: Add a new telemetry provider that surfaces the live 5-hour and weekly usage windows plus the monthly USD credit balance for OpenCode Go subscriptions (Go $10/month) via the same Bearer API key the user already uses for /zen/go/v1/models.

Why

OpenCode Go is a $10/month coding-agent subscription with usage-windowed plans. From opencode.ai/docs/go/:

  • 5-hour limit — $12 of usage
  • Weekly limit — $30 of usage
  • Monthly limit — $60 of usage

Users on Go today have no read-only way to surface their live quota in their DankBar without opening the Zen web console — same UX gap that motivated the merged Command Code provider (#21).

Proposed data source

Two endpoints under https://opencode.ai/zen/go/v1/, both authenticated with the same Bearer API key users already create in OpenCode Studio/Zen:

Endpoint Purpose Stability
GET /zen/go/v1/usage live 5h + weekly + monthly usage windows ✅ shipped in v1.18.17 (PR #16513, closes #16017)
GET /zen/go/v1/models public, no-auth — auth-only fallback when /usage fails ✅ documented at opencode.ai/docs/zen

The Bearer key is the same one users paste into DMS for any other OpenCode Zen provider — no cookies, no dashboard scraping, no auth-file reads required (env var OPENCODE_API_KEY).

Live verification

I have verified the response shape against the merged endpoint code (packages/console/app/src/routes/zen/go/v1/usage.ts, commit b5caa022):

// GET /zen/go/v1/usage
{
  "useBalance": false,
  "rollingUsage": {
    "status": "ok" | "rate-limited",
    "resetInSec": 12345,
    "usagePercent": 0-100
  },
  "weeklyUsage":  { "status": "ok" | "rate-limited", "resetInSec": 12345, "usagePercent": 0-100 },
  "monthlyUsage": { "status": "ok" | "rate-limited", "resetInSec": 12345, "usagePercent": 0-100 }
}

The endpoint returns usagePercent directly (server-side computation from Subscription.analyzeRollingUsage etc.) — we don't need to know the cap values in the adapter, which sidesteps the limits-drift problem.

resetInSec is "seconds until reset" → maps cleanly to the existing resetsAt schema (now + resetInSec in ISO 8601 UTC).

Honest coverage level

Quota (primary: 5h remaining %, secondary: weekly remaining %, credits: monthly remaining %). Falls back to Auth / configured when /v1/usage is unreachable (network, key invalid, no Go subscription), with a clear note in the card that quota windows are unavailable. Never fabricates a percentage — only renders what the API returned.

Error semantics (from usage.ts)

  • 401 + AuthError: "Missing API key." or "Unauthorized" → key invalid/missing
  • 403 + EntitlementError: "OpenCode Go subscription required." → key valid but no Go plan
  • Any 5xx or network failure → fall back to /v1/models for auth-only check (mirrors Command Code's /provider/v1/models fallback)

Why this differs from scraping precedents

Unlike CodexBar's earlier rejection of a Command Code scraping approach (steipete/CodexBar#2629), OpenCode ships an official Bearer-authenticated usage endpoint. No cookies, no auth-file reads, no HTML scraping. The implementation is a 1:1 structural parallel to the merged Command Code provider (#21).

Implementation outline

Mirrors the existing fetch_commandcode_native structure:

  • providers/get-opencode-usage → dispatches via the existing get-provider-wrapper
  • fetch_opencode_native reads OPENCODE_API_KEY, tries /zen/go/v1/usage, falls back to /zen/go/v1/models for auth-only on alpha failure
  • Widget/Settings/docs updates identical in shape to the Command Code entry, with primary = 5h, secondary = weekly, credits = monthly USD balance
  • Provider ID stays opencode (already in availableProviderOptions) — only the display name is OpenCode Go and the mode changes from informational to telemetry

Plan limits (for documentation only — not used by adapter)

  • 5h: $12 of usage
  • Weekly: $30 of usage
  • Monthly: $60 of usage
  • Subscription: $10/month

Questions for maintainers

  1. Comfortable with the v1.18.17 dependency? (stable since the merge; documented at opencode.ai/docs/go.)
  2. Preferred provider display name — OpenCode Go (matches the plan name) vs OpenCode Zen Go vs OpenCode (Go plan)?
  3. Logo — reuse the existing assets/provider-logos/opencode.svg (it currently represents the free OSS client) or want a dedicated opencode-go.svg?

Happy to iterate on the PR per feedback before merge. The PR will be ready alongside this issue so you can review end-to-end.

Activity

  1. added
    enhancement
    on Aug 26, 2026
  2. self-assigned this
    on Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions