QwenCloud Token Plan quota: is a qwencloud-CLI subprocess adapter acceptable, or too much of a workaround?
Context
QwenCloud Token Plan users get Balance query unsupported in the sidebar, because the
balance adapters in src/balance-providers.ts all speak "monetary balance with an API key",
while Token Plan bills in Credits from a subscription quota.
Worse, the quota cannot be queried with the key at all: the Token Plan dedicated key
(sk-sp-*) is inference-only. Every billing route answers ConsoleNeedLogin, and the
endpoint only routes /compatible-mode/v1/*, /apps/anthropic/v1/messages and
/api/v1/services/aigc/*. Confirmed in the QwenCloud Token Plan FAQ and independently in
steipete/CodexBar#2328.
So there are only two ways to read the number: the console gateway (browser cookie +
sec_token, undocumented) or the official @qwencloud/qwencloud-cli (device-flow login).
What my fork does
Branch: aiev/opencode-visual-cache → feat/qwencloud-token-plan-quota
(commits c90258d, 2a9594d)
- New balance provider
qwencloudthat runsqwencloud usage summary --format jsonas a subprocess and parsestoken_plan(remainingCredits / totalCredits / usedPct / resetDate) into the existingBalanceEntryshape, rendered asToken Plan 72%with an expandable detail row. BalanceProvidergains two optional fields:aliases(so OpenCode providerIDalibaba-token-plan/bailian-token-plan*resolve to this adapter) andrequiresKey: false(poll without an API key; the credential lives in the CLI login).node:child_processis resolved lazily throughprocess.getBuiltinModule, so hosts without it degrade to an error message instead of a crash. 8s timeout, inside the existing 10s poll budget.- Distinct error codes and copy in all four locales:
CLI(not installed),AUTH(needsqwencloud auth login),NOPLAN(the CLI account has no Token Plan), andEMPTY(response missing fields). /cache-balance-keyis a no-op for this provider (a pasted key would be useless) and the provider menu marks it as(qwencloud CLI).
No new runtime dependency; the plugin only requires the CLI to be present on PATH.
Why I consider it a gambiarra
- A TUI panel spawning a global CLI is an unusual dependency shape — it silently depends on the user installing and logging into a second tool that OpenCode knows nothing about.
- The CLI's own quota path is currently broken for a large slice of users: for accounts in
the gray cohort,
fetchTokenPlan()inQwenCloud/qwencloud-clisrc/services/tokenplan-service.tscallsGetSeatSubscriptionSummarywithproductCode: codes.teamsonly, and an Individual plan never appears there — sousage summaryreportssubscribed: false, totalCredits: 0for an active Individual Pro subscription (I verified this against a real account that the console shows asIndividual Plan · Pro · Active · Monthly Quota 180,000 · Remaining 99.6%). My fork shows the honestNOPLANmessage in that case, but the number is still missing until the CLI is fixed. - Polling spawns a process every 5 minutes per running TUI.
Alternatives I rejected
- Console gateway with a pasted cookie (
cs-data.qwencloud.com/data/api.json,zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/*): works today, but it is undocumented, breaks whenever the console changes, and would store a full session credential in the plugin KV (which is already plaintext for other providers — a session cookie is strictly worse than an API key). - Nothing at all: hide the balance row for Token Plan. Simple, but leaves the user without any quota signal in the tool where they burn it.
Question for the maintainers
Would you accept this as-is behind an opt-in flag, accept it only as a separate
"quota providers" module (so balance-providers.ts stays HTTP-only), or do you prefer not
to ship any CLI-subprocess dependency at all? If the last one, I am happy to keep it in my
fork and just fix the unsupported copy so it says "quota-based plan, see console" instead
of a generic unsupported message.
Happy to open a PR once you tell me which shape you want.
Update: the console-cookie source now works and is implemented — the CLI source does not
I went down both paths since filing this. Result, with evidence from a real account (Individual / Pro, ap-southeast-1):
The CLI adapter is useless for Individual plans. usage summary returns
token_plan.subscribed = false, totalCredits = 0 for an account the console shows as
Individual Plan · Pro · Active · Monthly quota 180,000 · Remaining 99.6%. I patched the
CLI locally (gray-cohort fallback to the legacy DescribeFrInstances path) and ran the
patched build against the same account: still false. Direct probes show why no
client-side fix exists — GetSeatSubscriptionSummary returns {"Code":"Success","Data":{}}
for the teams and personal product codes, DescribeFrInstances returns TotalCount: 0,
GetSubscriptionDetail errors out, and the apikeyMgr./tokenplan/personal/* APIs only
answer when they are wrapped in a console session. Tracked upstream as
QwenCloud/qwencloud-cli#13.
So the NOPLAN message my fork shows is accurate but the number never arrives.
The console gateway does return it, and that is now implemented in the same branch
(14a440f):
| call | returns |
|---|---|
GET home.qwencloud.com/tool/user/info.json |
data.secToken (CSRF) |
POST cs-data.qwencloud.com/data/api.json → tokenplan/personal/api/v2/usage |
per1MonthPercentage: 0.015465678, per1MonthResetTime: 1794326400000 |
→ …/subscription |
specCode: "pro", status: "VALID", remainingDays: 31, endTime |
→ …/quota-config |
pro: { five_hour: 12000, monthly: 180000 }, plus lite/essential/standard/addon |
Rendered as Token Plan 98.5% with details Plan: PRO, Credits: 177216 / 180000,
Used: 1.5%, Remaining: 98.5%, Reset: 31 days. Multi-window accounts (5h + week + month)
emit one used/remaining/reset row per window, Credits taken from the widest ceiling.
Shape of the change:
BalanceProvidergainscredentialSlot/optionalKeyPrompt/keySourceLabel, so an adapter can take an optional credential in its own KV slot (cache_panel.balance.qwencloud.cookie) instead of the API-key slot.- Keyless providers no longer auto-reuse an OpenCode API key in
pollBalance— that key cannot query billing anyway, and reusing it would have shipped ansk-*string to the console gateway as if it were a cookie. The pasted value is also shape-checked (looksLikeQwenCookie) before any request. - Console source is used when a cookie is configured; otherwise the CLI subprocess fallback
from the first commit still runs. New
COOKIEerror code (expired session) in all four locales; the menu marks the provider(qwencloud CLI)→(console cookie). parseQwenConsoleQuotais pure and tested against the captured payloads (tests/qwen-token-plan.test.ts, +106 lines). typecheck / build / tests all green.
What I need from you before this can be a PR
The remaining objection is mine, not yours: storing a browser session cookie in the plugin
KV is worse than storing an API key. It is broader than this one feature (full account
access, login_qwencloud_ticket is httpOnly so it can only be obtained from DevTools), it
expires on the console's schedule, and the endpoint is undocumented so it can break without
notice. Mitigations already in the commit: the value is only sent to
home.qwencloud.com / cs-data.qwencloud.com, it is masked in the UI like any other key,
never logged, and removing it falls back to the CLI.
So, concretely — which of these would you take?
- As-is: cookie-capable provider, documented in README, opt-in by construction (nothing happens until the user pastes a cookie).
- Hard-gated: the console path only compiles/loads behind an explicit setting
(e.g.
cache_qwen_console=1), so the default build never ships the code path. - Only the honest failure: drop both adapters, keep
aliasesso Token Plan stops sayingBalance query unsupportedand instead says "quota-based plan, see the console", and let #13 in the CLI repo decide when the number becomes queryable with the device-flow token.
I would take 1, ship 2 if you prefer, and I would not be sad with 3. Fork branch is
aiev/opencode-visual-cache → feat/qwencloud-token-plan-quota
(c90258d, 2a9594d, 14a440f) and it is what I run daily.