The agent pays for a remote resource that requires USDC via the x402 protocol. Budget-checked, kill-switch-gated, atomically enforced.
This is the payment primitive of the Agent Kit. The agent presents a payment requirement (received from a 402-responding service), the API validates against all 3 budget layers + the kill switch, executes the on-chain USDC transfer, and returns a payment header the agent can attach to retry the original request.Documentation Index
Fetch the complete documentation index at: https://docs.relayer.fi/llms.txt
Use this file to discover all available pages before exploring further.
x402fetch() helper instead of calling this endpoint directly. x402fetch handles the full 402 → pay → retry loop transparently.x402fetch| Use case | Recommended |
|---|---|
| Calling a third-party API that may return 402 | x402fetch — handles the loop for you |
| Building a custom client (non-Node.js, no SDK) | This endpoint — replicate the loop yourself |
| Paying for a resource without retrying (e.g. pre-paying for batch credit) | This endpoint — caller controls what to do with the payment header |
| Inspecting payment intent before executing | This endpoint — you can re-render the requirement to the user before submission |
x402fetch)await x402fetch(sdk, url, init) call in the SDK. This page covers what happens server-side during the middle step.
X-Agent-Auth + x-agent-id + x-request-timestamp) — when called by the agent SDK at runtime. See Authentication for the payload spec.Authorization: ApiKey ...) — when called by your backend on behalf of the agent.{id} path param must match the calling agent (if HMAC) or be a valid agent in the API key’s workspace (if API key).
paymentRequirement object:
"0.05"). String to avoid float precision issues."USDC" in v1. Reserved for future expansion."solana". EVM chain support is planned.X-Payment header. The resource will validate it and serve the protected content.killed or paused.infra — does the agent have infrastructure budget left?tokens — does the agent have LLM token budget left? (informational here)payments — does the requested amount fit under monthlyUSDC AND perTxUSDC?amount >= approvalThresholdUSDC, holds the payment and returns HTTP 202 with { approvalId } instead of executing. Wait for human approval, then retry.payment event to the agent event stream (visible at GET /v1/agents/{id}/audit).x402-pay calls, the Lua deduction ensures no double-spend past the cap. The cap cannot be bypassed by code path manipulation in the agent.
x402fetch handles this transparently — it polls /v1/signing/approvals/{id} every 5s until resolved or approvalTimeout (default 5 minutes), then retries the original request.
If you’re calling this endpoint directly, you must implement the same loop. Approvals can resolve in one of three states:
approved — proceed with the original retry using the payment headerrejected — surface the error to your agent’s reasoning; do not retryexpired — same as rejected; the threshold was set for a reason| Status | Cause | Fix / Recovery |
|---|---|---|
401 invalid_auth | HMAC headers missing or signature mismatch | Verify the SDK is correctly initialized; check secret rotation |
401 agent_killed | Agent in killed state | Provision a new agent; this one is dead |
402 budget_exhausted | One or more budget layers empty. Response body includes failedLayers | Top up the budget via POST /v1/agents/{id}/budget and retry |
402 insufficient_wallet_balance | Budget OK but wallet has no USDC | Fund via POST /v1/agents/{id}/fund/prepare + /fund/confirm |
503 kill_switch_active | Global kill switch tripped | Wait for resolution; do not retry until kill switch clears |
202 approval_required | Above threshold | Poll the approval ID |
paymentRequirementpaymentRequirement depends on the 402-responding service. The SDK normalizes common variants:
WWW-Authenticate: x402 headerpaymentRequirement JSON bodyPayment-Required body fieldx402fetch wrapper. It handles 402 detection, this endpoint call, header injection, and retry transparently — your agent code calls a normal fetch and never deals with payment plumbing directly. See SDK Reference — x402fetch.
x402fetch — the recommended way to do thisPOST /v1/agents/{id}/budget — adjust spend limits if you hit them oftenPOST /v1/agents/{id}/fund/prepare — top up the agent wallet