Skip to main content

Python SDK for Xenarch — x402 payment middleware for AI agents and publishers. FastAPI-native HTTP 402 pay-per-request with USDC micropayments on Base L2. Non-custodial, 0% fee. A pay-per-crawl alternative to Cloudflare.

Project description

xenarch — x402 MCP server & Python SDK for AI agent payments

Xenarch is a non-custodial x402 MCP server and Python SDK that lets AI agents pay for HTTP 402–gated APIs and content with USDC micropayments on Base L2. Works with LangChain, CrewAI, FastAPI, and any MCP client (Claude, Cursor, Cline). Payments settle on-chain via an immutable splitter contract — 0% fee today, hard-capped at 0.99% forever.

What makes Xenarch different

Cloudflare Pay-Per-Crawl TollBit Stripe/PayPal micropayments Xenarch
Works on any host ❌ (Cloudflare only) ❌ (enterprise) ✅ (with integration)
Non-custodial ✅ (on-chain splitter)
No API keys / no signup
Fee platform rate platform rate 2.9% + $0.30 min 0% today, 0.99% hard-capped
Open standard proprietary proprietary proprietary x402 + pay.json

Install

# For LangChain agents paying x402-gated APIs
pip install xenarch[langchain,x402]

# For publishers (FastAPI middleware)
pip install xenarch[fastapi]

Agent: pay for x402-gated content

from decimal import Decimal

from xenarch.tools import XenarchPay, XenarchBudgetPolicy

tool = XenarchPay(
    private_key="0x...",
    budget_policy=XenarchBudgetPolicy(
        max_per_call=Decimal("0.05"),
        max_per_session=Decimal("1.00"),
    ),
)

# Use directly, or register with any LangChain agent.
print(tool.invoke("https://example.com/premium-article"))

XenarchPay is a LangChain BaseTool over the neutral x402-agent pay loop, plus Xenarch's signed-receipt and reputation extras. Settles USDC on Base via EIP-3009 — never custodial.

FastAPI micropayments — publisher middleware

Xenarch exposes HTTP 402 micropayments through a one-decorator FastAPI middleware. Any route can charge a USDC micropayment per request, with the agent paying directly on-chain and no account required.

from fastapi import FastAPI
from xenarch import XenarchMiddleware

app = FastAPI()
app.add_middleware(
    XenarchMiddleware,
    site_token="your-site-token",
    protected_paths=["/premium/*"],
)

Or use the decorator:

from xenarch import require_payment

@app.get("/premium/article")
@require_payment(price_usd="0.05")
async def premium_article():
    return {"content": "This is premium content"}

The decorator returns HTTP 402 with the price when called without payment, verifies the on-chain USDC transfer, and grants access with a time-limited Bearer token.

API monetization for Python developers

Xenarch is an API monetization primitive for Python APIs. Unlike API gateway monetization platforms (Apigee, Kong, AWS API Gateway) that require subscriptions, dashboards, and API keys, Xenarch charges per request via the HTTP 402 spec — no account creation, no key provisioning, no custodial balance.

For Python publishers this means:

  • One decorator on any FastAPI endpoint
  • USDC settlement on-chain in real time
  • Per-request pricing that treats human users, bots, and AI agents identically
  • No integration with Stripe, PayPal, or card processors
  • An API monetization model that works for the long tail of APIs, not just enterprise

How it works

Xenarch is a non-custodial payment network. When an AI agent hits an x402-gated URL:

  1. The server returns HTTP 402 Payment Required with payment instructions (price, wallet, contract)
  2. The agent pays USDC through a smart contract on Base (max $1 per payment)
  3. The agent verifies the payment and receives a time-limited access token
  4. The agent re-requests the content with the access token

No signup. No API keys. No custodial balances. Every payment is an on-chain USDC transfer the agent can verify.

FAQ

How does Claude pay for APIs from Python? Claude (or any MCP agent) uses the Xenarch MCP server directly. For Python code that isn't an MCP agent, use xenarch[langchain,x402]XenarchPay is a LangChain BaseTool that pays any x402-gated URL.

Does Xenarch work with LangChain or CrewAI? LangChain works today via from xenarch.tools import XenarchPay. CrewAI, AutoGen, and LangGraph adapters are on the roadmap (XEN-172/173/174).

Is Xenarch a Stripe alternative for APIs? For per-request API monetization, yes. Stripe requires account creation, API keys, and charges 2.9% + $0.30 per transaction. Xenarch charges 0% today (0.99% hard-capped on-chain) and requires no account — the caller just pays USDC on Base.

Is Xenarch custodial? No. Payments settle on-chain via an immutable splitter contract. Funds never touch Xenarch infrastructure.

What is x402? x402 is an open protocol for HTTP 402 Payment Required. A server returns 402 with a price, the client signs a USDC micropayment on Base L2, and retries the request with proof of payment.

What is HTTP 402? HTTP 402 Payment Required is a status code reserved in the HTTP spec since 1997 for machine-to-machine payment. x402 is the open protocol that finally uses it.

What's the max payment per call? $1 USD.

Links

License

MIT

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

xenarch-0.2.1.tar.gz (54.5 kB view details)

Uploaded Source

Built Distribution

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

xenarch-0.2.1-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file xenarch-0.2.1.tar.gz.

File metadata

  • Download URL: xenarch-0.2.1.tar.gz
  • Upload date:
  • Size: 54.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for xenarch-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b878d5c86bacccd8d5eddf25a3aef146c195ed3fcf0a2310cb9abb0b7e74df21
MD5 60ad90c5699d4791539531c953b806dc
BLAKE2b-256 c63a22f1b5015a31a9f5ea1e078e0d746719227687dbddd4c85443781a9768be

See more details on using hashes here.

File details

Details for the file xenarch-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: xenarch-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for xenarch-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a5738794f9054b1c2d56cc19eaf92685fce0c8e31d8cdb57f34916baeaa591b
MD5 898ade178737b5178f19d75c1eccb674
BLAKE2b-256 af14728fc7184b034bfc0cc9528533fe1af0f82a5de090143e3b28ee8e6a91cc

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