Skip to main content
After installing the AgentPay SDK, the next crucial step is to initialize the AgentPayClient in your MCP Server application. This client object is your primary interface for interacting with AgentPay services like recording consumption and validating API keys.

Basic Initialization

To initialize the client, you need your Service Token (obtained when you registered your server).

Key Points for Initialization:

  • Service Token Security: Always load your Service Token from a secure source, like an environment variable or a secrets management system. Do not hardcode it in your source code.
  • Singleton Instance (Recommended): Typically, you should initialize the AgentPayClient once when your application starts and reuse the same instance throughout the lifetime of your server process. This is more efficient than creating a new client for every request.
    • How you achieve this depends on your web framework (e.g. storing it on the application object in Starlette).
  • Error Handling: Be prepared to handle cases where the SERVICE_TOKEN environment variable might not be set or if the client initialization itself fails for some reason (though typically, basic initialization is lightweight).

Client Configuration Options

At the moment, there are no other client configuration options, since:

Next Steps

Once the AgentPayClient is successfully initialized, you can proceed to: