> ## Documentation Index
> Fetch the complete documentation index at: https://developers.fd.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Prism (Facilitator)

> How Prism enforces x402 on merchant endpoints — the 402 response format, payment verification, and pricing models.

Prism acts as the x402 facilitator — it adds payment enforcement to your HTTP endpoints without you implementing the protocol directly. You configure prices; Prism handles the 402 response, payment verification, and on-chain settlement.

<Note>
  This page covers x402 from the **merchant/facilitator** perspective. For the
  **buyer/agent** side, see [Agent Wallet (Buyer Side)](/prism/integrations/x402/wallet).
</Note>

## How It Works

```mermaid theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
sequenceDiagram
    participant A as Agent
    participant M as Merchant (Prism SDK)
    participant B as Blockchain
    A->>M: GET /api/data
    M-->>A: 402 Payment Required
    Note over M: x402Version: 2<br/>network: "eip155:8453"<br/>asset: "0x833589fC..."<br/>amount: "10000"<br/>payTo: "0xSpectrum..."
    A->>B: On-chain stablecoin payment
    A->>M: GET /api/data<br/>X-PAYMENT: { signed payment }
    M->>B: Verify via Spectrum
    B-->>M: Confirmed
    M-->>A: 200 OK<br/>X-PAYMENT-RESPONSE: 0xTxHash<br/>Body: { requested data }
```

1. A request arrives without a valid payment header
2. Middleware returns **402 Payment Required** with `x402Version`, `accepts`, and `resource` fields
3. The agent's wallet pays on-chain and retries with an `X-PAYMENT` header
4. Prism's Spectrum layer verifies the on-chain transfer
5. If valid, the request proceeds and the transaction hash returns in `X-PAYMENT-RESPONSE`

Your application code only runs after payment is confirmed.

## Integration

You don't implement the x402 protocol directly — the Prism SDK middleware handles it. You configure what to charge, and the middleware handles the 402 response, payment verification, and settlement automatically. It's available for TypeScript, Python, and Java frameworks:

```typescript theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
import { prismPaymentMiddleware } from "@1stdigital/prism-express";

app.use(
  prismPaymentMiddleware(
    {
      identifyToken: process.env.PRISM_IDENTIFY_TOKEN,
      baseUrl: "https://prism-gw.fd.xyz",
    },
    {
      "/api/premium":     { price: "$0.01", description: "Premium API access" },
      "/api/ai/generate": { price: "$0.50", description: "AI content generation" },
    },
  ),
);
```

See the [Quick Start](/prism/quickstart) for a complete example, or the [SDK Overview](/prism/sdk/overview) for framework-specific guides.

## Payment Requirements (402 Response)

When the middleware returns 402, the response body contains:

| Field         | Type    | Description                                                              |
| ------------- | ------- | ------------------------------------------------------------------------ |
| `x402Version` | integer | Protocol version (currently `2`)                                         |
| `error`       | string  | Human-readable reason, e.g. `"Payment required to access this resource"` |
| `resource`    | object  | Describes the gated resource (see below)                                 |
| `accepts`     | array   | List of accepted payment options — one entry per chain/token combination |
| `extensions`  | object  | Reserved for future protocol extensions; currently `null`                |

The `resource` object contains:

| Field         | Type   | Description                                                     |
| ------------- | ------ | --------------------------------------------------------------- |
| `url`         | string | Full URL of the resource being protected                        |
| `description` | string | Human-readable description of what's being purchased (nullable) |
| `mimeType`    | string | MIME type of the response once payment is settled (nullable)    |

Each entry in `accepts` contains:

| Field               | Type    | Description                                                                                    |
| ------------------- | ------- | ---------------------------------------------------------------------------------------------- |
| `scheme`            | string  | Payment scheme. Prism emits `"exact"` (EIP-3009 `transferWithAuthorization`)                   |
| `network`           | string  | CAIP-2 chain identifier — e.g. `"eip155:8453"` (Base mainnet), `"eip155:84532"` (Base Sepolia) |
| `asset`             | string  | ERC-20 contract address of the settlement token (not a symbol)                                 |
| `payTo`             | string  | Spectrum settlement contract address — the `to` field in the EIP-3009 authorization            |
| `amount`            | string  | Amount in atomic token units (nullable). Example: `"10000"` = \$0.01 USDC at 6 decimals        |
| `maxTimeoutSeconds` | integer | Authorization validity window in seconds. Default: `300`                                       |
| `extra`             | object  | EIP-712 domain info (nullable). Fields: `name`, `version` — present for tokens like USDC       |

## Payment Verification

When the agent sends a request with the `X-PAYMENT` header:

1. Prism parses the signed payment from the header
2. Forwards it to the Spectrum settlement layer
3. Spectrum executes the on-chain transfer and verifies: correct amount, correct token, correct recipient, valid signature
4. If settlement succeeds, the request proceeds and the transaction hash is returned in the `X-PAYMENT-RESPONSE` header
5. If settlement fails, the middleware returns 402 with an error

The merchant never needs to verify payments manually — the middleware handles everything between the 402 and the 200.

## Pricing Models

### Fixed Pricing

Set a static price per endpoint — every request costs the same:

```typescript theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "/api/weather": {
    price: "$0.001",
    description: "Weather data"
  }
}
```

### Tiered Pricing

Different prices for different endpoints:

```typescript theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "/api/basic/*": {
    price: "$0.0001",
    description: "Basic API tier"
  },
  "/api/premium/*": {
    price: "$0.01",
    description: "Premium API tier"
  },
  "/api/ai/generate": {
    price: "$0.50",
    description: "AI generation"
  }
}
```

### Dynamic Pricing

For endpoints where the price depends on the request, apply per-route middleware:

```typescript theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
app.get(
  "/api/compute",
  prismPaymentMiddleware(config, {
    "/api/compute": {
      price: calculatePrice(req), // dynamic based on request
      description: "Compute resources",
    },
  }),
  (req, res) => {
    res.json({ result: "Computed" });
  },
);
```

x402 is an open standard — learn more at [x402.org](https://www.x402.org/). Prism implements the specification and handles the protocol complexity through the SDK, so you configure prices and the middleware does the rest.

<CardGroup cols={2}>
  <Card title="SDK Overview" icon="code" href="/prism/sdk/overview">
    Framework guides for TypeScript, Python, and Java
  </Card>

  <Card title="x402 Implementation" icon="bolt" href="/prism/integrations/x402">
    Both sides of x402: the wallet signs, Prism settles
  </Card>
</CardGroup>
