Skip to main content

Crate x402_gateway

Crate x402_gateway 

Source
Expand description

§tempo-x402-gateway

API gateway that adds x402 payment rails to any HTTP endpoint.

Register upstream APIs with a price, and clients pay per-request through the gateway at /g/{slug}/{path}. Payments are verified and settled on-chain before the request is proxied.

§Features

  • Endpoint registration with atomic slug reservation (BEGIN IMMEDIATE)
  • Embedded facilitator — runs in-process when FACILITATOR_PRIVATE_KEY is set
  • Proxy with SSRF protection — HTTPS-only targets, private IP blocking, DNS validation
  • Per-endpoint analytics — request counts, payment counts, revenue tracking
  • Prometheus metricsENDPOINT_PAYMENTS and ENDPOINT_REVENUE with slug labels
  • Pre-flight reachability check before payment settlement (don’t charge for dead targets)
  • Extensible database — downstream crates (x402-node) add tables via execute_schema()

§Modules

  • config — Gateway configuration (config::GatewayConfig)
  • db — SQLite database with extensible schema
  • middleware — Payment processing, header encoding, 402 response construction
  • proxy — HTTP proxy with header stripping and SSRF protection
  • routes — Endpoint registration, gateway proxy, analytics, health
  • state — Shared application state
  • validation — URL and SSRF validation
  • metrics — Prometheus metrics
  • facilitator — Embedded facilitator bootstrap

Part of the tempo-x402 workspace.

Re-exports§

pub use config::GatewayConfig;
pub use db::Database;
pub use error::GatewayError;
pub use state::AppState;

Modules§

config
cors
CORS configuration for the gateway and node binaries.
db
error
facilitator
Embedded facilitator: payment verification and on-chain settlement.
metrics
middleware
proxy
routes
state
validation