The Real Problem
AI image generation models (Flux, Stable Diffusion, DALL-E) incur per-generation GPU compute and API fees. Offering image generation without payment verification leads to server exhaustion or forcing users into monthly subscriptions.
Real-World Example: For example, an AI avatar generator could charge $0.05 per generated image, triggering the GPU pipeline only after payment is verified.
How aipp Solves It
aipp gates your image generation endpoint with an L402/x402 402 challenge. The client pays the prompt price upfront, receives a payment receipt, and resubmits the prompt. Your server verifies the receipt and invokes the model.
Step-by-Step Payment Flow
STEP 01
Submit Prompt
User or AI agent posts prompt to /api/generate-image.
STEP 02
402 Invoice
Server returns HTTP 402 with Lightning or USDC invoice.
STEP 03
Payment Settlement
Client pays invoice via wallet.
STEP 04
GPU Model Runs
Server verifies payment preimage and executes image generation pipeline.
Scope & Boundaries
What aipp Does
- ✓ Gates GPU-intensive image generation endpoints behind verified payments
- ✓ Issues machine-readable L402 and x402 challenge headers
- ✓ Auto-forwards net earnings to merchant wallet
What aipp Does Not Do
- ✗ Does not generate images or host AI model weights
- ✗ Does not provide GPU hardware, Flux, DALL-E, or Stable Diffusion pipelines
- ✗ Does not store generated image assets
Implementation Pattern
Below is the minimal implementation pattern using standard aipp endpoints / SDK:
import { Aipp, l402Paywall } from 'aipp-sdk';
app.post('/api/generate-image', l402Paywall({
client: aipp,
amountUsd: 0.05
}), async (req, res) => {
const imageBytes = await runFluxModel(req.body.prompt);
res.json({ image_url: imageBytes });
});
Settlement Architecture Note:
• Lightning Rail: In hosted Lightning flows, payments route through aipp's Lightning gateway before net proceeds are automatically forwarded to your configured wallet address.
• Base USDC Rail: USDC transfers settle directly on-chain to your designated EVM wallet address.
• No Merchant Spending Balance: aipp does not maintain a spendable merchant balance or require manual withdrawal steps.
Requirements & Limitations
- aipp verifies payment; merchant operates the AI image model and hosting
- Funds auto-forward to merchant wallet according to payout threshold
Frequently Asked Questions
Can users pay with WebLN browser wallets?
Yes. Users with WebLN-compatible browser wallets or mobile Lightning wallets can complete payment directly.
Related Use Cases
Implement Paid AI Image Generation with aipp
Read the developer documentation or generate your API key to gate requests behind Lightning and Base USDC payments.