The AgentPayClient is the primary interface for interacting with the AgentPay system from your Python MCP server.
The agentpay-sdk package currently on PyPI is a placeholder to reserve the name during Early Access. To get the actual SDK now, join the Waitlist.

Initialization

To begin, you need to import and initialize the AgentPayClient:
from agentpay_sdk import AgentPayClient
import os

# Retrieve your Service Token
# It's highly recommended to store and access your Service Token via an environment variable.
SERVICE_TOKEN = os.getenv("AGENTPAY_SERVICE_TOKEN")

if not SERVICE_TOKEN:
    # Handle the error appropriately in your application context
    print("CRITICAL: AGENTPAY_SERVICE_TOKEN environment variable is not set.")
    # For example, you might raise an exception:
    # raise EnvironmentError("AGENTPAY_SERVICE_TOKEN is not set.")
    agentpay_client = None
else:
    try:
        agentpay_client = AgentPayClient(service_token=SERVICE_TOKEN)
        print("AgentPayClient initialized successfully.")
    except Exception as e:
        print(f"Error initializing AgentPayClient: {e}")
        agentpay_client = None

AgentPayClient Constructor

AgentPayClient(service_token: str)
  • service_token (str, required):
    • Your unique Service Token obtained from the AgentPay Hub after registering your MCP server.
    • This token authenticates your server with AgentPay.
    • Security Note: The Service Token is highly sensitive. It is strongly recommended to load it from an environment variable or a secure secrets management system rather than hardcoding it.
It’s generally recommended to initialize the AgentPayClient once and reuse the instance throughout your application. This avoids redundant initializations and can be more efficient. How you achieve this depends on your web framework:
  • In Starlette, you might store it on the application object
  • In Flask, you might use the application context
  • In Django, you might use a custom middleware

Error Handling

Ensure proper error handling when initializing the client:
# Later in your code, before making calls:
if agentpay_client:
    # Proceed with agentpay_client.consume() or agentpay_client.validate_api_key()
else:
    # Handle the case where client initialization failed

Methods

This SDK reference page focuses on the AgentPayClient object initialization. For details on its methods, see: