Skip to main content

Python SDK for AiPayGen APIs with automatic x402 payment handling

Project description

AiPayGen SDK

Python client for AiPayGen APIs with automatic x402 payment handling.

Install

pip install aipaygen-sdk

# With crypto support (auto-pay via USDC)
pip install aipaygen-sdk[crypto]

Quick Start

from aipaygen_sdk import Client

client = Client(api_key="apk_xxx")

# Call tools
result = client.ask("What is quantum computing?")
print(result.result)

result = client.research("AI agent frameworks 2026")
result = client.summarize("Long text here...")
result = client.translate("Hello world", target="es")
result = client.code("def fibonacci(n):", language="python")

# Generic tool call
result = client.call_tool("sentiment", text="I love this product")

# Check balance
balance = client.check_balance()

Auto-Pay (x402)

When your free tier runs out, enable auto-pay to automatically handle 402 responses:

client = Client(
    api_key="apk_xxx",
    auto_pay=True,
    wallet_key="0x...",  # Your Ethereum private key
)

# Automatically pays USDC on Base when 402 is returned
result = client.research("detailed analysis of x402 protocol")
print(result.paid)     # True
print(result.receipt)  # PaymentReceipt(...)

Async

from aipaygen_sdk import AsyncClient

async with AsyncClient(api_key="apk_xxx") as client:
    result = await client.ask("Hello")
    print(result.result)

Streaming

for chunk in client.stream("research", query="MCP servers"):
    print(chunk.data, end="")

Error Handling

from aipaygen_sdk import Client, AuthError, PaymentRequired, RateLimitError

try:
    result = client.ask("Hello")
except AuthError:
    print("Invalid API key")
except PaymentRequired as e:
    print(f"Payment needed: {e.payment_info}")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after}s")

Environment Variables

  • AIPAYGEN_API_KEY — default API key (alternative to passing api_key=)

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

aipaygen_sdk-0.1.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

aipaygen_sdk-0.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file aipaygen_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: aipaygen_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for aipaygen_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4b76ab61b292a3e983954b43aa9c707279937e59cee2bd86764ba7a0e105d715
MD5 5350bfb21b400f9800fa2d12f3519100
BLAKE2b-256 8abb9f4d93c5ba60c446a6e55e0ccc62b2055bc43784d1a23a4a7aa83169883f

See more details on using hashes here.

File details

Details for the file aipaygen_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aipaygen_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for aipaygen_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a52e3e7a0b7ad76ca2a23d21af2e216b09235ecc86a3c6e7dd53956339c11d9
MD5 6cdb4bf513b1859461a966f369ba2fec
BLAKE2b-256 ea7b97fbc1503a2e436a68555f628879dd22c208f6b6ec4bd4f060d65bc64a87

See more details on using hashes here.

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