HTTP 402 is a payment challenge
A service can return a price and payment requirements with HTTP 402. The client fulfills the challenge, retries the request with proof, and receives the resource plus a receipt.
Learn how HTTP 402 agent payments work and design spending controls before an agent can purchase API access, data, or MCP tool calls.
Lesson outcome
Mental model
A service can return a price and payment requirements with HTTP 402. The client fulfills the challenge, retries the request with proof, and receives the resource plus a receipt.
A wallet or payment credential expands what an agent can do. Treat it like a production secret with a deliberately small balance and narrow scope.
Known low-cost services may fit an automatic budget. New vendors, unusual prices, recurring commitments, and sensitive purchases should stop for human approval.
Follow along
Write the five states in your workflow: request, 402 challenge, policy check, payment proof, and receipt. Name which system owns each state.
List the domains, MCP servers, assets, and payment methods the agent may use. Block redirects and any destination not on the list.
Choose a per-call maximum, daily total, monthly total, request-rate limit, and maximum recurring commitment. Enforce these outside the model prompt.
Require approval for a first-time vendor, a changed price, a recurring charge, a sensitive-data purchase, or any transaction above the automatic threshold.
Run one sandbox payment and record the challenge, policy decision, approval identity, payment proof, returned resource, and receipt identifier.
Practice task
Create a policy for an agent that may buy test API or MCP calls from two approved services. It must stop before any new vendor, recurring payment, or transaction above $0.25.
Guardrails