HTTP 402 challenge, the on-chain
settlement check, metering and receipts. Your API stays exactly as it is.
Zero code
Configure everything in the dashboard: a slug and your upstream URL.
No SDK in your stack, no process to host.
Non-custodial
Every batch settles on-chain straight to a wallet you own. AiFinPay
never holds your funds — there is no withdraw step.
What you need
Set it up
1
Sign in and create a service
Go to dash.aifinpay.io, create an account and
confirm your email. Create a service: pick a name and paste your
payout wallet (
0x…). That wallet is where every settlement lands —
AiFinPay never custodies it.2
Configure the Gateway
Open Site settings and press Add gateway. Choose a slug
(lowercase, e.g. Requests to it are challenged with
acme-search), enter your upstream base URL (e.g.
https://api.acme.dev) and leave Enable after verification ticked.
Press Review changes, then Apply changes.Your paid endpoint is:HTTP 402 until the agent pays;
paid requests are forwarded to https://api.acme.dev/<any-path>.It starts forwarding once you verify the upstream’s domain. Until then it
answers 403 gateway_unavailable, not a 402. The Domain verification
card on Site settings shows the TXT record to add at your DNS provider
(_aifp-verify.api.acme.dev); the DNS connection queue on the account
Dashboard lists it too. Add it, then press Check DNS now. Leave the
record in place: it is re-checked, and the gateway stops forwarding if it
disappears.If your Site URL (under Profile & keys) is on the same host as the
upstream, one record verifies both.3
Lock your origin
Right now agents could still call
api.acme.dev directly and skip the
paywall — so nothing actually gets paid. Closing that hole takes one rule
at your edge: see Lock your origin below for the
Cloudflare WAF and nginx rules. Do not skip this step; without it the
gateway is a suggestion rather than a paywall.4
Verify your domain
Agents that pay through the AiFinPay MCP server do not pay a
site until its domain is verified. Set Site URL under Profile &
keys to your own domain (e.g.
https://acme.dev). Then, on the account
Dashboard, open the site’s Website domain row in the DNS
connection queue and add the TXT record it shows
(_aifp-verify.acme.dev) at your DNS provider.On the hosted gateway the agent calls gateway.aifinpay.io, so the MCP
checks only that your domain is verified, not which host it is.5
Watch the money arrive
That’s the whole setup. From here the dashboard does the reporting:
- Transactions — every settled payment with its on-chain receipt.
- Payout — your wallet, and every batch that settled to it.
- Traffic Heatmap / Overview — which routes agents actually call.
Lock your origin
Without this the gateway can be bypassed: an agent that callsapi.acme.dev directly gets your data for free. This rule is what makes the
paywall real.
Saving the Gateway config generated an origin secret (shown once — store it
like a password). The gateway injects it into every forwarded request:
If the origin is an API
Already have your own API keys or sessions for developers and paying
customers? Keep them — the lock composes: allow requests that carry your
auth, allow requests that carry
AIFP-Proxy-Auth, refuse the rest. Your
existing users never touch the gateway; it is an additional door for agents
you have never issued a key to. The blanket rule below is for an origin with
no auth of its own.If the origin serves pages to people
Cloudflare:api. subdomain when the
content allows it, and using the blanket rule there.
Keep any genuinely private paths — /api/*, /login, admin panels — closed by
their own rules as before. This rule is about crawlers, not authentication.
With the inverted rule, Verify lock in the dashboard will report the origin
as open. That is correct and not a misconfiguration: the check requests your
origin without the secret and expects to be refused, but it does not identify
itself as an AI crawler, so your rule deliberately lets it through. Verify lock
is meaningful for API origins; for a site with human traffic, test instead with
a crawler user-agent.
401/403. A green verdict means the only way in is through the paywall.
What your server receives
The gateway is a straight proxy, with three deliberate exceptions. Methods & body. Every HTTP method is forwarded — GET, POST, PUT, PATCH, DELETE. Request bodies are forwarded for everything except GET/HEAD. (Currently JSON bodies; raw binary uploads are not proxied yet — put file endpoints behind the middleware path if you need them today.) Headers in. The agent’s headers pass through unchanged, minus standard hop-by-hop headers and AiFinPay’s own control headers. Two are added, and neither can be forged from outside — any inbound copy is stripped before the real value is injected:AIFP-Quota-Remaining) plus a signed per-action billing receipt. You
may optionally answer with an AIFP-Billing header (JSON: action,
category, execution_time_ms) — it is folded into that billing receipt so
the agent’s statement names your action names, not just paths.
Failure. Upstream timeout is 30 s; an unreachable upstream answers the
agent 502. Today the quota unit for that attempt is still consumed —
metering happens before the proxy call, and refund-on-failure is on the
roadmap rather than in the code. Keep your upstream healthy; a flapping
origin spends your agents’ batches on 502s.
How agents pay you
Agents using the AiFinPay SDK (Node, Python) or the MCP server handle the whole flow automatically — oneagent.pay(url) call resolves the 402, pays on-chain from the agent’s own
wallet and retries. The MCP server pays only once your domain is verified
(see Set it up). To be discovered by agents you don’t already know, list
your service on the Marketplace (dashboard → Marketplace → publish; a
short review keeps spam out of the public catalog).
Gateway vs. self-hosted verification
Both settle the same way: on-chain, straight to your wallet.