Skip to main content

Install

Import

@sigil-xyz/x402/next is a separate subpath — do not import from @sigil-xyz/x402 for Next.js usage.

Basic usage

Wrap your route handler with withSigilAuth:

TypeScript: sigilAgent type

The wrapped handler receives a NextRequest extended with sigilAgent?: string. This is already typed inside withSigilAuth — no extra declaration needed.

Verification only

Sharing config

Define the middleware config once and reuse it across routes:

Building agent headers

Use buildSigilHeaders from @sigil-xyz/x402 in your agent code to construct the signed headers:

Error responses

On failure the middleware returns 402 Payment Required: