Skip to main content

x402-style HTTP 402 paywall for INR payments via Amrood

Project description

amrood-paywall

x402-style HTTP 402 paywall for INR payments via Amrood.

Add pay-per-call pricing to any FastAPI endpoint in one line. AI agents with Amrood wallets pay automatically.

Quick Start

pip install amrood-paywall
from fastapi import FastAPI, Request
from amrood_paywall import amrood_pay

app = FastAPI()

@app.get("/api/data")
@amrood_pay(amount="5.00", pay_to="databot")
async def get_data(request: Request):
    return {"data": "premium content"}

Set your agent's API key so the server can verify incoming payments:

export AMROOD_AGENT_KEY=agk_live_xxx

How It Works

1. Client:  GET /api/data
2. Server:  402 Payment Required + X-AMROOD-PAY header
3. Client:  Pays ₹5.00 to @databot via Amrood API
4. Client:  GET /api/data + X-AMROOD-PAYMENT header (with transaction proof)
5. Server:  Verifies payment via Amrood's /v1/transactions/{id}/verify
6. Server:  200 OK + data

Payments between Amrood agents are instant and settled in INR. No crypto, no blockchain, no gas fees.

Protocol Headers

X-AMROOD-PAY (server → client)

Returned with HTTP 402 responses. Base64-encoded JSON:

{
  "version": 1,
  "payTo": "databot",
  "amount": "5.00",
  "asset": "INR",
  "resource": "/api/data",
  "description": "Payment for /api/data",
  "nonce": "n_abc123",
  "expiresAt": "2026-03-07T09:00:00Z"
}

X-AMROOD-PAYMENT (client → server)

Sent by the client after making the payment. Base64-encoded JSON:

{
  "version": 1,
  "transactionId": "txn_xyz789",
  "fromAgent": "researchbot",
  "nonce": "n_abc123"
}

Decorator Reference

@amrood_pay(
    amount="5.00",           # Price in INR (required)
    pay_to="databot",        # Amrood agent handle or ID (required)
    description="Premium data access",  # Human-readable (optional)
    agent_key="agk_live_...",  # Override AMROOD_AGENT_KEY env var (optional)
    base_url="https://amrood.io",  # Override AMROOD_BASE_URL (optional)
    expiry_seconds=600,      # Payment instruction validity (default 10 min)
)

Environment Variables

Variable Required Description
AMROOD_AGENT_KEY Yes Your agent's API key (the payee agent)
AMROOD_BASE_URL No Amrood API URL (default: https://amrood.io)

Client-Side (for AI agents)

If you're building an AI agent that needs to pay for APIs, use amrood-mcp which includes the amrood_http_pay tool. It handles the full 402 flow automatically:

"Fetch https://api.example.com/premium"
  → Agent detects 402, pays ₹5 to @databot, retries with proof
  → Returns the premium data

Replay Protection

Each 402 response includes a unique nonce. The server tracks used nonces in-memory with a 10-minute TTL. A payment proof with a reused nonce is rejected with HTTP 409.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

amrood_paywall-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

amrood_paywall-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file amrood_paywall-0.1.0.tar.gz.

File metadata

  • Download URL: amrood_paywall-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for amrood_paywall-0.1.0.tar.gz
Algorithm Hash digest
SHA256 16e40e4796bca2c378952eb98ff9672677abfe137c68baf3684476947b80426f
MD5 3a180875b58c2d60a4f3fc32520a70b2
BLAKE2b-256 cd406dcda4d9173561cf927535aae4d153c065d416fdb5eaeab458d07bcef54d

See more details on using hashes here.

File details

Details for the file amrood_paywall-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: amrood_paywall-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for amrood_paywall-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 efa1015b22f6f042666303a0be21bd2df822e77bf5d5d453efcd68e879b5b28e
MD5 f23124919ed14bd5d55d429932449c43
BLAKE2b-256 fb5e01d4d78478f7304a17caabe27fd1cfa138d1b2a63a1b9f7bbf51a01d715c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page