Skip to main content

Amazon Bedrock AgentCore + Privy

Enable AI agents to make autonomous stablecoin payments via AWS Bedrock AgentCore Payments using Privy embedded wallets. This recipe covers how to use Privy embedded wallets as the payment provider for AWS Bedrock AgentCore Payments, so agents can autonomously pay for APIs, MCP servers, and content using the x402 protocol.

Overview

Amazon Bedrock AgentCore is AWS’s managed platform for building and operating AI agents. AgentCore Payments is the service that lets an agent pay for paid endpoints (APIs, MCPs, and web content) over the x402 protocol. It owns the entire payment lifecycle: storing provider credentials, enforcing per-session spend limits, signing the payment, and recording the transaction. Privy provides the user-owned embedded wallet that holds the stablecoins. AgentCore connects to Privy through a PaymentConnector, retrieves signing material through AgentCore Identity, and calls ProcessPayment to produce the signed x402 proof. The agent never talks to Privy’s wallet APIs directly — it calls AgentCore, and AgentCore talks to Privy. With this integration, agents can:
  • Discover and call paid APIs, MCP tools, and paywalled content that return 402 Payment Required
  • Accept funds from the end user via fiat (cards, Apple Pay, Google Pay, ACH) or USDC stablecoin
  • Pay autonomously to the paid endpoint over x402 (v1 and v2)
  • Operate within spend limits enforced per Payment Session by AgentCore
  • Settle on-chain in USDC

How it works

AgentCore Payments is built from a small set of resources. Create them once, in order, and the agent uses them at runtime.
  • PaymentManager — The top-level resource for your account. It defines how agents authenticate (AWS_IAM or CUSTOM_JWT) and references the IAM execution role AgentCore assumes to do payment work.
  • PaymentCredentialProvider — Stores your Privy credentials (App ID, App Secret, authorization key) inside AgentCore Identity, backed by AWS Secrets Manager. The agent runtime never reads these directly.
  • PaymentConnector — Binds the PaymentManager to a payment provider. For Privy, create a StripePrivy connector that references the credential provider above.
  • PaymentInstrument — The end user’s wallet. Create it through the AgentCore CreatePaymentInstrument API (type EMBEDDED_CRYPTO_WALLET), not through the Privy SDK. AgentCore provisions the Privy embedded wallet on your behalf and returns the wallet address.
  • PaymentSession — A time-bounded spending context (maxSpendAmount, currency, expiryTimeInMinutes). When the session expires or the limit is reached, further payments in that session are denied.
  • ProcessPayment — At runtime, when the agent hits a 402, it calls ProcessPayment. AgentCore checks the session limit, retrieves the Privy signing key from Identity, signs the x402 proof, and returns it. The agent retries the request with the proof.
The runtime flow:

Automated setup using the AgentCore Payments skill

You can provision everything in this recipe two ways. The manual, step-by-step path is documented below (Manual setup). If you use an AI coding agent such as Kiro, Claude Code, or Codex, the AgentCore Payments skill can provision the same resources for you through a guided conversation, handling the CLI commands, SDK scripts, and framework wiring automatically. The skill provisions the following resources:
  • PaymentCredentialProvider — Stores your Privy credentials (App ID, App Secret, Authorization ID, Authorization Private Key) in AgentCore Identity.
  • Payment Manager — The top-level resource that coordinates payment operations.
  • Payment Connector — Links the manager to your Privy credentials via the AgentCore CLI.
  • Payment Instrument — A Privy embedded crypto wallet that your agent uses to pay merchants on behalf of a user.
  • Payment Session — A time-bounded context with spending limits.
The skill also wires payments into your agent with a framework-agnostic tool, so it works with Strands, LangGraph, OpenAI Agents SDK, or any Python framework.

Skill prerequisites

Before starting, make sure you have:
  • AWS account with credentials configured (aws configure).
  • An AWS Region where AgentCore Payments is availableus-east-1, us-west-2, eu-central-1, or ap-southeast-2.
  • Node.js 20+ installed (the skill installs the AgentCore CLI automatically).
  • A dedicated Privy app and authorization key — Have your App ID, App Secret, Authorization ID, and Authorization Private Key (with the wallet-auth: prefix stripped) ready. See the Manual setup prerequisites below for how to obtain these.
  • An agent that accesses a paid endpoint — The skill enables your agent to pay for x402-protected APIs. For testing, use the sandbox endpoint https://sandbox.node4all.com/v1/x402-test.
  • The Agent Toolkit for AWS aws-agents plugin installed in your AI coding agent.
