Skip to main content

Inter-Agent Transfer Protocol (IATP) - Enable AI Agents to utilize other AI Agents as tools

Project description

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

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

traia_iatp-0.1.105.tar.gz (264.6 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.105-py3-none-any.whl (317.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for traia_iatp-0.1.105.tar.gz
Algorithm Hash digest
SHA256 2c311822fe4efd6043a2758e12d54b45297122c176ce6dcf09137cb089b90be9
MD5 4cad062b4d7f52f8756a4b0b6ed2c8bd
BLAKE2b-256 4ccf2cc410c6a4c33d85aa48918a902f1be1ef96f9c1fbdabdb00ed17f93235c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for traia_iatp-0.1.105-py3-none-any.whl
Algorithm Hash digest
SHA256 c7d05373f3518e642926e40a137a8ed2b61c3a849e2f7d30bd77ea6edd17372c
MD5 b7236643d16917c3a92749e10b7abd1c
BLAKE2b-256 9e23658b877f76f5468326a32e3c505d2164434195980f1021d5b544ab838417

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