Skip to main content

Python SDK for pay — payment infrastructure for AI agents

Project description

pay-sdk

Python SDK for pay — payment infrastructure for AI agents. USDC on Base.

Three primitives: direct payments, tabs (pre-funded metered accounts), and x402 HTTP paywalls.

Install

pip install pay-sdk

Requires Python 3.10+.

Quick Start

from payskill import PayClient

client = PayClient(signer="cli")  # uses `pay sign` subprocess

# Pay another agent $5
result = client.pay_direct("0xprovider...", 5_000_000, memo="task-42")
print(result.tx_hash)

# Open a metered tab
tab = client.open_tab("0xprovider...", 20_000_000, max_charge_per_call=500_000)

# x402 request (SDK handles payment automatically)
response = client.request("https://api.example.com/data")

All amounts are in USDC micro-units (6 decimals). $1.00 = 1_000_000.

API Reference

PayClient

from payskill import PayClient

client = PayClient(
    api_url="https://pay-skill.com/api/v1",  # default
    signer="cli",  # "cli", "raw", "custom", or a Signer instance
)

Direct Payment

One-shot USDC transfer. $1.00 minimum.

result = client.pay_direct(to, amount, memo="")
# Returns: DirectPaymentResult(tx_hash, status, amount, fee)

Tab Management

Pre-funded metered account. $5.00 minimum to open.

# Open
tab = client.open_tab(provider, amount, max_charge_per_call)

# Query
tabs = client.list_tabs()
tab = client.get_tab(tab_id)

# Top up (no extra activation fee)
tab = client.top_up_tab(tab_id, amount)

# Close (either party, unilateral)
tab = client.close_tab(tab_id)

Returns Tab(tab_id, provider, amount, balance_remaining, total_charged, charge_count, max_charge_per_call, status).

x402 Requests

Transparent HTTP 402 handling. The SDK detects 402 Payment Required, pays (via direct or tab), and retries.

response = client.request(url, method="GET", body=None, headers=None)
# Returns: httpx.Response

If the provider requires tab settlement, the SDK auto-opens a tab at 10x the per-call price (minimum $5).

Wallet

status = client.get_status()
# Returns: StatusResponse(address, balance, open_tabs)

Webhooks

wh = client.register_webhook(url, events=["tab.opened"], secret="whsec_...")
webhooks = client.list_webhooks()
client.delete_webhook(webhook_id)

Funding

link = client.create_fund_link(amount=10_000_000)   # Coinbase Onramp
link = client.create_withdraw_link(amount=5_000_000)

Signer Modes

Mode Usage When
"cli" Subprocess call to pay sign Default. Key in OS keychain.
"raw" PAYSKILL_KEY env var Dev/testing only.
"custom" Your own callback Custom key management.
# CLI signer (default)
client = PayClient(signer="cli")

# Raw key (dev only)
client = PayClient(signer="raw", key="0xdead...")

# Custom callback
from payskill.signer import CallbackSigner
signer = CallbackSigner(callback=lambda hash_bytes: my_sign(hash_bytes))
client = PayClient(signer=signer)

Error Handling

from payskill.errors import (
    PayError,                  # Base class
    PayValidationError,        # Bad input (has .field)
    PayNetworkError,           # Connection failed
    PayServerError,            # Server returned error (has .status_code)
    PayInsufficientFundsError, # Not enough USDC
)

Configuration

Env Var Purpose
PAYSKILL_KEY Private key for raw signer mode

The API URL is configurable via the api_url parameter. Default: https://pay-skill.com/api/v1.

License

MIT

Project details


Download files

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

Source Distribution

pay_skill-0.1.3.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

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

pay_skill-0.1.3-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file pay_skill-0.1.3.tar.gz.

File metadata

  • Download URL: pay_skill-0.1.3.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pay_skill-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e1af5ef8725d70e6cac7e149558d6f45ef830541ab18a9b0b91da56544a2bad2
MD5 a8416eb1201e42b7f0c942220d0ad979
BLAKE2b-256 f4cdbbc23d19ddedf5ee49d4db824dbe153f06f987e1e9df36082dc1fe3b685f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pay_skill-0.1.3.tar.gz:

Publisher: release.yml on pay-skill/pay-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pay_skill-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pay_skill-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pay_skill-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dfd1ec0e827f5aeb67a68a8a5580688ea32f6b2fe2c851885bab4382e1c97194
MD5 0b375b68cb175a01bbb52f88a77db38d
BLAKE2b-256 5f91b260c412f17a9f64c1b4f9bc8c9d2f732f66251365c656457c002b64980a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pay_skill-0.1.3-py3-none-any.whl:

Publisher: release.yml on pay-skill/pay-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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