Skip to main content

IATP-D402: Inter-Agent Transfer Protocol with Payment Support

PyPI version Python 3.12+ License: MIT Documentation

IATP-D402 enables AI agents and APIs to charge for their services using the D402 payment protocol (HTTP 402 Payment Required). Build payment-enabled:

  • ๐ŸŒ APIs and web servers
  • ๐Ÿ”ง MCP (Model Context Protocol) servers
  • ๐Ÿค– A2A utility agents
  • ๐Ÿค CrewAI tools and agents

๐Ÿš€ Quick Start

Installation

pip install traia-iatp

Add D402 to Your FastAPI Server (5 lines)

from fastapi import FastAPI
from traia_iatp.d402.servers.fastapi import D402FastAPIMiddleware
from traia_iatp.d402.price_builder import D402PriceBuilder

app = FastAPI()

# Add D402 (5 lines)
price_builder = D402PriceBuilder(network="sepolia")
d402 = D402FastAPIMiddleware(server_address="0x...", facilitator_url="https://test-facilitator.d402.net")
price = price_builder.create_price(0.01)  # $0.01 USD
d402.register_endpoint("/api/analyze", price_wei=price.amount, token_address=price.asset.address, network="sepolia", description="Analysis")
d402.add_to_app(app)

# Your endpoint (unchanged!)
@app.post("/api/analyze")
async def analyze(request: Request):
    return {"result": "done"}

Call D402-Protected Servers (2 lines)

from traia_iatp.d402.clients.httpx import d402HttpxClient
from eth_account import Account

async with d402HttpxClient(
    operator_account=Account.from_key("0x..."),
    wallet_address="0x...",
    max_value=100000,
    base_url="http://localhost:8000"
) as client:
    # Payment automatic!
    response = await client.post("/api/analyze", json={"text": "test"})

๐Ÿ“š Documentation

Full documentation: docs.d402.net

Quick Links

Complete Integration Examples

The examples section provides complete, working code for:

  1. Wallet Creation & Funding - Setup wallets, get testnet USDC
  2. Existing Server โ†’ D402 - Add payments to your API (before/after)
  3. Calling D402 Servers - Build payment-enabled client
  4. API โ†’ MCP Server - Convert REST to MCP tools
  5. CrewAI + MCP - Use MCP server in crews
  6. MCP โ†’ Utility Agent - Wrap MCP as A2A agent
  7. CrewAI + Utility Agent - Use agents in crews

๐ŸŒŸ Key Features

D402 Payment Protocol

  • โœ… HTTP 402 Payment Required - Standard payment protocol
  • โœ… EIP-712 Signatures - Secure payment authorization
  • โœ… On-Chain Settlement - Smart contract-based settlements
  • โœ… Hosted Facilitators - No infrastructure setup required

Server Integration

  • โœ… FastAPI - D402FastAPIMiddleware
  • โœ… Starlette - D402PaymentMiddleware
  • โœ… Any ASGI Framework - D402ASGIWrapper (Flask, Django, Quart, etc.)
  • โœ… 5-line integration - Minimal code changes

Client Integration

  • โœ… HTTPX (Async) - d402HttpxClient with automatic payment
  • โœ… Requests (Sync) - Wrapper for synchronous apps
  • โœ… 2-line integration - Just make requests normally

MCP & A2A

  • โœ… MCP Servers - Payment-enabled tool servers
  • โœ… Utility Agents - A2A protocol with D402
  • โœ… CrewAI Integration - A2AToolkit for paid tools
  • โœ… Template Generation - Auto-generate server code

๐Ÿ”ง What's in the Package

Core Components (IN pip package)

