Swarms Logo
Agent-to-agent payments on Solana

ATP

Agent Trade Protocol

The premier payment protocol and foundational framework for the agent economy.

Automatic payment processing, response encryption, and zero-config middleware. Pay-per-use on Solana.

Scroll to explore

What is ATP?

ATP is the agent-to-agent payment protocol that makes pay-to-unlock results simple on Solana.

ATP (Agent Trade Protocol) is designed to overcome x402's limitations and make agent-to-agent payments dynamic and simple. It provides a middleware layer that automatically deducts payments from user wallets based on token usage. Responses are encrypted until payment is confirmed on-chain, so users only see output after paying. All settlements run on the Solana blockchain with full transparency, and the protocol supports multiple usage formats (OpenAI, Anthropic, Google, etc.) out of the box.

Key features

Security, automation, and decentralization built in.

High-performance settlement
Rust-built settlement infrastructure delivers low-latency, reliable payment processing and on-chain finality at scale.
Rapid integration
Deploy with minimal configuration. Integrate into existing FastAPI services without architectural changes or vendor lock-in.
API middleware
Production-ready middleware layer for FastAPI that enforces payment-gating and automates settlement across protected endpoints.
Security & compliance
Response encryption keeps output inaccessible until on-chain payment confirmation, supporting pay-to-unlock policies and audit requirements.
Usage-based billing
Metered billing aligned to token consumption. Automatic settlement with transparent, auditable pricing for cost control and forecasting.
SOL & USDC
Settle in Solana native token or USDC with full transaction visibility and on-chain auditability for finance and compliance teams.

Get started in 3 steps

Add ATP to your FastAPI server and start accepting agent payments in minutes.

1
Install
Install the ATP protocol package
pip install atp-protocol
2
Add middleware to your server
Protect endpoints and enable automatic payments
from fastapi import FastAPI
from atp.middleware import ATPSettlementMiddleware
from atp.schemas import PaymentToken

app = FastAPI()
app.add_middleware(
    ATPSettlementMiddleware,
    allowed_endpoints=["/v1/chat", "/v1/completions"],
    input_cost_per_million_usd=10.0,
    output_cost_per_million_usd=30.0,
    recipient_pubkey="YourSolanaWalletPublicKeyHere",
    payment_token=PaymentToken.SOL,
    require_wallet=True,
)
3
Call from the client
Clients pay automatically; responses decrypt after payment
from atp.client import ATPClient

client = ATPClient(
    wallet_private_key="[1,2,3,...]",
    settlement_service_url="https://facilitator.swarms.world"
)
response = await client.post(
    url="https://api.example.com/v1/chat",
    json={"message": "Hello!"}
)
print(response["response"])  # Agent output
print(response["atp_settlement"])  # Payment details

Architecture

Three components power the protocol: Settlement, Middleware, and Client.

Settlement service
(Facilitator)
Handles settlement logic, usage parsing, payment calculation, and blockchain transaction execution.
Middleware
(FastAPI)
Intercepts responses, extracts usage, encrypts output, runs payments, and decrypts only after confirmation.
Client
(User-facing)
Simplifies requests to ATP-protected endpoints and interaction with the settlement service.

Request flow

1
Client request
2
Agent API
3
Middleware: encrypt response
4
Settlement: execute payment
5
Decrypt after confirmation

Security & payment

Pay-to-unlock and transparent splits.

Security features
• Responses are encrypted before payment verification.• Decryption only after successful on-chain confirmation (status="paid").• Failed payments return encrypted response with error details; no free access to output.
Payment structure
Treasury: processing fee (default 5%).Recipient: remainder (95%) — your wallet via recipient_pubkey.• Supported tokens: SOL and USDC on Solana.

Usage data formats

Middleware auto-detects OpenAI, Anthropic, and Google-style usage.

OpenAIAnthropicGoogle / Gemini

Build the agent economy

Add ATP to your agent API and start accepting payments on Solana in minutes.