Claude Code:
Codex: The plugin is discovered automatically from the marketplace manifest. To add the marketplace, run:

Invoke the skill

The payments skill is part of the agents-build skill in the Agent Toolkit for AWS. To trigger it, describe your intent in your AI coding agent. For example:
  • “Add payments to my agent using agents-build skill in aws-agents plugin”
  • “Set up microtransactions for my agent using agents-build skill in aws-agents plugin”
  • “I need to handle 402 Payment Required responses using agents-build skill in aws-agents plugin”
  • “Wire my agent to pay for x402-protected APIs using agents-build skill in aws-agents plugin”
The skill detects payment-related intent and loads the payments workflow automatically.

What the skill does

The skill runs an automated process that provisions your payment infrastructure end-to-end. It runs most steps automatically and pauses twice for your input:
  1. Verifies or installs the AgentCore CLI and sets up the project.
  2. Creates the payment manager.
  3. Pauses — Run agentcore add payment-connector to enter your Privy provider secrets (App ID, App Secret, Authorization ID, and Authorization Private Key).
  4. Deploys resources to your AWS account (agentcore deploy -y).
  5. Wires a framework-agnostic payment tool (x402_payment_tool.py) into your agent.
  6. Creates a per-user Privy embedded wallet (instrument) and a budget-bounded session via the SDK.
  7. Pauses — Authorize the wallet (delegation) through the Privy wallet hub and fund it with testnet USDC from the Circle faucet.
  8. Sets environment variables and runs a test payment against a paid endpoint.
Before running the connector command, obtain your Stripe Privy credentials from the Privy dashboard: App ID, App Secret, Authorization ID, and Authorization Private Key (with the wallet-auth: prefix stripped). A successful run shows the agent calling x402_fetch, detecting a 402, settling payment via the AgentCore SDK, and the retry returning 200 with paid content.

Manual setup

This section walks through provisioning each resource manually with the AWS SDK (boto3). Follow these steps if you are not using the AgentCore Payments skill described above. Complete them in order, from prerequisites through creating a payment session.

Prerequisites

  • AWS account with AgentCore Payments access — Install and configure the AWS CLI v2 and Python 3.10+ with boto3. Verify your credentials with aws sts get-caller-identity. AgentCore Payments is available in us-east-1, us-west-2, eu-central-1, and ap-southeast-2.
  • A dedicated Privy app — Create a developer account at dashboard.privy.io and create a dedicated Privy app for AgentCore. Do not reuse an app that serves other purposes; this keeps credential scope and auditing clean. Copy the App ID and App Secret from the app settings.
  • A Privy authorization key — In your Privy app, go to Wallet Infrastructure > Authorization > New Key to generate a P-256 key pair. This key is what AgentCore uses to sign wallet operations. Note the Authorization ID (signer ID) shown alongside the key.
Privy prefixes the generated private key with wallet-auth:. AgentCore Payments does not accept this prefix. Strip it and store only the raw base64 content after the prefix.
After this, there are four Privy values to hand to AgentCore: App ID, App Secret, Authorization ID, and the Authorization Private Key (prefix stripped). For full provider detail, see the AWS Prerequisites for AgentCore payments.

Step 1: Store Privy credentials in AgentCore Identity

Create a PaymentCredentialProvider so AgentCore can store your Privy credentials securely. Resource names must be lowercase alphanumeric with hyphens only.
Never embed Privy credentials in agent source code or paste them in chat. Load them from environment variables (source .env.payments) at setup time. Once stored in AgentCore Identity, restrict the underlying Secrets Manager secret to the AgentCore Payments service role only.

Step 2: Create the Payment Manager

The Payment Manager needs an IAM role that trusts bedrock-agentcore.amazonaws.com and grants GetWorkloadAccessToken, GetResourcePaymentToken, and secretsmanager:GetSecretValue (see the IAM roles page for the exact policy).

Step 3: Create the Payment Connector

Bind the manager to Privy by referencing the credential provider from Step 1.

Step 4: Create the Payment Instrument (wallet)

Create the user’s embedded wallet through AgentCore. The end user’s email is linked here: it is the account they will log into when granting the agent permission to spend.
A new instrument starts with 0 USDC and the agent has no permission to spend until the end user grants it. Funding and delegation come next, in that order.

Step 5: Grant the agent permission (delegation)

This is a required step. The agent’s authorization key must be added as a signer on the end user’s embedded wallet, and only the user can approve that.
  1. Stand up a frontend using the Privy AgentCore SDK, which provides a reference wallet hub for login, agent connection, and on-ramping.
  2. Have the end user log in with the email linked in Step 4 (END_USER_EMAIL).
  3. The user approves delegation for the wallet, authorizing the agent to sign within AgentCore’s controls.
If delegation is skipped, ProcessPayment fails with a “Delegation not completed” error. The agent acts as an authorized signer only: the user retains ownership and can revoke access at any time.

Step 6: Fund the wallet

Once delegation is approved, fund the wallet with USDC.
  • Testnet: Get free testnet USDC on Base Sepolia from Circle’s faucet and send it to the wallet address from Step 4.
  • Mainnet: The end user funds the wallet through the Privy wallet hub: crypto-to-crypto transfer or supported fiat methods (cards, Apple Pay, Google Pay, ACH; availability varies by region).

Step 7: Create a Payment Session and enable payments

Create a session to bound spending, then wire payment handling into your agent.
The agent uses an x402-aware fetch tool. When it hits a 402, the tool reads the challenge, calls ProcessPayment, and retries with the signed proof. AgentCore checks the session limit, signs through Privy, and returns the proof.
Register x402_fetch as a tool in your agent framework (Strands, LangGraph, OpenAI Agents SDK, etc.) and the agent will pay for 402 resources autonomously.
Use a fresh HTTP client for the retry. Some merchants set cookies on the 402 response that cause the paid retry to fail if reused. Also build the proof to match the challenge’s x402Version: a v2 merchant silently ignores a v1 X-PAYMENT header and re-issues the same 402.

Spend controls

AgentCore enforces spending at the Payment Session level. There are no per-recipient allowlists or separate budget objects. When a payment would exceed the limit or the session has expired, AgentCore denies it before signing.

Observability

AgentCore Payments integrates with Amazon CloudWatch. Once enabled, every data plane API call (ProcessPayment, CreatePaymentInstrument, etc.) emits metrics, logs, and X-Ray spans automatically.

Enable it

  1. Create a CloudWatch log group (e.g. /bedrock-agentcore/payments/my-logs).
  2. Grant your IAM principal vended-log and X-Ray delivery permissions (logs:CreateDelivery, xray:PutTraceSegments, bedrock-agentcore:AllowVendedLogDeliveryForResource, and related).
  3. On the Payment Manager details page, under Log deliveries and tracing, point log delivery at your log group and enable traces.

Vended metrics

Key payment metrics published to CloudWatch: PaymentRequestCount, PaymentSuccessCount, PaymentFailureCount, PaymentLatency, and SpendAmount, plus per-operation OperationSuccess, OperationFailure, OperationLatency, Throttles, UserErrors, and ActiveSessions. Dimensions: Operation, PaymentManagerId, PaymentConnectorId, AgentName, and Currency. Alarm on PaymentFailureCount (misconfiguration/abuse signal) and PaymentLatency against your SLA.

Vended spans

One span per API call, named Bedrock.AgentCore.Payments.<Operation>, viewable in X-Ray with payment-specific attributes: spend_amount, spend_currency, merchant (payTo), session_remaining_budget, total_budget_amount, and token_fetch_latency_ms — plus resource IDs and standard AWS attributes. For the full reference, see the AgentCore Payments observability docs.

Supported networks

AgentCore Payments with Privy settles in USDC. For instrument creation, choose a network family; the x402 challenge then specifies the exact chain. For development, start with ETHEREUM / Base Sepolia and free testnet USDC from Circle’s faucet.

Testing

  • Use Base Sepolia for development.
  • Fund the wallet with testnet USDC from Circle’s faucet.
  • Point the agent at an x402-enabled test endpoint and confirm it pays and returns content. Browse live x402 services at x402scan.com.
If the agent loops on 402 after a successful ProcessPayment, the most common causes are cookie contamination on the retry, an x402 version/header mismatch, or an expired proof (~60s validity window).

Security considerations

  • User ownership. AgentCore is an authorized signer, not the wallet owner. The user grants delegation and can revoke it at any time. The user can also withdraw funds from the wallet at any time.
  • Credential isolation. Privy credentials live in AgentCore Identity / Secrets Manager. Restrict the secret to the AgentCore Payments service role only.
  • Session limits. Per-session maxSpendAmount and short expiry bound runaway spending.
  • HTTPS only. Reject non-HTTPS targets and block private/internal IP ranges to prevent SSRF.
  • Audit. AgentCore Observability and CloudTrail capture every ProcessPayment call; alarm on failed-payment spikes.
  • Rotate the App Secret and authorization key on a regular schedule (e.g., every 90 days).

Further reading