Skip to content

Proposal: Paid API Gateway architecture for x402 (OpenAPI wrappers, facilitator starter kit, operation-bound receipts, persistent SIWX proofs) #1921

@ayushozha

Description

@ayushozha

Summary

I want to propose a single architecture direction that ties together four adjacent ideas:

  1. OpenAPI-to-x402 Wrapper Generator
  2. Self-Hosted Facilitator Starter Kit
  3. Persistent SIWX Payment History + Proofs
  4. Operation-Bound Receipts

I am not proposing that all four land at once.

I am proposing that x402 consider a shared architecture for them, because they all appear to solve the same higher-level problem:

x402 already has strong payment primitives, but turning an existing API into a trustworthy paid API still requires too much bespoke glue around validation, receipts, repeat-access proofs, and facilitator deployment.

Refs: #1645, #1886, #1908, #1759, #1195, #1802

Why This Feels Like One Problem, Not Four

Today, if I want to wrap an existing API behind x402 and make it production-friendly, I need to solve all of this myself:

  • how to transform an existing OpenAPI surface into x402 route declarations and middleware
  • how to bind a payment to the specific validated operation being executed, not just the route
  • how to support repeat access in SIWX without relying on an in-memory server-local map
  • how to run a facilitator as a real service with auth, metrics, health checks, rate limits, and multi-network config

Those are currently separate pain points, but they can share one model.

Proposed Direction: PayableOperation Architecture

The core idea is to introduce a canonical intermediate model for a paid operation that tooling, receipts, SIWX, and facilitator deployment can all share.

1. PayableOperation descriptor

A PayableOperation is the canonical description of a paid endpoint or tool invocation.

Example shape:

interface PayableOperation {
  operationId: string;
  method: string;
  pathTemplate: string;
  inputSchemaRef?: string;
  pricing: PaymentOption[];
  canonicalization: "openapi-json-c14n-v1" | "none";
  receiptBinding: {
    includePathParams: boolean;
    includeQuery: boolean;
    includeBody: boolean;
    hash: "sha256";
  };
  accessPolicy?: {
    reusableViaSIWX: boolean;
    resourceKey: string;
    policyVersion: string;
  };
}

This should be creatable either:

  • manually from existing x402 route configs
  • or generated from an OpenAPI spec

2. operationDigest

At runtime, after request validation and canonicalization, the server computes an operationDigest from the validated request input.

For example:

sha256(
  method +
  pathTemplate +
  canonical(pathParams, query, body) +
  operationId +
  policyVersion
)

That digest becomes the thing the receipt is bound to.

This would directly address the concern raised in #1886 / #1645 that a payment receipt should prove not just "a payment happened" but "a payment happened for this exact validated operation."

3. OperationBoundReceipt

After settlement, the server/facilitator emits a structured receipt that includes:

  • settlement reference (tx hash / signature / network)
  • operationId
  • operationDigest
  • payer
  • payee
  • amount / asset
  • optional server or facilitator signature over the receipt payload

This could either:

  • extend the existing offer/receipt direction
  • or become a new extension specifically for operation-bound execution proofs

This gives x402 a stronger answer for irreversible paid actions than "the route was paid at some point."

4. AccessGrantProof for SIWX

Instead of SIWX relying only on a server-local hasPaid(resource, address) store, it could persist a higher-level proof object:

interface AccessGrantProof {
  payer: string;
  resourceKey: string;
  settlementRef: string;
  operationDigest?: string;
  policyVersion: string;
  issuedAt: string;
  expiresAt?: string;
  signer: "resource-server" | "facilitator";
  signature?: string;
}

This would allow:

  • persistent Redis/Postgres backends
  • cryptographic "already paid" proofs instead of bare in-memory state
  • future portability across restarts, deployments, and possibly services

I think this is the cleanest way to evolve SIWX without turning it into an unrelated product.

5. Facilitator Runtime Profile

The self-hosted facilitator starter kit could be defined around a standard runtime profile:

networks:
  - eip155:8453
  - solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp
http:
  port: 8402
  cors: ["*"]
auth:
  mode: bearer
observability:
  metrics: prometheus
  health: true
rateLimits:
  verifyPerMinute: 600
  settlePerMinute: 120
stores:
  receipts: postgres
  siwx: redis

That would let x402 ship a first-class facilitator deployment path without baking all infrastructure choices into the core SDK APIs.

How the Four Workstreams Fit

OpenAPI-to-x402 Wrapper Generator

A CLI could ingest an OpenAPI spec and generate:

  • PayableOperation descriptors
  • x402 route config / middleware wiring
  • input canonicalization / validation hooks
  • starter docs for pricing and accepts arrays
  • optional proxy handlers to upstream APIs

This feels like a major adoption lever, especially for teams who already have OpenAPI and want "make this API payable" instead of "rewrite it around x402."

Self-Hosted Facilitator Starter Kit

A first-class starter kit could package:

  • Docker / compose deployment
  • bearer auth
  • health endpoints
  • metrics
  • structured logs
  • rate limits
  • multi-network config
  • persistent receipt / SIWX storage adapters

This feels adjacent to #1908 and to the general move from demos toward deployable infrastructure.

Persistent SIWX Payment History + Proofs

This becomes much cleaner if it sits on top of AccessGrantProof instead of ad hoc storage.

Short-term, this could start with:

  • Redis backend
  • Postgres backend
  • signed proof payload format

Longer-term it could expand into portable or on-chain-verifiable proofs.

Operation-Bound Receipts

This is the most protocol-important of the four.

It creates a cryptographic link between:

  • what was validated
  • what was paid for
  • what was settled

That seems like the right primitive if x402 wants to support more irreversible / parameterized / agentic operations safely.

Suggested Phasing

Phase 1: spec + interfaces

  • define operationDigest and OperationBoundReceipt
  • define a persistent SIWX storage/proof model
  • decide what belongs in core vs extension vs examples

Phase 2: tooling

  • ship an OpenAPI wrapper generator (likely TypeScript-first)
  • generate PayableOperation descriptors and proxy scaffolds

Phase 3: deployment

  • ship a self-hosted facilitator starter kit around a standard runtime profile
  • include Docker, metrics, auth, health, rate limits, and persistent stores

Questions for Maintainers

  1. Does this feel like the right shared architecture for these four ideas, or are they better kept separate?
  2. Should operationDigest / operation-bound receipts live in core spec, an extension, or example-level guidance first?
  3. Should persistent SIWX proofs be treated as a natural evolution of SIWX, or should SIWX remain intentionally server-local?
  4. Would an OpenAPI wrapper generator be welcome if it started as TypeScript-only tooling outside the core protocol surface?
  5. Would a facilitator starter kit be better inside this repo, or as a separate maintained template/reference deployment?

If this direction seems aligned, I'd be happy to break it into smaller follow-up proposals or implementation slices.

Would especially value feedback from @CarsonRoscoe, @murrlincoln, and @Bortlesboat on whether this belongs in core, extensions, or external tooling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions