Skip to content

feat(console): add go usage endpoint - #16513

Merged
vimtor merged 3 commits into
anomalyco:devfrom
peculiarnewbie:go-usage-api
Aug 11, 2026
Merged

feat(console): add go usage endpoint#16513
vimtor merged 3 commits into
anomalyco:devfrom
peculiarnewbie:go-usage-api

Conversation

@peculiarnewbie

@peculiarnewbie peculiarnewbie commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #16017

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

this PR adds an API endpoint at /zen/go/v1/usage that 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:remote but met with cloudflare api key error.
I did copy the pattern in /zen/v1/models and copied the logic from /workspace/[id]/billing/lite-section.tsx

Screenshots / recordings

not a ui change

Checklist

  • I have tested my changes locally
    i guess running dev server and building counts as testing? but yea i don't think i can test this feature locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 7, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 7, 2026
@github-actions

github-actions Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@hendrixfreire

Copy link
Copy Markdown

Hey, any news on merging this?

@peculiarnewbie

Copy link
Copy Markdown
Contributor Author

no clue

@n-osennij

Copy link
Copy Markdown

+++

@patrezp

patrezp commented May 4, 2026

Copy link
Copy Markdown

I would like to see this implemented

@donrami

donrami commented May 9, 2026

Copy link
Copy Markdown

+1 for implementing this. In the meantime I'm using this hacky solution https://pi.dev/packages/pi-go-bars

@OmSoft-tech

Copy link
Copy Markdown

I would like to see this implemented

@slkiser

slkiser commented May 14, 2026

Copy link
Copy Markdown

Official support would be nice.

If you need usage and quota tracking in opencode, https://github.com/slkiser/opencode-quota

@n-osennij

Copy link
Copy Markdown

up

@m-saghir

Copy link
Copy Markdown

I'd employ this feature.

@matiasict

Copy link
Copy Markdown

+1

@Ksld154

Ksld154 commented May 19, 2026

Copy link
Copy Markdown

+1
really need this to check cross-device quota in OpenUsage

@hendrixfreire

hendrixfreire commented May 19, 2026

Copy link
Copy Markdown

Did they truly forget about this?

@robinebers

Copy link
Copy Markdown

Would really love this for OpenUsage. A lot of users keep asking, and the local SQL is unreliable.

@edsonboldrini

Copy link
Copy Markdown

+1

@igcodinap

Copy link
Copy Markdown

+1 pls merge this

@stevenup7

Copy link
Copy Markdown
  • 1 for this one, adding my name to the list of people wanting this, using @timm-u pi plugin but screen scraping feels pretty yuck

@vimtor

vimtor commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

sorry for the delay friends:
https://x.com/vimtor/status/2087291306569543797

