Skip to content

Agent402 with Amazon Bedrock AgentCore

Agent402 serves an AgentCore agent two things: a tool catalog to add as an AgentCore Gateway target, and an x402 offer on every paid call. The sample on this page pays that offer through AgentCore Payments.

Set up the tools

Add one Gateway target; this server offers two sources for it. The commands are from examples/agentcore-gateway, whose MCP server target ran as written with @aws/agentcore 0.27.1. Both start from a project and a gateway:

agentcore create --project-name agent402gw --no-agent && cd agent402gw
agentcore add gateway --name Agent402Gateway --protocol-type MCP --authorizer-type AWS_IAM

OpenAPI target

curl -s https://agent402.tools/openapi.json -o openapi.json
agentcore add gateway-target \
  --name Agent402API \
  --type open-api-schema \
  --schema ./openapi.json \
  --outbound-auth NONE \
  --gateway Agent402Gateway
agentcore deploy --yes

Each catalog route is one operation in the document, with its operationId and input schema.

MCP server target

agentcore add gateway-target \
  --name Agent402MCP \
  --type mcp-server \
  --endpoint https://agent402.tools/mcp \
  --gateway Agent402Gateway \
  --outbound-auth NONE
agentcore deploy --yes

The connector takes no authentication. Its tools include web.search, web.answer, catalog.search, catalog.find and catalog.call, and catalog.call runs a catalog tool by slug. The pure-CPU tools run free on the connector, rate-limited per client.

Pay for calls

This server answers an unpaid call to a paid route with 402, whether it arrives directly or through a Gateway target. In the sample on this page the agent pays. AWS's documentation says AgentCore Payments handles the agent's side of a payment, from receiving the seller's payment request, through signing with the configured wallet provider, to returning the payment proof the agent sends back, and that each Payment Session has a budget limit and an expiry and denies further payment requests once either is reached.

x402 is this server's default for the Payments plugin's HTTP client. A request whose User-Agent starts with python-httpx/ (what the plugin sent when the sample ran) is answered with the x402 offer alone: the PAYMENT-REQUIRED header and the full offer in the body, with no WWW-Authenticate: Payment challenge. The offer is payable in USDC with no extra configuration on this server's side.

To get the MPP challenges instead, send X-Payment-Offers: mpp with the request: the 402 then carries them as every other client gets them. Paying over MPP on Tempo takes USDC.e or PathUSD on Tempo; the sample's Tempo probe sets the plugin's network preferences to Tempo first:

network_preferences_config=["tempo:4217", "eip155:4217"]
buyer_pays_gas_fees=True

A paid call that ends in any status of 400 or above is not charged over x402: settlement runs after the tool and only on a successful response.

Run the sample

examples/agentcore-x402-buyer is a runnable buyer with two entry points.

  • direct_buy.py: fetch, 402, sign, retry, then check the paid sha256 answer against its own hash.
  • agent_buy.py: a Strands agent with the Payments plugin runs a web search, then a cited answer from a model-backed tool, each paid through the plugin.

Tools to try first

Every tool, price and input schema: our tools.

Links