FastAPI Server Example¶
Example FastAPI server with X402 payment requirements.
Setup¶
-
Install dependencies:
-
Configure environment:
-
Run the server:
-
Visit http://localhost:8000/docs for API documentation
Testing¶
Get free data:¶
Try premium endpoint (will return 402):¶
With payment client:¶
See the langchain-agent example for how to make payments automatically.
Endpoints¶
GET /- API information (free)GET /free-data- Free data (no payment)GET /premium-data- Premium data (0.10 USDC)GET /expensive-data- Expensive AI data (1.00 USDC)GET /tiered-data/{tier}- Tiered access (0.05 USDC)