Non-custodial multi-facilitator x402 client for autonomous AI agents (AiFinPay native + Coinbase x402 detection)
Project description
aifinpay-agent (Python)
Non-custodial multi-facilitator x402 payment client for autonomous AI agents.
agent.pay(url) works against:
- AiFinPay native flow (Solana Seat PDA + Ed25519)
- Coinbase x402 spec — detection + parsing today; on-chain settlement coming in 0.3.x
The Ed25519 keypair is generated locally and never leaves your process.
The SDK auto-detects the facilitator flavor on a 402 response and builds
the right auth payload (three-headers for AiFinPay, base64
PAYMENT-SIGNATURE for Coinbase x402).
Install
# alpha / prerelease (current)
pip install aifinpay-agent --pre
# stable (when 1.0 ships)
pip install aifinpay-agent
Quick start
from aifinpay import Agent, PayOptions
# Generate a fresh keypair locally — never transmitted
agent = Agent.new()
print("Fund this address:", agent.address)
print("Save this secret:", agent.secret_b58) # store securely!
# Wait until the wallet has at least $0.01 worth on-chain
agent.wait_for_funding(min_usd_cents=1)
# Request an invoice for a Seat (USDC on Solana)
invoice = agent.reserve_seat_invoice(amount_usd=1.00, asset="USDC")
print("Invoice:", invoice.raw)
# Build + sign + submit the Solana transaction with @solana/web3.js, anchorpy,
# or solana-py — the invoice contains program_id, treasury_vault, mints, etc.
# Generic x402 — auto-detects facilitator, signs, retries
resp = agent.pay("https://aifinpay.company/api/stats")
print(resp.json())
# Pay any third-party x402 endpoint (e.g. Coinbase x402-protected API)
resp = agent.pay(
"https://api.example.com/v1/data",
method="POST",
json={"q": "hello"},
options=PayOptions(max_amount_usd=0.10), # refuse if cost > $0.10
)
Loading an existing keypair
# from solana-keygen JSON file
agent = Agent.from_keypair_file("~/agent-wallet.json")
# from base58 secret string
agent = Agent.from_secret_b58("3RvZm7Gw...")
How x402 auth works under the hood
agent.pay(url):
- Sends the request unauthenticated.
- On
402, inspects the response and picks a facilitator adapter:- AiFinPay —
protocol: "AiFinPay vX"field in JSON body, oragreement_hash+treasury_vaultfingerprint - Coinbase x402 —
PAYMENT-REQUIREDHTTP header
- AiFinPay —
- Builds the right auth payload:
- AiFinPay → reads
x-noncefrom the 402 body (no extra round-trip), computesSHA-256("AiFinPay-x402:{nonce}:{pubkey}"), signs with Ed25519, setsx-agent-pubkey,x-nonce,x-signatureheaders - Coinbase x402 → builds a
PaymentPayload, base64-encodes, setsPAYMENT-SIGNATURE(settlement coming in 0.3)
- AiFinPay → reads
- Retries the original request with the auth attached.
The server verifies the signature, checks the agent's on-chain payment proof (Seat PDA for AiFinPay, settled tx for Coinbase x402), and serves the resource.
Privacy
- The server never sees your private key. Period.
- Nonces are consumed on use; replay-resistant.
- All transactions are public and on-chain — Solana + Polygon mainnet.
License
MIT.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aifinpay_agent-0.2.0a2.tar.gz.
File metadata
- Download URL: aifinpay_agent-0.2.0a2.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44e86760475f625d163a5fc1afcbb6c80ea6a878ba43cfee87b285c121d20b8e
|
|
| MD5 |
d2e37b421439182a45c910b7e5191106
|
|
| BLAKE2b-256 |
ecbc7de79707a086a3763e510c74196e7ce1f6a929954fb8df6ccac71da3f12e
|
File details
Details for the file aifinpay_agent-0.2.0a2-py3-none-any.whl.
File metadata
- Download URL: aifinpay_agent-0.2.0a2-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a7dc7bf502843cc55c6a3351253eff72a37e9b785e93245f1cf0633102e79a7
|
|
| MD5 |
3637e40484dedf331347713d657d7dcc
|
|
| BLAKE2b-256 |
d885f0adc93224769b1c998500a3440ef29a055ebdf5062c373bb3decadd0dc5
|