On a signed-in agy, `agy models` takes about 4.4s and `agy acp`'s
session/new about 3s. provider.models() needed three calls before
claude-opus-5-5, claude-sonnet-5-5 and gpt-oss-120b showed up, and
OpenCode 2.x calls it once.
What changed:
- packages/agy-cli/index.mjs:
- The offered-model probe now starts in listAgyModels' .then, as soon as
a non-empty list arrives and a caller asked for probeOffered. It no
longer waits for the next models() call. A hung or failed `agy models`
still never spawns the probe.
- probeSignedIn reuses the `agy models` stdout it already has. The same
parser (parseAgyModels, split out of listAgyModels) fills
cachedModelCatalog, and the probe starts. Sign-in waits for the probe
for at most 3s.
- The offer (acpOfferedModels, acpOfferedKey, offeredProbeAt and any
in-flight probe) is forgotten when agyPath changes and after a new
sign-in finishes. A generation counter drops the answer of a probe
that started before the reset.
- provider.warming() returns a promise while a list or probe is still
running, and null when nothing is.
- scripts/opencode2.mjs, copied byte for byte to every
packages/*/opencode2.mjs: after the first background refresh, the
adapter awaits hooks.provider.warming() once, for at most 60s, and then
refreshes once more. It does not loop. Plugins without warming() behave
as before.
- Not done: the issue's on-disk catalog cache (point 3), skipped as asked.
Known gap: agy-cli has no `config` hook, so under OpenCode 2.x the adapter
lists no provider for it. refresh() returns before it calls
provider.models(), so the follow-up refresh can't add agy's models on 2.x
until agy-cli gets a config hook.
Tests: test/testkit.mjs's fake agy takes a sessionNewDelayMs. The new
tests in test/catalog.mjs set 1.5s on both `agy models` and session/new
and wait for state through warming(), with no fixed sleeps:
- On a slow cold start, the first models() after warming lists Claude and
GPT, from one probe spawn.
- authorize() on a signed-in agy fills the catalog, and the next models()
runs no second `agy models`.
- The sign-in wait is bounded: with a 6s session/new, sign-in returns in
about 4.5s.
- Changing agyPath probes again.
The hang test now awaits warming() before it counts acp spawns.
scripts/opencode2.test.mjs: the warming list is read a second time when
warming ends, and only once when nothing is warming.
Run on Linux (a separate test Mac was over its load limit):
- packages/agy-cli bun test: 17 pass, 0 fail.
- bun scripts/check.mjs agy-cli: ok.
- bun scripts/check.mjs (all packages): ok.
- Root bun test in a temp HOME: 8530 pass, 19 skip, 0 fail.
Broken by hand on Linux, each red, then restored green:
- No probe in the .then: the slow cold-start test.
- probeSignedIn drops the list: the authorize and bounded-wait tests.
- agyPath change keeps the old offer: the agyPath test.
- Unbounded sign-in wait: the bounded-wait test (7514ms).
- Probe also on a failed listing: the hang test.
- origin/main's index.mjs with the new tests: all four #1064 tests.
- Adapter reads the list once: the warming adapter test, and the
copy-identity check.
Not tried: a real agy (no Google sign-in, no network). The reset after
login.finish has no unit test of its own.
Reported-by: hiee3
@magpie-community/opencode-cloudflare-workers-ai-auth
A provider plugin for OpenCode 1.x and
magpie that signs in to Cloudflare Workers AI with your
API token and serves it as a provider every agent can use: 28+ models discovered
live from models.dev, paid-only models flagged,
and a daily Neurons allowance row in magpie quota.
Not affiliated with or endorsed by Cloudflare.
What you need
| Item | Where to find it |
|---|---|
| Cloudflare Account ID | 32 hex characters, on the dashboard's Account home → right sidebar |
| Cloudflare API token | Dashboard → avatar → My Profile → API Tokens → create a Custom Token with Account → Workers AI → Edit (add Account Settings → Read for the plan name and Account Analytics → Read for today's actually-used Neurons in magpie quota) |
| magpie | 0.1.1110 or later, or OpenCode 1.x |
No zones need to be selected on the token. Free and Paid plans both get 10,000 Neurons/day free; eight frontier models need Workers Paid or prepaid AI Gateway credits (flagged below).
The quota card shows the daily free allowance as a count and a Used / Left percentage, resetting at 00:00 UTC. Paid or unconfirmed plans keep this window informational; only a confirmed Free plan stops routing when it is spent.
Install in magpie
magpie plugin add @magpie-community/opencode-cloudflare-workers-ai-auth # from npm
magpie plugin add /path/to/folder # local copy
Then sign in:
magpie plugin login cloudflare-workers-ai
| Prompt | What to enter |
|---|---|
| API Token | the Workers AI:Edit token from the table above |
| Account ID (optional) | 32 hex characters; leave empty to use the plugin's accountId option |
- Each sign-in is one account. Sign in again to add another one (e.g. a Free
account and a Paid account) — magpie fails over between them automatically;
magpie quotashows each account's row separately. - Sign in again with the same Account ID to replace that account, e.g. to rotate the token. Sign-ins are kept in magpie's account storage; nothing is written outside magpie's config.
- If Cloudflare refuses the token, magpie marks the account and asks you to sign in again.
Commands you'll actually use
magpie providers # is the provider signed in?
magpie provider test cloudflare-workers-ai # one small request (~300 ms in our sandbox)
magpie provider test cloudflare-workers-ai @cf/meta/llama-3.3-70b-instruct-fp8-fast
magpie quota # plan + Neurons/day window
magpie claude cloudflare-workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast # run Claude Code on it
magpie codex cloudflare-workers-ai/@cf/openai/gpt-oss-120b # or Codex, same idea
magpie plugin logout cloudflare-workers-ai # remove the sign-in
Models are named cloudflare-workers-ai/@cf/<org>/<model> — the same IDs
models.dev lists for the provider, refreshed hourly.
In OpenCode 1.x
opencode.json:
{ "plugin": ["@magpie-community/opencode-cloudflare-workers-ai-auth"] }
then opencode auth login → Cloudflare Workers AI (same two fields).
Paid-only models
Eight models are gated by Cloudflare behind Workers Paid or prepaid AI Gateway credits and are flagged (Paid) in the name — that is exactly how the model picker renders it:
@cf/moonshotai/kimi-k2.6,
@cf/moonshotai/kimi-k2.7-code, @cf/zai-org/glm-5.2, @cf/zai-org/glm-5.3,
@cf/zai-org/glm-5.3-flash, @cf/deepseek-ai/deepseek-v4-flash-0731,
@cf/deepseek-ai/deepseek-v4.1-flash-1017,
@cf/deepseek-ai/deepseek-v4-pro-0813
Everything else counts only against the shared 10,000 Neurons/day allowance (billed on a Paid account past it), so no model carries a free badge by design.
Options
magpie plugin options opencode-cloudflare-workers-ai-auth '{"accountId": "…", "discoveryTTLMs": 1800000}'
| Option | Default | Notes |
|---|---|---|
accountId |
— | default Account ID used when a sign-in leaves it empty |
apiKey |
— | default token (the sign-in's key wins) |
baseTemplate |
see below | template target that the Account ID is interpolated into |
discoveryTTLMs |
3600000 |
catalog refresh interval |
baseTemplate default (insertion target, Account ID interpolated per account):
https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/v1
Troubleshooting
| You see | Meaning |
|---|---|
| Model list empty, provider missing | magpie plugin add . again, then magpie plugin --json: the error field says why (catalog fetch failed, or the token was refused) |
magpie: the sign-in failed: 需要 API Token |
the token prompt was left empty — re-run magpie plugin login cloudflare-workers-ai |
401 Authentication error from provider test |
the token was refused: check scope (Workers AI:Edit) or sign in again |
403 from provider test |
token and Account ID don't match |
400 No route for that URI |
if this survives a re-plugin add, it's a stale plugin version — the current proxy normalizes template URLs; file an issue |
Model … absent from the current catalog |
the model id isn't in models.dev's cloudflare-workers-ai section; pick a listed model |
| 400 on a (Paid) model | your plan is Free and the model needs Workers Paid or AI Gateway credits |
| Quota row shows the fallback plan text | the token lacks Account Settings → Read; the escalation is purely cosmetic — the Neurons window is still shown |
Quota row shows 10,000 / 10,000 remaining but requests fail with used up your daily free allocation |
the token lacks Account Analytics → Read, so the used amount is unknown and magpie renders the allowance as untouched — grant that scope and refresh |
Development
node --check src/index.mjs # parse guard (the upstream bug that started this fork)
node --test # 23 tests, no network needed
sh scripts/sandbox.sh login # magpie 0.1.1326 in a throwaway HOME
sh scripts/sandbox.sh test # provider test inside that sandbox
sh scripts/sandbox.sh json # plugin --json inside that sandbox
scripts/sandbox.sh keeps its HOME in .sandbox/ (git-ignored), so your real
magpie, agents and sign-ins are never touched.
Plugin contract notes
- Single async plugin function;
config,auth.methods(oneapimethod withpasswordprompts),auth.loader,auth.usageandprovider.modelshooks loader(getAuth, provider)reads the contract account shape (auth.key,auth.metadata.accountId); the legacy OpenCode multi-method shape works tooauthorizereturns{ type: "success", key, metadata }/{ type: "failed", error }- On catalog failure at load,
config()degrades to an empty model list instead of throwing; the per-accountprovider.modelsserves the cached catalog after - One file, zero runtime dependencies, ESM,
node >= 20
Version / license
| Version | 0.0.4 |
| License | MIT — Copyright (c) 2026 Guislabert |
| Runtime | Node.js >= 20, ESM only |
| Author | @Guislabert |
| 中文 | README.zh-CN.md |
MIT © Guislabert