Integrate our AI image generation capabilities directly into your applications. The API is stateless and RESTful.
Endpoint: POST /generate
Authentication: Include your secret API key in the X-API-KEY header.
Request Parameters:
- prompt (Required): Text description of the image to generate.
- model:
flux-2-klein-4b (Default) or flux-1-schnell.
- photorealistic:
true or false. Appends quality-enhancing keywords.
- width / height: Integer (256-1280). Must be a multiple of 32.
- seed: Integer. Use for reproducible results. Defaults to random.
- safety_tolerance: Integer. 1 (Strict), 2 (Medium), 3 (Loose).
Request Body (JSON):
{
"prompt": "A cute robot astronaut in a flower garden",
"model": "flux-2-klein-4b",
"photorealistic": true,
"width": 1024,
"height": 576,
"seed": 123456,
"safety_tolerance": 2
}
Example cURL Command:
curl -X POST "https://your-worker-url.workers.dev/generate" \
-H "Content-Type: application/json" \
-H "X-API-KEY: YOUR_SECRET_KEY" \
-d '{
"prompt": "A futuristic cityscape at sunset",
"model": "flux-2-klein-4b",
"photorealistic": true,
"width": 1024,
"height": 576
}'
Response (JSON):
{
"success": true,
"modelUsed": "@cf/black-forest-labs/flux-2-klein-4b",
"extension": "png",
"imageData": "data:image/png;base64,iVBORw0KGgoAAA..."
}