feat: add OpenCode Go usage support - #3
JairajSustained wants to merge 1 commit into
Conversation
iefnaf
left a comment
There was a problem hiding this comment.
Thanks for the PR — nice work overall! I verified the core implementation and it holds up well:
- ✅
opencode-gois a real provider in pi-ai (id: "opencode-go", name "OpenCode Go", API-key auth), so the auth lookup id is correct — pi stores API-key providers inauth.jsonunder their provider id. - ✅ The endpoint is real (I confirmed
https://opencode.ai/zen/go/v1/usagereturns HTTP 401 without auth). - ✅ All 6 tests pass, and the defensive field fallbacks +
readPercentCandidatehandle garbage responses safely.
Two issues to fix before merging:
1. The "opencode" alias in detectProvider is incorrect
if (provider === "opencode-go" || provider === "opencode") return "opencode-go";pi-ai registers two distinct providers: opencode (OpenCode Zen — the BYO-key marketplace, per-token billing) and opencode-go (the Go subscription plan). They have separate credentials (auth.json["opencode"] vs auth.json["opencode-go"]) and separate usage APIs — /zen/go/v1/usage only reports Go subscription quota.
With this alias, a Zen-only user running /usage gets routed down the Go branch, the key lookup under "opencode-go" fails, and they see "No OpenCode Go API key found (connect OpenCode Go to get a key)" — confusing, since they do have a working key, it's just stored under the other id. It's like routing Anthropic Console API users to the Claude Pro subscription panel.
Please drop the alias and match strictly:
if (provider === "opencode-go") return "opencode-go";(The test using { provider: "opencode", id: "glm-5.2" } would need updating too.) Zen usage/credits would be a separate feature with its own endpoint if we ever want it.
2. Needs rebase — conflicts with master
This is based on the old master. 7b8ddea (add Kimi, drop Anthropic/Gemini/Antigravity) conflicts in all 4 files — ProviderKey, detectProvider, PROVIDER_LABELS, and canShowForProvider all need reworking onto the new provider list. Also note the imports are still @mariozechner/*; coordinate with #2 (the scope migration) for merge order or fold that in during the rebase.
Minor (non-blocking)
- Missing a test for the
"unrecognized response shape"branch (e.g. response withoutusageor non-numeric percents). - In
canShowForProvider, the(auth as AuthData)casts are redundant —AuthDataalready declares the"opencode-go"field.
The core of the feature is solid — with the alias removed and rebased onto current master, this should be good to go.
Adds OpenCode Go to /usage.