src/traia_iatp/
โ”œโ”€โ”€ d402/                     # D402 payment protocol
โ”‚   โ”œโ”€โ”€ servers/             # Server middleware (FastAPI, Starlette, MCP)
โ”‚   โ”œโ”€โ”€ clients/             # Client libraries (HTTPX, base client)
โ”‚   โ”œโ”€โ”€ asgi_wrapper.py      # Universal ASGI wrapper
โ”‚   โ”œโ”€โ”€ price_builder.py     # USD-based pricing
โ”‚   โ””โ”€โ”€ facilitator.py       # Facilitator client
โ”‚
โ”œโ”€โ”€ mcp/                      # MCP server templates & tools
โ”œโ”€โ”€ server/                   # Utility agent templates
โ”œโ”€โ”€ client/                   # A2A client & CrewAI tools
โ”œโ”€โ”€ contracts/                # Smart contract integration
โ””โ”€โ”€ registry/                 # Agent discovery & search

Examples (NOT in pip package)

examples/                     # Integration examples
โ”œโ”€โ”€ servers/                 # FastAPI, Starlette, ASGI examples
โ””โ”€โ”€ clients/                 # HTTPX, Requests examples

Documentation (NOT in pip package)

docs/                         # GitBook documentation
โ”œโ”€โ”€ getting-started/         # Installation, quick start
โ”œโ”€โ”€ examples/                # Complete integration examples (0-6)
โ”œโ”€โ”€ wallet-setup/            # Wallet creation & CLI
โ”œโ”€โ”€ d402-servers/            # Server integration guides
โ”œโ”€โ”€ d402-clients/            # Client integration guides
โ”œโ”€โ”€ mcp-servers/             # MCP server guides
โ”œโ”€โ”€ utility-agents/          # Utility agent guides
โ””โ”€โ”€ crewai-integration/      # CrewAI guides

๐Ÿ— Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Your Application                         โ”‚
โ”‚      (API / MCP Server / Utility Agent / CrewAI Crew)      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚
                           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  IATP-D402 Framework                        โ”‚
โ”‚  โ€ข Server Middleware  โ€ข Client Libraries  โ€ข Templates      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚
                           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  D402 Payment Protocol                      โ”‚
โ”‚  โ€ข HTTP 402  โ€ข EIP-712 Signing  โ€ข Facilitator Service      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚
                           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               Smart Contracts (On-Chain)                    โ”‚
โ”‚         โ€ข IATPWallet  โ€ข Settlement  โ€ข Tokens                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŒ Facilitators (No Setup Required)

You don't need to run your own facilitator!

  • All Testnets: https://test-facilitator.d402.net (currently: Sepolia)
  • All Mainnets: https://facilitator.d402.net (currently: Arbitrum)

See Facilitator URLs for details.

๐Ÿ” Wallet Creation

# Create IATP wallet (owner creates their own wallet)
traia-iatp create-iatp-wallet \
  --owner-key 0x... \
  --create-operator \
  --wallet-name "My Server" \
  --wallet-type MCP_SERVER \
  --network sepolia

See Creating Wallets for complete guide.

๐Ÿ“ฆ Use Cases

1. Monetize Your API

# Add payment to any endpoint
d402.register_endpoint("/api/analyze", price_usd=0.01)

2. Build Payment-Enabled MCP Servers

@mcp.tool()
@require_payment_for_tool(price=price_builder.create_price(0.01))
def analyze(text: str) -> dict:
    return analyze_sentiment(text)

3. Use Paid Tools in CrewAI

toolkit = A2AToolkit.create_from_endpoint(
    endpoint="http://localhost:9001",
    payment_private_key="0x...",
    wallet_address="0x...",
    max_payment_usd=1.0
)

agent = Agent(role="Analyst", tools=toolkit.tools)

๐Ÿ›  CLI Commands

# Create IATP wallet
traia-iatp create-iatp-wallet --owner-key 0x... --create-operator

# Create utility agency from MCP server
traia-iatp create-agency --name "My Agent" --mcp-name "Trading MCP"

# List available agencies
traia-iatp list-agencies

# Search for tools
traia-iatp find-tools --query "sentiment analysis"

