Skip to content

Name the OpenCode plan only when one is known - #1

Closed
dadofsambonzuki wants to merge 1 commit into
bitbonsai:opencode-agent-usagefrom
dadofsambonzuki:opencode-plan-label
Closed

dadofsambonzuki wants to merge 1 commit into
bitbonsai:opencode-agent-usagefrom
dadofsambonzuki:opencode-plan-label

Conversation

@dadofsambonzuki

Copy link
Copy Markdown

Follow-up to omacom#13548, on the same file. This branch is based on yours, so it can be merged into it or cherry-picked as-is.

The mechanism

GET https://opencode.ai/zen/go/v1/usage answers with percents and reset times and nothing else:

{"usage":{"rolling":{"status":"ok","percent":19,"resetsAt":"2026-09-30T11:20:47.701Z"},
          "weekly":{"status":"ok","percent":22,"resetsAt":"2026-10-05T00:00:00.000Z"},
          "monthly":{"status":"ok","percent":27,"resetsAt":"2026-10-21T07:45:46.000Z"}}}

No plan field, and nothing else an API key authenticates against names one: /zen/go/v1/{subscription,plan,account,me,limits,credits,balance}, /zen/v1/usage|credits|balance and /inference/go/v1/{subscription,account,plan,limits} all answer 404, and the console that does know the subscription is session-gated. So tierLabel = "Go" is an assertion rather than a reading — right for the $10 plan, wrong for a Go Plus ($40) subscriber, whose panel would name a plan they do not have.

The change

  • plan_from_payload() reads the plan out of the payload when the endpoint reports one — plan, planType, plan_type, planName, plan_name, tier, planId, plan_id, at the top level or under usage/subscription/account. A tier the endpoint starts naming therefore appears in the panel with no change here, which is the part that matters for tiers that do not exist yet.
  • plan_label() resolves the label: the user's own declaration in ~/.config/omarchy/agents/opencode.json ({"plan": "Go Plus"} — the same override file the Fireworks collector reads its funding from) → the payload's plan → blank.
  • The probe cache carries the plan next to the windows, so a cache hit keeps what the endpoint last named, and a keyless run still takes the declared plan.
  • README: an "OpenCode plan name" section documenting the override file and why the label can be blank.
  • test/shell.d/agent-usage-opencode-limits-test.sh now sandboxes XDG_CONFIG_HOME, so no case can read the operator's own override file and pass by accident.

The caveat

With neither source the label is blank and the panel renders that as "Subscription" (Panel.qml's heroMeta() falls back to it when tierLabel is empty). That is the honest reading of a percents-only payload, but it is a visible change for existing Go users — if a tier should always show, the source for it is the Console session, not this endpoint, and I am happy to wire that up instead.

Tests

New cases in test/shell.d/agent-usage-opencode-limits-test.sh:

  • uses a plan the endpoint reports
  • reads the declared plan from the config file
  • prefers the declared plan over the payload's
  • keeps the declared plan without a key
  • leaves the plan blank when nothing states it

One existing assertion changes: the first case pinned tierLabel == "Go" for a payload whose plan is unknown.

How much each source changes the record (the same driver run against your head and this branch, urllib stubbed, no fixtures for the numbers):

case as pushed with this patch
endpoint names a plan (Go Plus) "Go" "Go Plus"
config override (Go Plus) "Go" "Go Plus"
no source states a plan "Go" ""

What I ran

  • bash test/shell.d/agent-usage-opencode-limits-test.sh → 17 ok, exit 0
  • bash test/shell.d/agent-usage-opencode-scanner-test.sh → 5 ok, exit 0
  • ./test/shell → 288 scripts run, 13 failing; all 13 are environment-dependent (an omarchy-pkgs checkout, omasnap, the machine's own Hermes install, a browser launcher) and each reproduces with byte-identical ok/not-ok counts on the unpatched head, so none is this change. hermes-cli-test.sh, for example: 6 ok / 1 not ok on both.
  • On a live Go account (real ~/.local/share/opencode, 732 prompts over 18 sessions): the record is identical apart from the label — limits Rolling (5h) 22%, Weekly (7-day) 23%, Monthly 28%, totalPrompts 732, totalSessions 18, activeDays 8.

The Go gateway reports percents and reset times, not the plan they belong to:
`/zen/go/v1/usage` names no plan, and neither does any endpoint an API key
authenticates against, so `tierLabel` asserted the $10 Go plan for what may be
a Go Plus account.

Use a plan the payload reports as it stands — that is what lets a future tier
appear without this collector changing — and otherwise leave the label blank,
which the panel renders as "Subscription". A user whose plan the endpoint still
hides can declare it in `~/.config/omarchy/agents/opencode.json`, the override
file the Fireworks collector already uses for its account.
@dadofsambonzuki

Copy link
Copy Markdown
Author

A design note that is worth recording here, since it is the same thread as the plan-label change.

The collector currently has to reconstruct per-model usage from client stores (opencode's own database, pi/omp transcripts, and other harnesses that spent the same subscription). That is a workaround: those stores are per-machine and per-client, so they miss usage from other machines and from harnesses whose database you do not know about, and the account-level percentages in /zen/go/v1/usage are the only numbers that are actually authoritative.

There are open feature requests for the endpoint that would replace all of it — anomalyco/opencode#43983 (expose Go usage history through the API key, whose own body notes the local database "does not represent server-side accounting, usage from other machines, or the server-side reconciliation"), #13497 (per-model breakdown and totals) and #44189 (balance in the usage response). The server-side usage table already carries model, provider, tokens, cost and keyID per event, so this is a matter of exposure rather than of data.

If such an endpoint appears, this collector should prefer it and treat the local scans as a fallback for the cases where it is unavailable (no key, no entitlement, no network): one authoritative source, no per-client scans to keep in sync, and no double counting when two stores hold the same session. I have raised the requirement on #43983 with the panel's needs; no change needed here today, just worth agreeing on the direction before more local scanners get written.

@bitbonsai

Copy link
Copy Markdown
Owner

Thank you, Nathan. The plan-label idea is sound: do not name a plan the endpoint never reports, and let a user declare their own. This PR can not go in as it is, though. It targets opencode-agent-usage, the branch behind omacom#13548, and dhh closed that one on Oct 2 and brought a rewritten collector into quattro through omacom#14040. The file this patch changes is now a different file.

Closing this one. If the Go Plus label still shows wrong on quattro, I will redo the idea there as a small new PR, with your authorship noted. Your note about the usage endpoint (anomalyco/opencode#43983) is a good direction to keep in mind for the collector.

@dadofsambonzuki

Copy link
Copy Markdown
Author

Re-cut on quattro as suggested: omacom#18440.

It targets the rewritten collector from omacom#14040 — nothing from this branch is carried over, since the functions it changed no longer exist — and keeps the same three-part idea: read the plan from the answer if it ever reports one, take a declaration in ~/.config/omarchy/agents/opencode.json over it, and leave the label blank rather than naming Go.

The endpoint is unchanged as of today: GET /zen/go/v1/usage still answers percents and reset times only, and /zen/go/v1/{subscription,plan,account,me,limits,credits,balance,profile} still 404. Go is three plans now (Go $10, Go Plus $40, Go Teams $20/member), all on that one endpoint, so the hardcoded label was naming the cheapest one for everyone.

Thanks for the pointer to anomalyco/opencode#43983 — usage history is a separate gap and I have not touched it here.

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