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.
After both exist, call ProcessPayment with the payment session ID, payment instrument ID, and a payment payload. The service validates the request, checks the budget, signs the transaction on the appropriate blockchain, and returns a signed payment result. For the complete request and response schema, see ProcessPayment in the API Reference.
AgentCore payments supports two payment protocols, which you select with the paymentType parameter:
-
CRYPTO_X402— The x402 protocol. Provide the merchant’s x402 payment payload inpaymentInput.cryptoX402, and the agent retries the request with the signed proof in theX-PAYMENTheader. -
MPP— The Machine Payments Protocol (MPP). Forward the merchant’sWWW-Authenticate: Paymentchallenge inpaymentInput.mpp, and the agent retries the request with the returned credential in theAuthorizationheader.
Choose the paymentType that matches the protocol the merchant used in its 402 Payment Required response. For x402 request and response details, see Pay an x402 payment request. For MPP request and response details, see Pay an MPP challenge.
Tip
You can automate the steps on this page with the AgentCore Payments skill in the AWS agent toolkit. The skill is part of the aws-agents plugin and lets an AI coding agent create your Payment Manager, connector, credential provider, payment instrument, and session using the agentcore CLI, and add a process payment tool to your agent. For details, see the quickstart and the AWS agent toolkit on GitHub
There are five ways to invoke the ProcessPayment API:
Example
Pay an x402 payment request
When a merchant responds with an x402 payment payload in its 402 Payment Required response, you forward that payload to AgentCore payments, and AgentCore payments returns a signed proof. You copy the merchant’s payload into paymentInput.cryptoX402, and AgentCore payments checks the budget, signs the transaction with the wallet, and returns the signed proof. You attach the proof to the X-PAYMENT header and retry the original request.
Request and response
Provide the following fields in paymentInput.cryptoX402:
-
version— The x402 protocol version (for example,1or2). Required. -
payload— The merchant’s x402 payment requirements, passed as a JSON object. This specifies thescheme,network,maxAmountRequired,asset,payTo, and other fields from the merchant’s402response. Required. -
permit2AllowanceLimit— The maximum on-chain Permit2 allowance to grant, in the asset’s smallest denomination. Optional. Set this only for theupto(metered) scheme, which settles through the Permit2 contract; supplying it for theexactscheme is a validation error. See Permit2 allowance for upto payments.
The response returns the following fields in paymentOutput.cryptoX402:
-
version— The x402 protocol version. -
payload— The signed transaction proof, as a JSON object. Attach it to theX-PAYMENTheader and retry the original request.
A status of PROOF_GENERATED indicates that the transaction was signed and the payment proof is included in paymentOutput.
Schemes
An x402 payload names a scheme. AgentCore payments supports the following schemes:
-
exact— Pays a fixed amount specified in the merchant’s payload. This is the default scheme, and it requires no allowance handling. -
upto— Pays a metered amount up to a ceiling. This scheme settles through the Permit2 contract, so the payer wallet must have granted a Permit2 allowance. See Permit2 allowance for upto payments.
Permit2 allowance for upto payments
The upto scheme settles through the Permit2 contract, which moves funds with transferFrom. The payer wallet must first grant Permit2 an ERC-20 allowance, or settlement fails with a Permit2-allowance precondition error. This grant follows the same on-chain approval model as any direct Permit2 approval. For more information, see Uniswap Permit2
To handle this, set permit2AllowanceLimit to the maximum allowance in the asset’s smallest denomination (for example, 1000000 = 1 USDC at 6 decimals). To grant an unlimited allowance, pass the maximum uint256 value as a string: 115792089237316195423570985008687907853269984665640564039457584007913129639935. When you set this field, AgentCore payments submits an on-chain approve transaction before signing. This transaction incurs blockchain network (gas) fees paid from the wallet’s native token balance.
Because approve sets, rather than adds to, the wallet’s allowance, set permit2AllowanceLimit only when the wallet needs approving (for example, its first upto payment) to avoid a redundant on-chain transaction. Omit the field to skip allowance handling entirely. This field applies only to the upto scheme; supplying it for the exact scheme is a validation error.
The following example processes an upto payment and grants an allowance of 1 USDC to Permit2. For upto, maxAmountRequired carries the ceiling the merchant advertises in its 402 response, and extra.facilitatorAddress is the settlement facilitator from that same response.
Example
Limitations
-
The
permit2AllowanceLimitfield is valid only for theuptoscheme. Supplying it for theexactscheme returns aValidationException.
For x402 payment request validation errors and their resolutions, see x402 payment request errors. For payment processing errors and their resolutions, see Payment processing errors.
Pay an MPP challenge
When a merchant returns a WWW-Authenticate: Payment challenge in its 402 Payment Required response, forward the challenge verbatim in paymentInput.mpp. AgentCore payments parses the challenge, checks the budget, signs with the wallet, and returns a ready-to-send Authorization header value. AgentCore payments handles the header parsing, base64url decoding, and signing, so you do not need to perform these operations.
Request and response
Provide the following fields in paymentInput.mpp:
-
version— The MPP protocol version (for example,1). Required. -
wwwAuthenticateHeaders— The rawWWW-Authenticate: Paymentheader value from the merchant’s402response, passed verbatim. Provide exactly one header. Required. -
buyerPaysGasFees— Whether to authorize paying blockchain network (gas) fees from the buyer’s wallet when the seller does not sponsor them. Optional. Omitted orfalsemeans the buyer declines. See Network fee consent.
The response returns the following fields in paymentOutput.mpp:
-
version— The MPP protocol version. -
selectedPaymentId— Theidof the challenge that AgentCore payments paid, echoed from the input challenge so that you can correlate the result without decoding the credential. -
paymentCredential— The ready-to-sendAuthorizationheader value, in the formPayment <base64url-token>. Attach it as theAuthorizationheader and retry the original request.
Important
Do not decode or modify paymentCredential. It embeds the original challenge and the signed payload, and the merchant’s HMAC binds to those exact bytes. Attach the value as returned.
The following example processes an MPP challenge. Set --payment-type "MPP" and forward the merchant’s WWW-Authenticate: Payment challenge verbatim in paymentInput.mpp.wwwAuthenticateHeaders (exactly one header).
Example
Methods and tokens
An MPP challenge names a payment method. AgentCore payments supports the following methods for the charge intent:
-
evm— Canonical USDC only. The challenge must includemethodDetails.chainIdandrealm. -
tempo— Any Tempo chain, selected bymethodDetails.chainId, using the network’s recognized USDC-equivalent token. -
solana— Themainnetanddevnetnetworks, with server-sponsored fees only.
The payment instrument’s blockchain network must match the challenge method. Provider support depends on the connector type:
| Method | Coinbase CDP | Stripe (Privy) |
|---|---|---|
|
|
Supported |
Supported |
|
|
Supported |
Supported |
|
|
Not supported |
Supported |
Network fee consent
Blockchain network (gas) fees are separate from the challenge amount. A challenge advertises who sponsors them through its methodDetails.feePayer flag:
-
methodDetails.feePayer=true— The seller sponsors the network fees.buyerPaysGasFeeshas no effect. -
methodDetails.feePayer=falseor absent — The buyer pays the network fees from the paying wallet, in addition to the payment amount. Because that cost is not visible in the challenge amount, AgentCore payments signs only if you setbuyerPaysGasFees=true; otherwise it returns aValidationException. For thetempomethod, this consent is required whenever the seller does not sponsor fees.
The evm method needs no fee consent, because the facilitator broadcasts the transaction and pays the gas. The solana method supports only server-sponsored fees today.
Limitations
-
AgentCore payments fulfills exactly one challenge per
ProcessPaymentcall. Provide a single header inwwwAuthenticateHeaders. -
Only the
chargeintent and pull mode are supported. -
MPP challenges are short-lived. If the challenge has expired, AgentCore payments returns a
ValidationExceptionand consumes no budget. Request the paid resource again to obtain a fresh challenge, then retry.
For MPP challenge validation errors and their resolutions, see MPP challenge errors.
Framework integrations
For full reference documentation including error handling, configuration options, and built-in tools, see Framework integrations.
| Framework | Integration type | Reference |
|---|---|---|
|
Plugin (hook-based) |
Interrupt handling, config options, built-in tools |
|
|
Middleware (wraps tool calls) |
Error callbacks, allowlists, async support, config options |