Skip to main content
Start here: need to register a service and create a plan first? Follow the 5-minute setup.
Add payment protection to agents running on Amazon Bedrock AgentCore using the x402 protocol. The @requires_payment decorator handles verification and settlement automatically, wrapping verify - work - settle in a single Lambda invocation.

x402 Payment Flow

MCP Event Format

AgentCore communicates using MCP JSON-RPC 2.0. The decorator expects the AgentCore Gateway interceptor event format:
Key points:
  • The x402 token travels in the payment-signature HTTP header
  • Tool names follow AgentCore convention: TargetName___toolName
  • Only tools/call method is billable by default

Installation

See the Python SDK installation guide for full setup details.
No extra dependencies required. The AgentCore decorator uses only the core payments-py package.

Quick Start: Protecting a Lambda Handler

The @requires_payment decorator wraps a Lambda handler with x402 payment verification and settlement.
The decorator automatically:
  • Returns a 402 PaymentRequired response when no token is provided
  • Verifies the x402 token via the Nevermined facilitator
  • Executes the handler on successful verification
  • Burns credits after successful execution
  • Adds payment-response header and _meta.x402 transaction data to the response

Response Formats

The handler can return any of these formats:

Bare MCP result (simplest)

With credits override

Full MCP response body

Complete InterceptorOutput

The decorator wraps and enriches all formats with payment-response headers and _meta.x402 transaction data.

Credits Flow

The credits parameter is used for both verify (pre-flight check) and settle (default burn amount). The handler can override the settle amount by returning _meta.creditsToCharge in its response.

Decorator Configuration

Basic

With Agent ID

Dynamic Credits

Calculate credits based on the event:

Custom Token Header

Lifecycle Hooks

Client Implementation

Decorator vs Interceptor

payments-py provides two patterns for AgentCore payment protection: Use the decorator when your agent runs as a Lambda function and you want the simplest integration. Use the interceptor when you need a separate payment layer in front of an existing agent target (MCP server, OpenAPI, Lambda) via the AgentCore Gateway.

Environment Variables

Next Steps

Payment Patterns

Advanced credit charging patterns

x402 Protocol

Deep dive into x402 payment flows

Strands Integration

Decorator for Strands AI agent tools

Payment Models

Configure credits, subscriptions, and dynamic pricing