Reference for the AgentPayClient.validate_api_key() method, for proactively checking the status and validity of a User API Key.
validate_api_key()
method allows your MCP server to proactively check the status of a User API Key with AgentPay before attempting a consume()
call or performing other actions.
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.api_key
(str, required):
ValidationResult
)validate_api_key()
method returns a ValidationResult
object with the following attributes:
is_valid
(bool):
True
if the API key is valid, active, and recognized by AgentPay for your service.False
otherwise (e.g., key does not exist, is inactive, suspended, or not associated with your service).invalid_reason
(str | None):
is_valid
is False
, provides the reason for invalidity. Possible values:
"invalid_key"
: The key is not recognized or has been revoked"outstanding_payment"
: The key is associated with an account that has outstanding payments"insufficient_balance"
: The key is valid but the associated account has insufficient balanceNone
if is_valid
is True
AgentPayError
: If there is an error communicating with the AgentPay serviceValueError
: If the api_key
parameter is empty or Nonevalidate_api_key()
consume()
call, perhaps for non-billable operations that still require a legitimate user, or to provide more granular feedback to the user about their key status.consume()
call, the consume()
method itself will validate the key. Calling validate_api_key()
and then immediately consume()
for every billable action would be redundant; only if there is meaningful business logic in between.validate_api_key()
indicates an invalid key, you should typically deny access to the protected resource or functionality.