One-shot agent payments for Python APIs: x402 + MPP dual-rail, discovery docs, local revenue ledger, Aegis trust — wrap a FastAPI app in five lines.
Project description
aegis-router
One-shot agent payments for Python APIs. Wrap a FastAPI app in five lines so AI agents can discover it, trust it, and pay for it — x402 (USDC on Base) and MPP (Machine Payments Protocol, Tempo) from the same route, with spec-current discovery docs, a local revenue ledger, and the Aegis trust layer built in.
from fastapi import FastAPI
from aegis_router import PaidAPI
app = FastAPI()
api = PaidAPI(app, pay_to="0xYourAddress", realm="api.example.com")
@api.paid("$0.01", example={"result": "…"})
@app.get("/paid/search")
async def search(q: str):
return {"result": do_search(q)}
api.install()
That route now:
- answers 402 Payment Required with BOTH an x402
payment-requiredchallenge and an MPPWWW-Authenticate: Paymentchallenge — buyers pay with whichever rail their client speaks; - verifies x402 payments via your facilitator and MPP payments directly against Tempo RPC (replay-protected, no facilitator needed);
- appears in
/openapi.jsonwithx-payment-info, in a generated/llms.txt, and in/.well-known/x402— all derived from the same registry that charges, so advertised price and wire price can never drift; - logs every call and every settlement (rail, payer, tx reference) to a local SQLite ledger — you know you're being paid, and by whom, from minute one;
- returns the reason in the 402 body when a payment fails, instead of silently not getting paid.
Install
pip install aegis-router # + aegis-buy client: pip install 'aegis-router[aegis]'
Python ≥ 3.11. Payments stack: the official x402 SDK and pympp (Tempo Labs' MPP SDK).
Why this and not a TypeScript router
- Python-native. FastAPI/Starlette middleware, not a Next.js proxy in front of your API.
- Dual-rail, four networks. x402 challenges on Base by default (bring your own facilitator for Solana/Polygon/Arbitrum accepts) plus MPP on Tempo — every payment standard you skip is a buyer who can't pay you.
- Trust, not just payments. Making an endpoint payable is table stakes; Aegis makes it provably delivering: register once and its verifiers continuously score your liveness, challenge validity, price honesty and actual paid delivery — a score buyers check before they spend.
- A ledger in the box. Other stacks tell you to watch your wallet.
- Loud failures. Buyers get told why a payment was rejected.
Trust & discovery flywheel
aegis-router check https://api.example.com # lint your live agent-payability
aegis-router submit https://api.example.com # register with the Aegis trust hub ($0.05 via x402)
aegis-router summary # local revenue by rail
Then register with the scanners: x402scan and mppscan.
Configuration
| Argument | Default | Notes |
|---|---|---|
pay_to |
— | EVM address receiving USDC (x402, Base) |
realm |
— | Your public host, e.g. api.example.com |
mpp_recipient |
pay_to |
Tempo address receiving Tempo USDC |
mpp_secret_key |
MPP_SECRET_KEY env |
HMAC secret binding challenge ids; set it in production |
facilitator |
https://facilitator.xpay.sh |
Any x402 facilitator |
network |
eip155:8453 |
x402 settlement network |
ledger_path / replay_path |
./aegis-router-*.db |
SQLite files |
enable_mpp / enable_x402 |
True |
Run single-rail if you must |
Per-route: api.price(path, price, method=, description=, example=, input_example=, input_schema=, mpp=) or the @api.paid(...) decorator.
Agent-assisted setup
Point your coding agent at https://aegis.borisinc.com/merchants.md and tell it:
Read https://aegis.borisinc.com/merchants.md and follow the guide to make my API discoverable and payable by agents. Only ask me questions if you need input you can't determine yourself.
License
MIT. Built and operated in production by Boris Inc — every borisinc.com service runs this exact stack on mainnet.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aegis_router-0.1.0.tar.gz.
File metadata
- Download URL: aegis_router-0.1.0.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4705431dc581aa48db937fe3b6fed9b2417f8b5192353e12ac23212e3800cd8
|
|
| MD5 |
154d8b6818f87afbefb75fad842f2899
|
|
| BLAKE2b-256 |
68522441c02340e1bfc427bed1cbfcd8b24babcef8879fcfbc22f70169b93355
|
File details
Details for the file aegis_router-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aegis_router-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73cf06d4518bf16d560ef022007f76a30c5790145a9716fe36936feb1e1b2fec
|
|
| MD5 |
a45132b2185efd0617ce6f9205a72ba9
|
|
| BLAKE2b-256 |
c81fa8cfac41a005c40b4cb7b9d0a9137266b19bf7b859ae8e54cda9cec10673
|