Guidance on SDK error categories, communicating errors to users, logging best practices, and general exception handling for robust server development.
agentpay_client.consume()
and agentpay_client.validate_api_key()
can result in errors. The primary way to check for these is by inspecting the success
attribute (or is_valid
for validation) of the result object and then using the error_code
and error_message
for details.
INSUFFICIENT_FUNDS
from consume()
):
INVALID_API_KEY
from consume()
or validate_api_key()
):
AGENTPAY_SERVICE_TOKEN
environment variable is correct and the AgentPay Hub shows your server as active.SERVER_RATE_LIMITED
if AgentPay applies rate limits to service token usage.)consume()
calls, especially using the same usage_event_id
for idempotency. For validate_api_key()
, retries might also be appropriate depending on the context.try...except
blocks to catch any unexpected exceptions that might arise from the SDK itself (e.g., issues with underlying HTTP libraries, unexpected response parsing errors).
error
, message
, details
fields) that client applications can parse and handle.usage_event_id
, user_id
(if available on your end), amount_cents
) for your own auditing and records, though AgentPay Hub will be your primary source of truth for billing.api_key
(or a non-sensitive part of it), error_code
, error_message
, and usage_event_id
for debugging and support.