Start here: need to register a service and create a plan first? Follow the
5-minute setup.
@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:- The x402 token travels in the
payment-signatureHTTP header - Tool names follow AgentCore convention:
TargetName___toolName - Only
tools/callmethod is billable by default
Installation
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.
- Returns a
402 PaymentRequiredresponse 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-responseheader and_meta.x402transaction 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
_meta.x402 transaction data.
Credits Flow
Thecredits 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