Process a payment
To process a payment, you need two resources:
-
Payment instrument — An embedded crypto wallet with Coinbase or Stripe. See Create a payment instrument.
-
Payment session — A time-bounded session that optionally enforces a spending budget. See Create a payment session.
Once both exist, call ProcessPayment with the payment session ID, payment instrument ID, and an x402 payment payload. The service validates the request, checks the budget, signs the transaction on the appropriate blockchain, and returns a cryptographic proof. For the complete request and response schema, see ProcessPayment in the API Reference.
There are three ways to invoke the ProcessPayment API:
Example
Strands SDK reference
The following sections describe Strands-specific configuration and behavior.
Handling payment interrupts
When payment processing fails, the plugin stores the failure and raises an interrupt. Your application should handle these interrupts:
result = agent("Access the premium endpoint at https://api.example.com/premium") while result.stop_reason == "interrupt": responses = [] for interrupt in result.interrupts: if interrupt.name.startswith("payment-failure-"): reason = interrupt.reason exception_type = reason.get("exceptionType") if exception_type == "PaymentInstrumentConfigurationRequired": plugin.config.update_payment_instrument_id("payment-instrument-new123") responses.append({ "interruptResponse": { "interruptId": interrupt.id, "response": "Payment instrument configured. Please retry.", } }) elif exception_type == "PaymentSessionConfigurationRequired": plugin.config.update_payment_session_id("payment-session-new456") responses.append({ "interruptResponse": { "interruptId": interrupt.id, "response": "Payment session configured. Please retry.", } }) else: responses.append({ "interruptResponse": { "interruptId": interrupt.id, "response": f"Payment failed: {reason.get('exceptionMessage')}", } }) result = agent(responses)
Disabling auto-payment
To access only payment visibility tools without automatic payment execution (for example, to keep a human or custom logic in the loop before any payment transaction), disable automatic processing:
config = AgentCorePaymentsPluginConfig( payment_manager_arn="arn:aws:bedrock-agentcore:us-east-1:123456789012:payment-manager/pm-abc123", user_id="user-123", region="us-east-1", auto_payment=False, # Disable automatic 402 processing )
Network preferences
You can specify preferred blockchain networks for payment processing:
config = AgentCorePaymentsPluginConfig( payment_manager_arn="arn:aws:bedrock-agentcore:us-east-1:123456789012:payment-manager/pm-abc123", user_id="user-123", payment_instrument_id="payment-instrument-xyz789", payment_session_id="payment-session-def456", region="us-east-1", network_preferences_config=["eip155:8453", "base-sepolia", "solana-mainnet"], )
If not specified, the system uses a default preference order prioritizing Solana mainnet and Base (Ethereum L2) for low transaction fees.
Configuration options
The following table lists the AgentCorePaymentsPluginConfig parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
|
|
|
Yes |
ARN of the Bedrock AgentCore Payment Manager resource |
|
|
|
Yes |
Unique identifier for the user |
|
|
|
No |
Payment instrument ID. Can be set later via |
|
|
|
No |
Payment session ID. Can be set later via |
|
|
|
No |
AWS region for the payment manager |
|
|
|
No |
List of network CAIP-2 identifiers in order of preference |
|
|
|
No (default: |
Whether to automatically process 402 payment requirements |
|
|
|
No (default: |
Maximum interrupt retries per tool use. Set to 0 to disable interrupts |
|
|
|
No |
Agent name propagated via HTTP header on API calls |
Built-in agent tools
The plugin registers three tools that agents can use to query payment information at runtime:
| Tool | Description |
|---|---|
|
|
Retrieve details about a specific payment instrument |
|
|
List all payment instruments for a user |
|
|
Retrieve details about a payment session (budget, status, expiry) |
These tools enable agents to make informed decisions about payment methods and payment limits during conversations. For more details and end-to-end examples, refer to the Strands Agents