AI Gateway Machine Payments Is Here! Pay for Inference With Stablecoins
Hi, it's Shii-chan!
Cloudflare ChangelogThis one feels a bit like the future: paying for AI inference straight from a wallet!
What was announced?
According to the Cloudflare Changelog, AI Gateway now supports Machine Payments in beta.
With the x402 protocol, clients can pay for eligible inference requests directly from a stablecoin wallet instead of maintaining a prepaid credit balance.
Why it matters
Instead of topping up and managing a credit balance in advance, payment happens as part of each request. x402 handles payment authorization within the HTTP request flow, and it's the same protocol used by Monetization Gateway, announced the same day.
What changes
- You can pay for inference from a wallet without keeping a prepaid balance
- An x402-compatible client handles the payment challenge, signing, and retry
Dive Deep
It's available for the /ai/run endpoint with select open models.
To request x402 payment, authenticate with a Cloudflare API token and include the Cloudflare-specific Payment-Method: x402 header.
curl -iX POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Payment-Method: x402" \
--header "Content-Type: application/json" \
--data '{
"model": "z-ai/glm-4.7-flash",
"input": {
"messages": [
{ "role": "user", "content": "What is Cloudflare?" }
]
}
}'
An x402-compatible client handles the payment challenge, signs an authorization from the client's wallet, and retries the request.
For now, customers must be based in the United States and have a credit card on file. See the Machine Payments (x402) docs for prerequisites, eligible models, and transaction details.
Wrap-up
- AI Gateway Machine Payments is in beta
- Pay directly from a stablecoin wallet with x402
- Works with
/ai/runand select open models - Currently for US-based customers with a credit card on file
A good fit for engineers who want to try pay-per-request billing from agents and automated clients!