๐Ÿ”— Links

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿค Support


Made with โค๏ธ by the Traia Team

Download files

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

Source Distribution

traia_iatp-0.1.112.tar.gz (273.7 kB view details)

Uploaded Source

Built Distribution

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

traia_iatp-0.1.112-py3-none-any.whl (326.6 kB view details)

Uploaded Python 3

File details

Details for the file traia_iatp-0.1.112.tar.gz.

File metadata

  • Download URL: traia_iatp-0.1.112.tar.gz
  • Upload date:
  • Size: 273.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for traia_iatp-0.1.112.tar.gz
Algorithm Hash digest
SHA256 55b6e269070742e52ae38f877f323735376e212750067f2e9f387968b35588f1
MD5 56eaecc1912171f0fce715360de02eef
BLAKE2b-256 953d872afd1ab20379b4982590e012aab122481f72ba3a5acf89a0527d6fb59f

See more details on using hashes here.

File details

Details for the file traia_iatp-0.1.112-py3-none-any.whl.

File metadata

File hashes

Hashes for traia_iatp-0.1.112-py3-none-any.whl
Algorithm Hash digest
SHA256 fd2318f787dc6e6b56b4acccf3e3f5420ce9d8cb05f6c995b2fda3e0b207941f
MD5 f3323243be048fefd7a4cc3a9752709e
BLAKE2b-256 417ffa46e3c1beac46d0a938fcbf0e1a0b686bafd34150797fd0919cf331efbe

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.112 This release

2 files

0.1.111

2 files

0.1.110

2 files

0.1.109

2 files

0.1.108

2 files

0.1.107

2 files

0.1.106

2 files

0.1.105

2 files

0.1.104

2 files

0.1.103

2 files

0.1.102

2 files

0.1.101

2 files

0.1.100

2 files

0.1.99

2 files

0.1.98

2 files

0.1.97

2 files

0.1.96

2 files

0.1.95

2 files

0.1.94

2 files

0.1.93

2 files

0.1.92

2 files

0.1.91

2 files

0.1.90

2 files

0.1.89

2 files

0.1.88

2 files

0.1.87

2 files

0.1.86

2 files

0.1.85

2 files

0.1.84

2 files

0.1.83

2 files

0.1.82

2 files

0.1.81

2 files

0.1.80

2 files

0.1.79

2 files

0.1.78

2 files

0.1.77

2 files

0.1.76

2 files

0.1.75

2 files

0.1.74

2 files

0.1.73

2 files

0.1.72

2 files

0.1.71

2 files

0.1.70

2 files

0.1.69

2 files

0.1.68

2 files

0.1.67

2 files

0.1.66

2 files

0.1.65

2 files

0.1.64

2 files

0.1.63

2 files

0.1.62

2 files

0.1.61

2 files

0.1.60

2 files

0.1.59

2 files

0.1.58

2 files

0.1.57

2 files

0.1.56

2 files

0.1.55

2 files

0.1.54

2 files

0.1.53

2 files

0.1.52

2 files

0.1.50

2 files

0.1.49

2 files

0.1.48

2 files

0.1.47

2 files

0.1.46

2 files

0.1.45

2 files

0.1.44

2 files

0.1.43

2 files

0.1.42

2 files

0.1.41

2 files

0.1.40

2 files

0.1.39

2 files

0.1.38

2 files

0.1.37

2 files

0.1.36

2 files

0.1.35

2 files

0.1.34

2 files

0.1.33

2 files

0.1.32

2 files

0.1.31

2 files

0.1.30

2 files

0.1.29

2 files

0.1.28

2 files

0.1.27

2 files

0.1.26

2 files

0.1.25

2 files

0.1.24

2 files

0.1.23

2 files

0.1.21

2 files

0.1.17

2 files

0.1.16

2 files

0.1.15

2 files

0.1.14

2 files

0.1.13

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

Supported by

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