Cloudflare Workers AI
Serverless AI inference on Cloudflare's network, with text-to-image models callable over a REST API or a Workers binding.
- Always free
- Commercial use not stated
- No card required
Free tier
10,000 Neurons per day, reset at 00:00 UTC, usable with FLUX, Stable Diffusion and Leonardo text-to-image models.
- 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 devstill 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 you do
- Sign up at https://dash.cloudflare.com/sign-up/workers-and-pages (email, Google, GitHub or Apple).
- If you used Google, GitHub or Apple, set a password at https://dash.cloudflare.com/forgot-password; API token creation requires one.
- 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.
- To use the Workers binding instead, approve the browser prompt from
npx wrangler login.
How your agent gets access
API key
- Get it at
- dash.cloudflare.com/?to=/:account/ai/workers-ai
- Env var
CLOUDFLARE_API_TOKEN
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
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.
Check it worked
curl -s "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/models/search?search=flux" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
Sources
- developers.cloudflare.com/workers-ai/platform/pricing
- developers.cloudflare.com/workers-ai/platform/limits
- developers.cloudflare.com/workers-ai/platform/errors
- developers.cloudflare.com/workers-ai/platform/data-usage
- developers.cloudflare.com/workers-ai/models/flux-1-schnell
- developers.cloudflare.com/workers-ai/models/flux-2-dev
- developers.cloudflare.com/workers-ai/models/flux-2-klein-4b
- developers.cloudflare.com/workers-ai/models/flux-2-klein-9b
- developers.cloudflare.com/workers-ai/models/lucid-origin
- developers.cloudflare.com/workers-ai/models/phoenix-1.0
- developers.cloudflare.com/workers-ai/models/stable-diffusion-xl-base-1.0
- developers.cloudflare.com/workers-ai/models/stable-diffusion-xl-lightning
- developers.cloudflare.com/changelog/post/2026-01-15-flux-2-klein-4b-workers-ai
- developers.cloudflare.com/changelog/post/2026-07-28-models-require-workers-paid
- developers.cloudflare.com/workers-ai/get-started/rest-api
- developers.cloudflare.com/workers-ai/get-started/workers-wrangler
- developers.cloudflare.com/api/resources/ai/methods/run
- developers.cloudflare.com/api/resources/ai/subresources/models/methods/list
- developers.cloudflare.com/fundamentals/api/get-started/create-token
- developers.cloudflare.com/fundamentals/api/reference/sdks
- developers.cloudflare.com/fundamentals/account/create-account
- developers.cloudflare.com/fundamentals/user-profiles/login
- developers.cloudflare.com/workers/platform/pricing
- developers.cloudflare.com/workers/wrangler/install-and-update
- developers.cloudflare.com/workers/wrangler/commands/general
- developers.cloudflare.com/workers/wrangler/system-environment-variables
- www.cloudflare.com/products/workers
- www.cloudflare.com/service-specific-terms-developer-platform
- developers.cloudflare.com/workers-ai/llms.txt