AI Image Generation API
AI IMAGE GENERATION — POST {prompt} and get back a PNG, base64 in JSON (?raw=1 for raw bytes). Gemini 2.5 Flash Image (nano-banana): photoreal scenes, illustrations, product shots, UI mockups — renders text in images well. Optional {aspect_ratio}: 1:1 (default), 16:9, 9:16, 4:3 + 6 more. Reference images: pass {url} or {image_base64}, or up to 3 in {reference_images}, to edit, restyle, or compose ('put this product on this beach'). The x402 payment IS the auth.
Parameters
| Name | In | Description | |
|---|---|---|---|
prompt | body | required | What to generate, up to 2,000 chars — subject, style, composition, lighting |
aspect_ratio | body | 1:1 (default), 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, or 21:9 | |
url | body | Optional public URL of a reference image to edit/restyle instead of generating from scratch (png, jpeg, gif, webp; max 5 MB) | |
image_base64 | body | Alternative to url: a reference image as base64 (data URI accepted) | |
reference_images | body | Up to 3 reference images (URLs or base64 strings, 6 MB combined) to compose — product placement, style transfer, character consistency |
Example request
curl -X POST "https://api.webbersites.com/api/generate-image" \
-H "Content-Type: application/json" \
-d '{"prompt":"A watercolor fox reading a newspaper in a rainy cafe window","aspect_ratio":"16:9"}'
# first call returns 402 + payment requirements; an x402 client pays and retries automaticallyExample response
{
"image_base64": "iVBORw0KGgo…",
"content_type": "image/png",
"bytes": 812344,
"mode": "generate",
"aspect_ratio": "16:9",
"model": "gemini-2.5-flash-image"
}How payment works
There is no signup and no API key. Call the endpoint; it replies 402 Payment Required with machine-readable payment requirements. Your client signs a USDC transfer authorization (EIP-3009, gasless) and retries with the X-PAYMENT header — @x402/fetch does this automatically. See the overview for a working snippet.