Your First Request
Walk through a complete request lifecycle step by step.
Step 1: Check API Health (Free)
python
import httpx
response = httpx.get("https://api.foursec.xyz/health")
print(response.json())Response:
json
{
"status": "healthy",
"version": "2.1.0",
"uptime_seconds": 86400,
"total_requests": 150000,
"supported_symbols": ["ETH", "BTC", "SOL", "ARB", "OP", "MATIC", "AVAX", "DOT", "LINK", "UNI"]
}Step 2: Get Available Endpoints (Free)
python
response = httpx.get("https://api.foursec.xyz/")
print(response.json())Response:
json
{
"name": "4SEC Market Data API",
"version": "2.1.0",
"endpoints": [
{"path": "/price/:symbol", "method": "GET", "price": "$0.01"},
{"path": "/price/history/:symbol", "method": "GET", "price": "$0.02"},
{"path": "/volume/:symbol", "method": "GET", "price": "$0.01"},
{"path": "/arbitrage-opportunity", "method": "GET", "price": "$0.03"},
{"path": "/volatility-index/:symbol", "method": "GET", "price": "$0.02"}
]
}Step 3: Make a Paid Request
python
from x402.client import X402Client
from eth_account import Account
wallet = Account.from_key("0x_your_key")
client = X402Client(wallet=wallet)
response = client.get("https://api.foursec.xyz/price/ETH")
print(f"Status: {response.status_code}")
print(response.json())The Payment Flow
Behind the scenes:
client.get("/price/ETH")— sends GET request- API responds: 402 Payment Required with payment details
- x402 client decodes: amount=0.01 USDC, network=Base
- Client signs USDC transfer (EIP-712 typed data)
- Client retries request with payment proof in headers
- API verifies payment on-chain
- API returns 200 + data
Cost Summary
| Request | Cost | Cumulative |
|---|---|---|
| GET /health | $0.00 | $0.00 |
| GET / | $0.00 | $0.00 |
| GET /price/ETH | $0.01 | $0.01 |
| GET /price/ETH (within 30s) | $0.00 | $0.01 |
| Total | $0.01 |
Next Steps
- API Reference — All endpoints
- Python SDK — Advanced patterns
- Payment Flow — Deep dive