AI Image Generator
Generate images from text prompts with Workers AI at the edge
Generate PNG images from text prompts using Workers AI and the @cf/black-forest-labs/flux-1-schnell model at the edge.
Features
- Generate PNG images from text prompts at the edge
- Workers AI image model (
@cf/black-forest-labs/flux-1-schnell) - Returns binary image responses directly from the Worker
- No external image API keys required
API Reference
GET /generate
Generates a PNG image from the provided text prompt.
Prop
Type
Example Request
curl "https://your-worker.workers.dev/generate?prompt=a%20sunset%20over%20snow-capped%20mountains" \
--output image.pngSuccess Response
Returns a PNG image with the following header:
Content-Type: image/pngError Response
{
"error": "Missing or invalid query parameter: prompt",
"code": "INVALID_PROMPT"
}Error Codes
400- Missing or invalidprompt(INVALID_PROMPT)502- Workers AI model run failed (AI_ERROR)
Use Cases
- Prototype AI image generation without external API keys
- Generate placeholder or marketing visuals from text at the edge
- Learn Workers AI image models in a stateless Worker
- Build creative tools that return binary image responses directly
Limitations
- Workers AI image generation is subject to usage limits by plan
- Fixed model and parameters; no style, size, or batch controls in this experiment
- Returns a single PNG per request; no async jobs or storage
- Public endpoint with no authentication or rate limiting
Deployment
Deploy
Enable the Workers AI binding (AI) in your Worker settings. The deploy button configures this automatically via wrangler.json. Requires a Cloudflare account with Workers AI enabled.
Test your deployment
curl "https://your-worker.workers.dev/generate?prompt=a%20sunset%20over%20snow-capped%20mountains" \
--output image.pngLocal Development
cd apps/experiments/ai-image-generator
npm install
npm run devTest locally:
curl "http://localhost:8787/generate?prompt=a%20cyberpunk%20cityscape" \
--output image.pngCloudflare Features Used
- Workers - Edge compute runtime
- Workers AI -
@cf/black-forest-labs/flux-1-schnellimage generation model