|
| 1 | +--- |
| 2 | +title: Pay-Per-Request AI Inference with PPQ.ai and the 402 Protocol |
| 3 | +description: PPQ.ai now supports native 402 payments via MPP — no more credit topups needed to give your agent access to AI APIs. |
| 4 | +date: 2026-04-07 |
| 5 | +tags: [bitcoin, lightning, "402", mpp, ai-agents, ppq] |
| 6 | +image: /blog/images/2026-04-07-pay-per-request-ai-inference-ppq-402.jpg |
| 7 | +imageAlt: A glowing cyan lightning bolt striking a hexagonal API node, surrounded by floating payment packets and bitcoin symbols on a dark navy background. |
| 8 | +--- |
| 9 | + |
| 10 | +AI agents need access to AI APIs — but managing prepaid credits for each service is friction that doesn't belong in an autonomous workflow. PPQ.ai now supports native 402 payments via the MPP (Machine Payments Protocol), so your agent can pay for exactly what it uses, one request at a time. |
| 11 | + |
| 12 | +## The Old Way: Credit Topups |
| 13 | + |
| 14 | +Until recently, using PPQ.ai in an automated workflow meant maintaining a credit balance — loading funds upfront and hoping you'd budgeted correctly. For agents running in production, this worked well enough with NWC auto topups: you could set a threshold and have the wallet automatically top up from a lightning wallet when the balance ran low. |
| 15 | + |
| 16 | +That approach still works great. But it has overhead: you're managing a separate account balance, monitoring thresholds, and pre-funding access to an API you might only call occasionally. |
| 17 | + |
| 18 | +## The New Way: 402 Pay-Per-Request |
| 19 | + |
| 20 | +PPQ.ai now supports the [402 Payment Required](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/402) flow via MPP — Machine Payments Protocol. When your agent makes a request, PPQ.ai responds with a `402` and a payment request. Your agent pays, then retries the original request automatically. |
| 21 | + |
| 22 | +No balance to manage. No topups to configure. Your agent pays exactly what the request costs — nothing more. |
| 23 | + |
| 24 | +## Unified 402 Fetch in the Alby Payments Skill |
| 25 | + |
| 26 | +The [Alby bitcoin payments skill](https://github.com/getAlby/payments-skill) added a unified `fetch402` function that handles all three major 402 payment protocols in a single call: |
| 27 | + |
| 28 | +- **L402** — the original LSAT-based HTTP 402 protocol |
| 29 | +- **x402** — Coinbase's 402 variant |
| 30 | +- **MPP** — Machine Payments Protocol, used by PPQ.ai |
| 31 | + |
| 32 | +Install the skill: |
| 33 | + |
| 34 | +```bash |
| 35 | +npx skills add getAlby/payments-skill |
| 36 | +``` |
| 37 | + |
| 38 | +Once installed, your agent can call any 402-gated API without knowing which protocol it uses — the skill detects and handles it automatically. |
| 39 | + |
| 40 | +## Example: Generating an Image from PPQ.ai |
| 41 | + |
| 42 | +Here's what a real agent session looks like. Given the prompt: |
| 43 | + |
| 44 | +> "Generate an image from PPQ.ai using the 402 option and alby. The prompt: 'a superhero bee shouting 402 is awesome'" |
| 45 | +
|
| 46 | +The agent used the payments skill's CLI to make the request: |
| 47 | + |
| 48 | +```bash |
| 49 | +npx -y @getalby/cli fetch \ |
| 50 | + -u https://api.ppq.ai/v1/images/generations \ |
| 51 | + -m POST \ |
| 52 | + -H '{"Content-Type":"application/json"}' \ |
| 53 | + -b '{"model":"gpt-image-1","prompt":"a superhero bee shouting '\''402 is awesome'\''","n":1,"size":"1024x1024","quality":"low"}' \ |
| 54 | + --max-amount 0 |
| 55 | +``` |
| 56 | + |
| 57 | +The `--max-amount 0` flag tells the CLI to approve any payment amount automatically. The result: |
| 58 | + |
| 59 | +```json |
| 60 | +{ |
| 61 | + "created": 1775576898, |
| 62 | + "data": [ |
| 63 | + { |
| 64 | + "url": "https://api.ppq.ai/v1/media/gen_zp-zdKLuKQfAjO7m/0?sig=...", |
| 65 | + "content_type": "image/png" |
| 66 | + } |
| 67 | + ], |
| 68 | + "model": "gpt-image-1", |
| 69 | + "cost": 0.023 |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +The agent paid $0.023 — exactly the cost of that one image, settled over lightning. No account needed. No balance to top up. No API key to rotate. |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +## Example: Generating a Video from PPQ.ai |
| 78 | + |
| 79 | +The same 402 flow works for video generation. Given the prompt: |
| 80 | + |
| 81 | +> "Generate a short video of the superhero bee paying to pass through an API gate, using the 402 option and alby" |
| 82 | +
|
| 83 | +The agent made the request using `kling-2.1-master`: |
| 84 | + |
| 85 | +```bash |
| 86 | +npx -y @getalby/cli fetch \ |
| 87 | + -u https://api.ppq.ai/v1/videos \ |
| 88 | + -m POST \ |
| 89 | + -H '{"Content-Type":"application/json"}' \ |
| 90 | + -b '{"model":"kling-2.1-master","prompt":"A cartoon superhero bee wearing a cape flies up to a glowing hexagonal API gate on a dark navy background. The bee drops a tiny golden lightning bolt coin into a glowing slot on the gate. The gate flashes bright cyan and swings open. The bee zooms through triumphantly. Flat minimal animation style, no text, seamless loop.","duration":"5","aspect_ratio":"16:9","quality":"720p"}' \ |
| 91 | + --max-amount 0 |
| 92 | +``` |
| 93 | + |
| 94 | +The response comes back as a pending job with a `status_url` to poll. Once complete: |
| 95 | + |
| 96 | +```json |
| 97 | +{ |
| 98 | + "id": "gen_y5eM1UCxQT7bNVUd", |
| 99 | + "model": "kling-2.1-master", |
| 100 | + "status": "completed", |
| 101 | + "data": { |
| 102 | + "url": "https://api.ppq.ai/v1/media/gen_y5eM1UCxQT7bNVUd/0?sig=...", |
| 103 | + "content_type": "video/mp4" |
| 104 | + }, |
| 105 | + "cost": 0.92 |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +$0.92 for a 5-second 720p video, paid over lightning with no account or API key: |
| 110 | + |
| 111 | +<video src="/blog/images/superhero-bee-402.mp4" autoplay loop muted playsinline style="width:100%;border-radius:8px;"></video> |
| 112 | + |
| 113 | +## What the Alby Payments Skill Gives Your Agent |
| 114 | + |
| 115 | +Beyond 402 fetch, the skill covers the full range of bitcoin lightning operations an autonomous agent might need: |
| 116 | + |
| 117 | +- Send and receive lightning payments |
| 118 | +- Create invoices and check payment status |
| 119 | +- Fetch wallet balance and transaction history |
| 120 | +- Convert between fiat amounts and satoshis |
| 121 | +- Handle L402, x402, and MPP pay-per-request APIs |
| 122 | + |
| 123 | +It connects to any [Nostr Wallet Connect](https://nwc.dev) compatible wallet — including wallets created instantly at [lncurl.lol](https://lncurl.lol). |
| 124 | + |
| 125 | +## Conclusion |
| 126 | + |
| 127 | +402 payments turn AI APIs into true pay-per-use infrastructure. PPQ.ai's MPP support, combined with the unified 402 fetch in the Alby payments skill, means your agent can access AI inference — image generation, text, embeddings — without account management or pre-funded balances. Just a lightning wallet and a request. |
| 128 | + |
| 129 | +--- |
| 130 | + |
| 131 | +## Get started |
| 132 | + |
| 133 | +Need a Lightning wallet for your agent? Create one in one command — no sign-up, no KYC: |
| 134 | + |
| 135 | +```bash |
| 136 | +curl -X POST https://lncurl.lol |
| 137 | +``` |
| 138 | + |
| 139 | +You'll get back a Nostr Wallet Connect URI. Fund it with a few sats and your agent can pay for APIs, services, and tools autonomously. |
0 commit comments