POST
/api/generate$0.02–$0.05🎨 AI Image Generation
Generate high-quality AI images from text prompts using Flux models (Schnell, Dev, Pro) via fal.ai. Choose your model based on speed vs quality tradeoff. Schnell is fastest and cheapest; Pro is highest quality.
💡 flux-schnell: $0.02 | flux-dev: $0.03 | flux-pro: $0.05
Request Body
Response Fields
Code Examples
cURL
bash
curl -X POST https://sparkforge.sh/api/generate \
-H "Content-Type: application/json" \
-H "X-PAYMENT: <x402-payment-token>" \
-d '{
"prompt": "A neon-lit cyberpunk city at night, rain reflections",
"model": "flux-schnell",
"width": 1024,
"height": 1024
}'Python
python
import requests
response = requests.post(
"https://sparkforge.sh/api/generate",
headers={
"Content-Type": "application/json",
"X-PAYMENT": "<x402-payment-token>"
},
json={
"prompt": "A neon-lit cyberpunk city at night, rain reflections",
"model": "flux-schnell",
"width": 1024,
"height": 1024
}
)
data = response.json()
print(data["image_url"]) # → CDN URL of generated imageTypeScript / Node.js
typescript
import { wrapFetchWithPayment } from "@x402/fetch";
const fetch402 = wrapFetchWithPayment(fetch, wallet);
const res = await fetch402("https://sparkforge.sh/api/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
prompt: "A neon-lit cyberpunk city at night, rain reflections",
model: "flux-schnell",
width: 1024,
height: 1024,
}),
});
const { image_url, model, seed } = await res.json();Example Response
json
{
"image_url": "https://fal.media/files/abc123/generated.jpg",
"model": "flux-schnell",
"seed": 42069,
"price": "$0.02"
}💳 Payment via x402
This endpoint costs $0.02–$0.05 per call, paid in USDC on Base, Polygon, or Solana. Use the @x402/fetch library to handle payments automatically, or implement the x402 handshake manually.
bash
# Free demo mode (no payment)
curl https://sparkforge.sh/api/generate?demo=true
# Or try via MCP (Claude Desktop, Cursor, Windsurf)
# Add to mcp config: { "url": "https://sparkforge.sh/api/mcp" }