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.5.tar.gz (22.5 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.5-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pay_skill-0.1.5.tar.gz
  • Upload date:
  • Size: 22.5 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.5.tar.gz
Algorithm Hash digest
SHA256 716876cc96ad336378234dde27781351feaed769287a55a4cb68013d6ef9bd30
MD5 ce673769027be3ddb09aca6fae90cfbb
BLAKE2b-256 8fb46825353f931a63d5bc95529b4de3e211e8ffbc2b054eddea86f88014d7a5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pay_skill-0.1.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fa9a8a227576ec5848c30bf08381ebd4df172cb1b283ce10f611b2cd146bf787
MD5 4c02f0422e603f5746ce118de0ae5674
BLAKE2b-256 5596492953bd810e5e5c7af1c0637f70c1b6196a53bf8670036ebc57c09be6d1

See more details on using hashes here.

Provenance

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