Skip to Content
API ReferenceX402 Generate

X402 Generate

POST /api/x402/{slug}

Generate AI content using the X402 payment protocol. The first request returns a 402 challenge; the retry with a signed payment header triggers generation.

Path Parameters

ParameterTypeDescription
slugstringEndpoint identifier (e.g., nano-banana)

Request Body

{ "prompt": "A photorealistic sunset over the ocean", "aspect_ratio": "16:9", "output_format": "webp" }
FieldTypeRequiredDescription
promptstringYesGeneration prompt (1–10,000 characters)
aspect_ratiostringNoImage ratio: 1:1, 4:3, 3:4, 16:9, 9:16
output_formatstringNoOutput format: png, jpg, webp
resolutionstringNoOutput resolution (provider-dependent)

Headers

HeaderValueDescription
Content-Typeapplication/jsonRequired
X-PAYMENTBase64-encoded paymentRequired on retry after 402 challenge

Response — 402 Payment Required (First Request)

{ "error": "X402: Payment Required", "accepts": [ { "scheme": "exact", "network": "base", "asset": "USDC", "amount": "50000", "recipient": "0x1234...abcd" } ], "x402Version": 1 }

The amount is in USDC’s smallest unit (6 decimals). 50000 = $0.05 USDC.

Response — 200 Success (After Payment)

{ "success": true, "taskId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "statusUrl": "/api/task/a1b2c3d4-e5f6-7890-abcd-ef1234567890", "message": "Generation started. Poll statusUrl for results." }

Error Responses

StatusCodeDescription
400VALIDATION_ERRORInvalid or missing prompt
402Payment challenge (normal X402 flow)
404NOT_FOUNDEndpoint slug does not exist
429Rate limited (10 req/min)
500EXECUTION_ERRORGeneration failed server-side

Example with x402-fetch

import { wrapFetch } from 'x402-fetch' const fetchX402 = wrapFetch(fetch, { payerWalletPrivateKey: process.env.WALLET_PRIVATE_KEY, }) const res = await fetchX402('https://402claw.cloud/api/x402/nano-banana', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt: 'A cyberpunk cityscape' }), }) const { taskId, statusUrl } = await res.json()

Example with curl

# Step 1: Get 402 challenge curl -X POST https://402claw.cloud/api/x402/nano-banana \ -H "Content-Type: application/json" \ -d '{"prompt": "A cyberpunk cityscape"}' # Step 2: Sign payment and retry (see X402 spec for signing details) curl -X POST https://402claw.cloud/api/x402/nano-banana \ -H "Content-Type: application/json" \ -H "X-PAYMENT: <signed-payment>" \ -d '{"prompt": "A cyberpunk cityscape"}'
Last updated on