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

Metadata

Release files for traia-iatp 0.1.112

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for traia-iatp 0.1.112
File Size Uploaded
traia_iatp-0.1.112.tar.gz 273.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for traia-iatp 0.1.112
File Interpreter ABI Platform
traia_iatp-0.1.112-py3-none-any.whl Python 3 none any Details

Total release size: 600.3 kB

Release files / traia_iatp-0.1.112.tar.gz

Download URL traia_iatp-0.1.112.tar.gz
Size 273.7 kB
Tags Source
SHA-256 checksum
How to use checksums
55b6e269070742e52ae38f877f323735376e212750067f2e9f387968b35588f1
BLAKE2b-256 checksum
How to use checksums
953d872afd1ab20379b4982590e012aab122481f72ba3a5acf89a0527d6fb59f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Release files / traia_iatp-0.1.112-py3-none-any.whl

Download URL traia_iatp-0.1.112-py3-none-any.whl
Size 326.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd2318f787dc6e6b56b4acccf3e3f5420ce9d8cb05f6c995b2fda3e0b207941f
BLAKE2b-256 checksum
How to use checksums
417ffa46e3c1beac46d0a938fcbf0e1a0b686bafd34150797fd0919cf331efbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Release history Release notifications | RSS feed

This release

0.1.112 This release

2 release files

0.1.99

2 release files

0.1.98

2 release files

0.1.97

2 release files

0.1.96

2 release files

0.1.95

2 release files

0.1.94

2 release files

0.1.93

2 release files

0.1.92

2 release files

0.1.91

2 release files

0.1.90

2 release files

0.1.89

2 release files

0.1.88

2 release files

0.1.86

2 release files

0.1.85

2 release files

0.1.84

2 release files

0.1.83

2 release files

0.1.82

2 release files

0.1.81

2 release files

0.1.80

2 release files

0.1.79

2 release files

0.1.78

2 release files

0.1.77

2 release files

0.1.73

2 release files

0.1.72

2 release files

0.1.71

2 release files

0.1.70

2 release files

0.1.69

2 release files

0.1.68

2 release files

0.1.67

2 release files

0.1.66

2 release files

0.1.65

2 release files

0.1.64

2 release files

0.1.63

2 release files

0.1.62

2 release files

0.1.61

2 release files

0.1.60

2 release files

0.1.59

2 release files

0.1.58

2 release files

0.1.57

2 release files

0.1.56

2 release files

0.1.55

2 release files

0.1.54

2 release files

0.1.53

2 release files

0.1.52

2 release files

0.1.50

2 release files

0.1.49

2 release files

0.1.48

2 release files

0.1.47

2 release files

0.1.46

2 release files

0.1.35

2 release files

0.1.34

2 release files

0.1.33

2 release files

0.1.32

2 release files

0.1.31

2 release files

0.1.30

2 release files

0.1.29

2 release files

0.1.28

2 release files

0.1.23

2 release files

0.1.21

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page