d3ara1n added a commit to d3ara1n/pi-extensions that referenced this pull request Aug 12, 2026
opencode.ai/zen/go/v1/usage 随 anomalyco/opencode#16513 合并后已上线。
重写 opencodeGoUsage 适配实测响应结构(usage.rolling/weekly/monthly 的
percent + resetsAt ISO 时间戳),并注册回 BUILTIN_PROVIDERS(id 与 pi
内置 provider key 一致,有 key 即自动生效)。
OnesoftQwQ added a commit to OnesoftQwQ/opencode-go-copilot that referenced this pull request Aug 12, 2026
Fetch Go plan subscription usage from the official /zen/go/v1/usage
endpoint (live since 2026-08-11, anomalyco/opencode#16513) and render
it as a section in the token status bar tooltip.

- add src/goUsage.ts: usage fetcher with 5-minute TTL cache, lenient
  field-name parsing (percent/usagePercent, resetsAt/resetInSec), stale
  cache retention on failure and 401 detection (no active Go plan)
- statusBar: tooltip appends usage section (5h/weekly/monthly percent +
  reset countdown + useBalance + last updated), background polling with
  configurable interval, click-to-refresh via command binding
- add opencodego.checkUsage command: force refresh and show summary
- new settings opencodego.showUsageInTooltip (default true) and
  opencodego.usageRefreshInterval (default 5 min, 1-60)
- zh-cn/en localization for all new strings
OnesoftQwQ added a commit to OnesoftQwQ/opencode-go-copilot that referenced this pull request Aug 12, 2026
* feat: show OpenCode Go plan usage in the status bar tooltip

Fetch Go plan subscription usage from the official /zen/go/v1/usage
endpoint (live since 2026-08-11, anomalyco/opencode#16513) and render
it as a section in the token status bar tooltip.

- add src/goUsage.ts: usage fetcher with 5-minute TTL cache, lenient
  field-name parsing (percent/usagePercent, resetsAt/resetInSec), stale
  cache retention on failure and 401 detection (no active Go plan)
- statusBar: tooltip appends usage section (5h/weekly/monthly percent +
  reset countdown + useBalance + last updated), background polling with
  configurable interval, click-to-refresh via command binding
- add opencodego.checkUsage command: force refresh and show summary
- new settings opencodego.showUsageInTooltip (default true) and
  opencodego.usageRefreshInterval (default 5 min, 1-60)
- zh-cn/en localization for all new strings

* feat: add logging for Go usage fetch and polling

Log the usage data fetch lifecycle so the extension output channel
shows why the status bar tooltip has or lacks usage data.

- goUsage: log successful fetches (goUsage.fetch.ok, info, with url,
  durationMs, per-window percent and useBalance); split failures into
  goUsage.fetch.unauthorized (401, no active Go plan) and
  goUsage.fetch.failed (other); log JSON parse errors as
  goUsage.fetch.parseError — exactly one log record per attempt
- statusBar: debug logs for polling lifecycle
  (goUsage.poll.start/stop/disabled/skip)
- extension: remove unused hasApiKey helper
- AGENTS.md: document goUsage.* log tags in the logging conventions

* feat: compact Go usage tooltip layout

Simplify the Go usage section in the status bar tooltip per user
request: no blank separator line, window labels shortened to
"5H" / Week / Month with percent only, and a single reset
countdown line for the 5h window.

- statusBar: render "Go 用量" title, "5H 65%" / "周 30%" /
  "月 12%" lines and "五小时窗口将在 2H13M 后重置"; drop the
  useBalance and last-updated lines
- goUsage: formatResetDuration now emits compact "2H13M"/"45M";
  remove formatAgo and getUsageFetchTimestamp (no longer used)
- localize: replace tooltip keys with the compact variants
- AGENTS.md: sync function docs

* feat: show Go plan usage as the status bar main text

The status bar now displays the Go plan usage (5h window) as its main
text, e.g. "Go 5H 65%" (or "Go --" while no usage data is cached),
instead of the token count. Token input/output details remain in the
tooltip alongside the usage windows.

- statusBar: add updateStatusBarGoUsageText, use it from initStatusBar,
  updateContextStatusBar, updateStatusBarWithApiPrompt, refreshGoUsage
  and refreshGoUsageNow; polling now always runs (status bar text
  depends on usage data), showUsageInTooltip only gates the tooltip
  section; drop createProgressBar and the token-based main text
- statusBar: updateContextStatusBar drops the unused model parameter;
  updateStatusBarWithApiPrompt signature simplified to (statusBarItem)
- provider: update call sites; drop unused ASK_IMAGE_TOOL_NAME and
  InterceptedToolCall imports
- localize: replace Token Count / Ready / Current model token usage
  keys with Go usage and token usage
- AGENTS.md: sync status bar docs and log tag list

* feat: drop Go usage tooltip title, keep status bar numeric icon

- statusBar: remove the "Go 用量" title line from the tooltip usage
  section (windows now follow the token lines directly, no blank line);
  keep the $(symbol-numeric) icon in the status bar main text
  ("$(symbol-numeric) Go 5H 65%" / "$(symbol-numeric) Go --")
- AGENTS.md: sync docs

* feat: join tooltip usage label and percent with em dash

Use "——" (no space) between the window label and the percent in the
status bar tooltip usage section: "5H——65%" / "周——30%" / "月——12%".

* chore: apply prettier-style formatting

Reformat src/extension.ts, src/goUsage.ts, src/localize.ts,
src/provider.ts and src/statusBar.ts with the prettier code style
(tab indentation, long-line wrapping). No logic changes.

* Revert "chore: apply prettier-style formatting"

This reverts commit bf4c4a3.
ltmoerdani pushed a commit to ltmoerdani/opencode-copilot-chat that referenced this pull request Aug 12, 2026
Pure, unit-testable module for the official OpenCode Go usage endpoint
(upstream anomalyco/opencode#16513, verified live in production):

- fetchGoUsage(): GET /zen/go/v1/usage with the existing opencode-go key as
  a Bearer token; classifies failures (unauthorized / no-subscription /
  not-found / network / invalid) so callers can fall back to local
  estimates. The key is never logged or persisted.
- mergeServerUsage(): overlays the server-accurate rolling/weekly/monthly
  percent + resetsAt onto a locally-computed UsageSummary. The endpoint
  does not return raw spend, so spent is derived as limit x percent / 100
  to keep the status bar and tooltip consistent; today/yesterday and
  per-session spend stay local.
- GO_LIMITS stays the source of the display limits (they match the
  server's ZEN_LIMITS).
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.

[FEATURE]: Add Go plan usage/balance API endpoint (rolling/weekly/monthly windows)