Observed since 21 Oct, 09:52 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
A Python SDK for monetizing AI/autonomous agents with subscription and pay-per-use models
A plug-and-play Python SDK for monetizing AI and autonomous agents. Easily add subscription, pay-per-use, and access control to your agentic, LLM, or SaaS apps—regardless of framework. Supports modular payment providers (Stripe, PayPal, Crypto, Mock) and pluggable storage (Memory, File, Database) with comprehensive health monitoring and validation.
Vision:
For a deep dive into the architecture, design decisions, and vision, see ARCHITECTURE_DECISION.md.
from aiagent_payments import PaymentManager, PaymentPlan
from aiagent_payments.providers import create_payment_provider, StripeProvider, PayPalProvider, CryptoProvider, MockProvider
from aiagent_payments.storage import MemoryStorage, FileStorage, DatabaseStorage
from aiagent_payments.models import PaymentType, BillingPeriod
# Define a payment plan
plan = PaymentPlan(
id="pro",
name="Pro Plan",
payment_type=PaymentType.SUBSCRIPTION,
price=10.0,
currency="USD",
billing_period=BillingPeriod.MONTHLY,
features=["premium"],
)
# Setup manager
provider = create_payment_provider("mock") # or "stripe", "paypal", "crypto"
storage = MemoryStorage()
manager = PaymentManager(storage=storage, payment_provider=provider)
manager.create_payment_plan(plan)
# Subscribe a user (SDK manages subscription internally)
manager.subscribe_user("user@example.com", plan_id="pro")
pip install aiagent_payments
stripe, paypalrestsdk, web3, sqlalchemy, alembic, flask, fastapi, uvicorn, crewai, python-dotenvrequirements.txt and setup.py for full list.aiagent_payments/config.py:
ENABLED_STORAGE = ["memory", "file", "database"]
ENABLED_PROVIDERS = ["mock", "stripe", "paypal", "crypto"]
export AIAgentPayments_EnabledStorage="memory,file,database"
export AIAgentPayments_EnabledProviders="mock,stripe,paypal,crypto"
.env for local secrets (see example.env).from aiagent_payments import PaymentManager, PaymentPlan
# ...see Quickstart above...
from aiagent_payments.providers import StripeProvider
from aiagent_payments.storage import DatabaseStorage
# Check provider health
stripe_provider = StripeProvider(api_key="sk_test_...")
status = stripe_provider.check_health()
print(f"Provider healthy: {status.is_healthy}")
# Check storage health
storage = DatabaseStorage("payments.db")
status = storage.check_health()
print(f"Storage healthy: {status.is_healthy}")
# Get capabilities
capabilities = stripe_provider.get_capabilities()
print(f"Supports refunds: {capabilities.supports_refunds}")
from aiagent_payments.exceptions import ValidationError
try:
# This will raise ValidationError for empty user_id
pm.check_access("", "feature_name")
except ValidationError as e:
print(f"Validation error: {e}")
python cli/main.py --help
You can generate a Stripe-hosted Checkout Session URL for your users:
from aiagent_payments.providers import StripeProvider
from aiagent_payments.models import PaymentPlan
stripe_provider = StripeProvider(api_key="sk_test_...")
plan = PaymentPlan(
id="pro",
name="Pro Plan",
description="Premium access",
payment_type=PaymentType.SUBSCRIPTION,
price=10.0,
currency="USD",
)
success_url = "https://yourapp.com/success"
cancel_url = "https://yourapp.com/cancel"
checkout_result = stripe_provider.create_checkout_session(
user_id="user@example.com",
plan=plan,
success_url=success_url,
cancel_url=cancel_url,
metadata={"source": "web_checkout"}
)
# Use the checkout_url in your web application
checkout_url = checkout_result["url"]
session_id = checkout_result["session_id"]
Accept cryptocurrency payments using stablecoins like USDC, USDP, and USDG:
from aiagent_payments.providers import StripeProvider
stripe_provider = StripeProvider(api_key="sk_test_...")
# Create a stablecoin payment intent
payment_intent = stripe_provider.create_stablecoin_payment_intent(
user_id="user@example.com",
amount=25.00,
currency="USD",
stablecoin="usdc",
metadata={"service": "ai_analysis"}
)
# Create a stablecoin checkout session (hosted payment page)
checkout_url = stripe_provider.create_stablecoin_checkout_session(
user_id="user@example.com",
amount=25.00,
currency="USD",
stablecoin="usdc",
success_url="https://yourapp.com/success",
cancel_url="https://yourapp.com/cancel"
)
# Process the payment
transaction = stripe_provider.process_stablecoin_payment(
user_id="user@example.com",
amount=15.99,
currency="USD",
stablecoin="usdp"
)
# Get supported stablecoins
stablecoins = stripe_provider.get_supported_stablecoins()
# ['usdc', 'usdp', 'usdg']
# Customer management
customer = stripe_provider.create_customer(
user_id="user@example.com",
email="customer@example.com",
name="John Doe"
)
portal_url = stripe_provider.create_customer_portal_session(
customer_id=customer["id"],
return_url="https://yourapp.com/account"
)
Important: Stripe stablecoin payments are currently only available to a limited set of US businesses. You must:
crypto_payments capability activeFor more details, see Stripe's stablecoin documentation.
PayPal Checkout requires user approval, so the SDK provides a two-step flow:
from aiagent_payments.providers import PayPalProvider
paypal_provider = PayPalProvider(
client_id="your_client_id",
client_secret="your_client_secret",
sandbox=True,
return_url="https://yourapp.com/return",
cancel_url="https://yourapp.com/cancel"
)
# Step 1: Create order
order_response = paypal_provider.create_order(
user_id="user_123",
amount=25.99,
currency="USD",
return_url="https://yourapp.com/success",
cancel_url="https://yourapp.com/cancel"
)
# Step 2: Get approval link and redirect user
approval_link = next(
link['href'] for link in order_response['links']
if link['rel'] == 'approve'
)
# Step 3: Capture after user approval (via webhook or return URL)
transaction = paypal_provider.capture_order(
user_id="user_123",
order_id=order_response['id']
)
The examples are organized into logical categories and have been curated to ensure they work end-to-end:
All examples are tested and work without external API keys or dependencies. See the examples directory for more details.
python cli/main.py setup — Initialize storage and planspython cli/main.py list-plans — List available payment planspython cli/main.py subscribe --user user@example.com --plan pro — Subscribe a userpython cli/main.py status --user user@example.com — Show user subscription/statuspython cli/main.py --help for all commands and optionsPaymentProvider in aiagent_payments/providers/ with required methods including _get_capabilities(), _validate_configuration(), and _perform_health_check().StorageBackend in aiagent_payments/storage/ with required methods including _get_capabilities(), _validate_configuration(), and _perform_health_check().__init__.py and update config as needed.pytest --maxfail=3 --disable-warnings -v
make lint
make format
We welcome contributions, bug reports, and feedback from the AI agent developer community. Open an issue or pull request, or join the discussion to help shape the future of agent monetization.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.0.1b1 | 21 Jul 2025 | 33 |
This describes our collected data; it is not a security assessment.
Observed since 21 Oct, 09:52 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:d3fb6c70074d6edde1c31b93364f49ba85c522b0889828ea5df0ec966928c629