Repository navigation
cloudflare-workers-ai 0.0.6: a plan option counts the free allowance for routing - #1079
duchanghexuhe wants to merge 1 commit into
Conversation
…for routing when Cloudflare names no plan
|
Thanks @duchanghexuhe. The diagnosis is right: when Cloudflare's account answer has no The problem is where the switch lives. Could you ask for it at sign-in instead, next to Account ID, and keep it per account?
An account signed in before this has no |
Problem
Cloudflare's
GET /client/v4/accounts/{account_id}response for a Workers AI token carries noplanfield (verified against a real account: it returns onlyid,name,type,settings,legacy_flags,created_on). Soinfo?.result?.planis always empty,planstays at the fallback text,planIsFreestaysfalse, and the daily Neurons window is always emitted withaside: true.magpie's routing treats an
asidewindow as informational, so such a key's remaining allowance is permanently unknown to routing: it is sorted behind every account whose allowance is known, with "remaining allowance unknown" on the Routing page. This happens even when usage itself reads perfectly — GraphQL Analytics returns today'stotalNeuronsfine; it is the plan that can't be confirmed.Change
New plugin option
plan:freeorpaid.free→ plan is "Workers Free",planIsFree = true, the Neurons window is notaside, so routing counts the 10,000/day allowance and stops the key when it is spent.paid→ plan is "Workers Paid", the window staysaside(past the free allowance a Paid account is billed, not refused).The declaration wins over the best-effort account answer, so it works for tokens that are told no plan.
magpie plugin options opencode-cloudflare-workers-ai-auth '{"accountId": "…", "plan": "free"}'Also:
node --test.Why an option rather than detection
The account object has no plan to read, and
GET /accounts/{id}/subscriptions(the other place a Workers plan shows) needsAccount Billing → Read— a Workers AI token gets403 Authentication errorthere. Asking the user, who knows their plan, is the only reliable confirmation; magpie's side already requires a confirmed Free plan before a free allowance may bench an account, which is what this option supplies.No behaviour changes when the option is unset; existing tests are untouched and still pass.