# Cloudflare Workers AI

> Serverless AI inference on Cloudflare's network, with text-to-image models callable over a REST API or a Workers binding.

- Category: [Image generation](https://freetier.tech/c/image-generation.md)
- Free tier: Always free. 10,000 Neurons per day, reset at 00:00 UTC, usable with FLUX, Stable Diffusion and Leonardo text-to-image models.
- Commercial use not stated
- No card required
- Pricing: https://developers.cloudflare.com/workers-ai/platform/pricing/
- Last verified: 2026-10-28

## Free tier limits

- 10,000 Neurons per day on Workers Free and Workers Paid
- The daily allocation resets at 00:00 UTC
- Text-to-Image rate limit: 720 requests per minute (beta models may be lower)
- FLUX.1 [schnell]: 4.80 Neurons per 512x512 tile plus 9.60 per step (4 steps by default, 8 max)
- FLUX.2 [klein] 4B: 5.37 Neurons per input 512x512 tile, 26.05 per output tile
- FLUX.2 [dev]: 18.75 Neurons per input 512x512 tile per step, 37.50 per output tile per step
- FLUX.2 [klein] 9B: 1,363.64 Neurons for the first megapixel (1024x1024), 181.82 per subsequent megapixel
- Leonardo Phoenix 1.0: 530 Neurons per 512x512 tile plus 10 per step
- Leonardo Lucid Origin: 636 Neurons per 512x512 tile plus 12 per step
- Beta models Stable Diffusion XL base 1.0 and SDXL-Lightning: listed at $0.00 per step

## Gotchas

- Workers Free has no pay-as-you-go; once the 10,000 daily Neurons are used, requests fail with HTTP 429 (error 3036) until 00:00 UTC.
- Neuron cost depends on the model, the number of 512x512 tiles and the step count; Leonardo models cost 530-636 Neurons per tile versus 4.80 for FLUX.1 [schnell].
- Inference from `wrangler dev` still runs on your Cloudflare account and counts toward the daily allocation.
- Each model has its own license or provider terms (see its model page), and Cloudflare's terms require following them; check them before commercial use.
- Cloudflare can make a model Workers Paid only, after which Free requests get HTTP 403 (error 5035); the July 2026 change covered a few resource-intensive LLMs, not image models.
- Requests can fail with HTTP 429 error 3040 (Out of capacity); retry later.
- Response formats differ by model; FLUX models and Lucid Origin return JSON with a base64 image, while Stable Diffusion XL and Phoenix return raw PNG or JPEG bytes.
- FLUX.2 models take multipart form data, even for a prompt-only request.
- Accounts created with Google, GitHub or Apple sign-in have no password at first, and creating API tokens requires one.

## Setup

### What the human does

1. Sign up at https://dash.cloudflare.com/sign-up/workers-and-pages (email, Google, GitHub or Apple).
2. If you used Google, GitHub or Apple, set a password at https://dash.cloudflare.com/forgot-password; API token creation requires one.
3. Open Workers AI at https://dash.cloudflare.com/?to=/:account/ai/workers-ai, select Use REST API > Create a Workers AI API Token > Create API Token, then copy the token and the Account ID.
4. To use the Workers binding instead, approve the browser prompt from `npx wrangler login`.

### How the agent gets access

#### API key

- Get it at: https://dash.cloudflare.com/?to=/:account/ai/workers-ai
- Env var: `CLOUDFLARE_API_TOKEN`
- Notes: Also set CLOUDFLARE_ACCOUNT_ID from the same dialog. A custom token needs Workers AI Read and Workers AI Edit. The token is shown only once.

#### CLI login

- Install: `npm i -D wrangler@latest`
- Run: `npx wrangler login`
- Notes: For Workers that call models through the AI binding (env.AI). Opens a browser; use --device when the localhost:8976 callback is unreachable. In headless environments, set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID instead.

### Verify

```sh
curl -s "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/models/search?search=flux" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
```

## Docs

- Quickstart: https://developers.cloudflare.com/workers-ai/get-started/rest-api/
- llms.txt: https://developers.cloudflare.com/workers-ai/llms.txt

## Sources

- https://developers.cloudflare.com/workers-ai/platform/pricing/
- https://developers.cloudflare.com/workers-ai/platform/limits/
- https://developers.cloudflare.com/workers-ai/platform/errors/
- https://developers.cloudflare.com/workers-ai/platform/data-usage/
- https://developers.cloudflare.com/workers-ai/models/flux-1-schnell/
- https://developers.cloudflare.com/workers-ai/models/flux-2-dev/
- https://developers.cloudflare.com/workers-ai/models/flux-2-klein-4b/
- https://developers.cloudflare.com/workers-ai/models/flux-2-klein-9b/
- https://developers.cloudflare.com/workers-ai/models/lucid-origin/
- https://developers.cloudflare.com/workers-ai/models/phoenix-1.0/
- https://developers.cloudflare.com/workers-ai/models/stable-diffusion-xl-base-1.0/
- https://developers.cloudflare.com/workers-ai/models/stable-diffusion-xl-lightning/
- https://developers.cloudflare.com/changelog/post/2026-01-15-flux-2-klein-4b-workers-ai/
- https://developers.cloudflare.com/changelog/post/2026-07-28-models-require-workers-paid/
- https://developers.cloudflare.com/workers-ai/get-started/rest-api/
- https://developers.cloudflare.com/workers-ai/get-started/workers-wrangler/
- https://developers.cloudflare.com/api/resources/ai/methods/run/
- https://developers.cloudflare.com/api/resources/ai/subresources/models/methods/list/
- https://developers.cloudflare.com/fundamentals/api/get-started/create-token/
- https://developers.cloudflare.com/fundamentals/api/reference/sdks/
- https://developers.cloudflare.com/fundamentals/account/create-account/
- https://developers.cloudflare.com/fundamentals/user-profiles/login/
- https://developers.cloudflare.com/workers/platform/pricing/
- https://developers.cloudflare.com/workers/wrangler/install-and-update/
- https://developers.cloudflare.com/workers/wrangler/commands/general/
- https://developers.cloudflare.com/workers/wrangler/system-environment-variables/
- https://www.cloudflare.com/products/workers/
- https://www.cloudflare.com/service-specific-terms-developer-platform/
- https://developers.cloudflare.com/workers-ai/llms.txt

JSON: https://freetier.tech/api/v1/services/cloudflare-workers-ai.json
