Skip to main content

aifinpay-agent (Python)

Non-custodial multi-facilitator x402 payment client for autonomous AI agents on AiFinPay — canonical domain aifinpay.io (the legacy aifinpay.company host is retired). SDK settlement: Polygon (default) + Solana; the protocol is live across 13 networks — see aifinpay.io/llms.txt.

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

# install (latest)
pip install aifinpay-agent

# 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.io/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):

  1. Sends the request unauthenticated.
  2. On 402, inspects the response and picks a facilitator adapter:
    • AiFinPayprotocol: "AiFinPay vX" field in JSON body, or agreement_hash + treasury_vault fingerprint
    • Coinbase x402PAYMENT-REQUIRED HTTP header
  3. Builds the right auth payload:
    • AiFinPay → reads x-nonce from the 402 body (no extra round-trip), computes SHA-256("AiFinPay-x402:{nonce}:{pubkey}"), signs with Ed25519, sets x-agent-pubkey, x-nonce, x-signature headers
    • Coinbase x402 → builds a PaymentPayload, base64-encodes, sets PAYMENT-SIGNATURE (settlement coming in 0.3)
  4. 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.

Download files

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

Source Distribution

aifinpay_agent-1.4.2.tar.gz (41.1 kB view details)

Uploaded Source

Built Distribution

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

aifinpay_agent-1.4.2-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

Details for the file aifinpay_agent-1.4.2.tar.gz.

File metadata

  • Download URL: aifinpay_agent-1.4.2.tar.gz
  • Upload date:
  • Size: 41.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.7

File hashes

Hashes for aifinpay_agent-1.4.2.tar.gz
Algorithm Hash digest
SHA256 aa9491bd6e83f93a5db058e9fec632de99008db906459a0fec80ab1b9d869681
MD5 25a0f62687e6720931b194ef74e17a2f
BLAKE2b-256 383d6b1196ce5223c27701b62e8f9a3118392b6687ddf70688a2a0a7b7b534da

See more details on using hashes here.

File details

Details for the file aifinpay_agent-1.4.2-py3-none-any.whl.

File metadata

  • Download URL: aifinpay_agent-1.4.2-py3-none-any.whl
  • Upload date:
  • Size: 33.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.7

File hashes

Hashes for aifinpay_agent-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6b79adf40d513a0fc87b41aa3ac86f7a5d16a321a88c2d37b32ac70c5fa968f7
MD5 0c86f0d31a3fc4e54c6e813accc8b7c5
BLAKE2b-256 cfb37da7b9a120ca50aca1108ae9183bd71d6c8023663371ca6d24c704bd29cf

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.4.2 This release

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

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