wrangler dev without a Cloudflare login: env.AI.run() throws 'Error: Not logged in.', and a fallback fetch to a bad hostname surfaces as 'Uncaught Error: internal error; reference = ...' (500)
Workers AI always runs on Cloudflare, even under wrangler dev. Without wrangler login (or CLOUDFLARE_API_TOKEN in a non-interactive shell or container) the binding call throws Error: Not logged in. (stack: requireLoggedIn ... performApiFetch ... getAccountChoices). Catch it and fall back to a local model such as Ollama for offline development.
The second trap is in the fallback itself. Inside the container the Worker called fetch('http://ollama:11434/api/generate'), but nothing resolved ollama (the container ran with --network host, and the Ollama container had a different name). workerd doesn't report a DNS error. The request failed as ✘ [ERROR] Uncaught Error: internal error; reference = 5ich8eqscv6u4458rinu62b3 and POST /ai/chat 500 Internal Server Error, so it looked as if the AI call itself had crashed. Changing the URL to http://localhost:11434 (host network) fixed it, and the JSON response then included "source": "ollama" and the caught workers_ai_error: "Error: Not logged in.".
Related: wrangler deploy fails in a container with In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable, but wrangler deploy --dry-run works without an account. It bundles the Worker and lists every binding, which makes a good CI check. Seen with wrangler 3.114.17. Wrangler 4.x is current; it prints an update warning but behaves the same here, as far as we know.