Skip to content

feat(python): add facilitator HTTP server#1908

Open
Bortlesboat wants to merge 1 commit intox402-foundation:mainfrom
Bortlesboat:feat/python-facilitator-http-server
Open

feat(python): add facilitator HTTP server#1908
Bortlesboat wants to merge 1 commit intox402-foundation:mainfrom
Bortlesboat:feat/python-facilitator-http-server

Conversation

@Bortlesboat
Copy link
Copy Markdown
Contributor

Summary

The Python SDK has x402Facilitator (logic) and HTTPFacilitatorClient (client), but no way to host a facilitator as an HTTP service. The Go SDK has this via go/http/server.go. This PR fills that gap.

Adds create_facilitator_app() — a factory function that wraps any x402Facilitator or x402FacilitatorSync instance in a FastAPI application exposing the standard facilitator endpoints:

  • GET /supported — capability discovery
  • POST /verify — payment verification
  • POST /settle — payment settlement
  • GET /health — liveness check

Design decisions

  • Backend-agnostic — wraps any registered mechanism (EVM, SVM, or future mechanisms), not tied to a specific chain
  • Async + sync — accepts both x402Facilitator (async) and x402FacilitatorSync (sync via thread pool)
  • V1/V2 routing — handles both protocol versions based on x402Version in the request body
  • Optional CORScors_origins parameter for cross-origin deployments
  • Reuses existing typesVerifyResponse, SettleResponse, SupportedResponse from x402.schemas
  • Lazy FastAPI import — only imported when create_facilitator_app() is called, so the module doesn't force the dependency

Usage

from x402 import x402Facilitator
from x402.http.facilitator_server import create_facilitator_app

facilitator = x402Facilitator()
facilitator.register(["eip155:8453"], some_scheme)

app = create_facilitator_app(facilitator)

# uvicorn app:app --host 0.0.0.0 --port 8402

Testing

20 unit tests covering:

  • All four endpoints (supported, verify, settle, health)
  • Valid and invalid payments
  • Missing/malformed request bodies
  • Unsupported scheme/network errors
  • Both async and sync facilitator variants
  • CORS configuration and absence
  • Response schema round-trip validation (server output parseable by VerifyResponse/SettleResponse/SupportedResponse)
20 passed in 0.54s

Add create_facilitator_app() factory that wraps x402Facilitator or
x402FacilitatorSync in a FastAPI application exposing the standard
/supported, /verify, /settle, and /health endpoints. This brings the
Python SDK to parity with the Go SDK's facilitator hosting capabilities.

Supports both async and sync facilitators (sync runs in thread pool),
optional CORS configuration, and V1/V2 protocol version routing.

Includes 20 unit tests covering all endpoints, error handling, CORS,
both facilitator variants, and response schema round-trip validation.
@cb-heimdall
Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 2026

@Bortlesboat is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added sdk Changes to core v2 packages python labels Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python sdk Changes to core v2 packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants