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.9.tar.gz (23.3 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.9-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pay_skill-0.1.9.tar.gz
  • Upload date:
  • Size: 23.3 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.9.tar.gz
Algorithm Hash digest
SHA256 b3a50c4a70e3235b2a2c6732ae7044eecdbc17b98d410784e22266566fa82615
MD5 a5910c64e5c5fa7cd9a2fcf71059e4fa
BLAKE2b-256 bcf1fc9d5e997f81c45f0ff98efe7e07b7308bb9d66b75b19f83242ce38928b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pay_skill-0.1.9.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.9-py3-none-any.whl.

File metadata

  • Download URL: pay_skill-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 17.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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 8adaa153c0252dcc10a431e5d9e2abd70cb53fe82b4dd4aec69775df996f4a30
MD5 7d84d5d5b2d54b5a6d650f90d5f36011
BLAKE2b-256 8393f5681059150f7d7d643f69eadff24ec92664394283b3da2cb2c33c95815c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pay_skill-0.1.9-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