FastAPI middleware for Machine Payments Protocol (MPP). Add 402 Payment Required challenges, secure sessions, and receipt validation to your APIs for AI agents.
fastapi-mpp is an early-stage Python project in the AI payments / x402 ecosystem, focused on agent-economy, ai-agents, autonomous-agents, fastapi. It currently has 3 GitHub stars and 1 forks, and sits alongside related tools like crewai-x402, langchain-x402, awesome-mpp, MPP-Inspector, Intentmesh-agent2agent, agent-apprenticeship.
Machine Payments Protocol middleware for FastAPI.
Version v0.3 hardens receipt validation, replay protection, session binding, and
adds pluggable storage backends with Redis support for production deployments.
This project is still beta.
pip install fastapi-mpp
For production validation, install Tempo support so default cryptographic validation is available:
pip install "fastapi-mpp[tempo]"
Optional extras:
pip install "fastapi-mpp[dotenv]"
pip install "fastapi-mpp[redis]"
pip install "fastapi-mpp[stripe]"
pip install "fastapi-mpp[all]"
RedisStore is designed for Redis 6.2+ where GETDEL is available for atomic
one-time challenge consumption.6.2+ is strongly recommended for production compatibility and operations.import os
from fastapi import FastAPI, Request
from mpp_fastapi.core import MPP
from mpp_fastapi.stores import RedisStore
app = FastAPI()
# Production mode (default): requires receipt_validator or fastapi-mpp[tempo].
mpp = MPP(
store=RedisStore(
redis_url=os.getenv("MPP_REDIS_URL", "redis://localhost:6379/0"),
)
)
@app.get("/premium")
@mpp.charge(amount="0.05", currency="USD", description="Premium data")
async def premium(request: Request):
return {"data": "paid content"}
402 Payment Required with:WWW-Authenticate: Payment challenge="<base64url(JSON)>", realm="MyAPI", expires="..."challenge_id, intent, amount, currency, expires_at, hintsAuthorization: Payment credential="<base64url(receipt-json)>"Payment-Receipt: <base64url(receipt-json)>Legacy compatibility can be kept with allow_legacy_headers=True:
X-MPP-ReceiptX-MPP-Session-Idfrom fastapi import FastAPI, Request
from mpp_fastapi.core import MPP
from mpp_fastapi.types import MPPChargeOptions
app = FastAPI()
mpp = MPP()
session_options = MPPChargeOptions(
amount="0.01",
currency="USD",
description="Session-metered call",
session=True,
max_amount="0.50",
require_idempotency_key=True,
)
@app.post("/agent/infer")
@mpp.charge(options=session_options)
async def infer(request: Request):
return {"result": "paid inference"}
Sessions are HMAC-signed opaque tokens bound to:
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"
uvicorn examples.simple_app:app --reload
Then test:
curl -i http://127.0.0.1:8000/free
curl -i http://127.0.0.1:8000/premium
Expected behavior demo:
GET /free -> 200 OK
GET /premium (without Authorization) -> 402 Payment Required
GET /premium (with Authorization: Payment credential="...") -> 200 OK
Read SECURITY.md before production usage.
Incoming:
Authorization: Payment credential="..." (preferred)Payment-Receipt (supported)Payment-Session (session spends)X-MPP-Receipt and X-MPP-Session-Id in legacy modeIdempotency-Key for safer retriesResponse on 402:
WWW-Authenticate: Payment challenge="...", realm="...", expires="..."Response on success:
Payment-ReceiptPayment-Session when session authorization is establishedBaseStore; default InMemoryStore is single-process only.RedisStore is available for multi-worker production deployments.8KB) for authorization and receipt headers.10 challenges/IP/minute).uv pip install -e ".[dev]"
pytest
ruff check .
mypy src
Inspired by the MPP ecosystem work and early protocol specs from Tempo and Stripe collaborators. Please refer to official protocol repos/specs for normative behavior and updates.
MIT
CrewAI integration for x402 payments - autonomous agent crews that pay for APIs with USDC
LangChain integration for x402 payments - let AI agents pay for APIs with USDC automatically
The MPP registry — 100+ Machine Payments Protocol tools, SDKs, services, and payment methods across 15+ chains. The definitive directory for Stripe + Tempo agent payments.
A CLI tool and web dashboard for inspecting, testing, and debugging Machine Payments Protocol flows. Think "Postman for HTTP 402" — it visualizes the full challenge-response-receipt cycle, simulates payment failures, validates receipt signatures, benchmarks session channels, and generates test reports.
IntentMesh is an open protocol and reference architecture for structured negotiation between autonomous software agents.
The living ecosystem where AI agents complete tasks through workflow loops, improve through iterative execution, are evaluated by mentor agents or humans in the loop, and turn completed work into reusable work experience and data to improve future agents.
The living ecosystem where AI agents complete tasks through workflow loops, improve through iterative execution, are evaluated by mentor agents or humans in the loop, and turn completed work into reusable work experience and data to improve future agents.
The AI agent with a wallet — spends USDC autonomously to get real work done. Apache-2.0, TypeScript.
The first agentic payment network: policy-controlled, gasless, and real money-ready. OmniClaw CLI + Financial Policy Engine let autonomous agents pay and earn safely at machine speed.
Multi-Agent AI Task Orchestrator 2026
Autonomous AI BD Agent for SolCex Exchange: 24/7 Cross-Chain Token Scoring & Payments 2026
HELP WANTED: AI AGENTS. Real bounties, real money, every payout sealed to a public ledger. The notice board for gofrantic.com