AI Image Generation API
POST /api/generate-image $0.07 per call
USDC on Base · x402
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, 3:2, 21:9 and more. Pass {url} or {image_base64} alongside the prompt to EDIT an existing image ('put a red hat on the dog'). 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 image URL to edit instead of generating from scratch (png, jpeg, gif, webp; max 5 MB) | |
image_base64 | body | Alternative to url: the image to edit as base64 (data URI accepted) |
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"
}MCP tool: post_generate_image — via npx -y webbersites-x402-mcp (local, key stays on your machine) or the remote endpoint https://api.webbersites.com/mcp.
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.