API Reference¶
WasiAI provides REST APIs for inference, model management, and IPFS operations.
Base URL¶
Authentication¶
Wallet Authentication¶
Most write operations require a connected wallet. The frontend handles authentication via wagmi/RainbowKit.
x402 Payment¶
Inference endpoints require payment via the x402 protocol. See x402 Protocol for details.
Endpoints Overview¶
| Endpoint | Method | Description |
|---|---|---|
/api/inference/{modelId} | POST | Run AI inference (x402) |
/api/models | GET | List all models |
/api/models/{id} | GET | Get model details |
/api/models/publish | POST | Publish a new model |
/api/indexed/models | GET | Get cached model list |
/api/ipfs/upload | POST | Upload file to IPFS |
/api/ipfs/metadata | POST | Upload JSON metadata |
Quick Reference¶
Run Inference¶
# Step 1: Get payment requirements
curl -X POST https://wasiai.io/api/inference/1 \
-H "Content-Type: application/json" \
-d '{"input": "Analyze this text"}'
# Response: HTTP 402
{
"x402Version": 1,
"accepts": [{
"scheme": "exact",
"network": "avalanche-fuji",
"maxAmountRequired": "10000",
"payTo": "0x...",
"asset": "0x5425890298aed601595a70AB815c96711a31Bc65"
}]
}
# Step 2: Sign payment and retry with X-PAYMENT header
curl -X POST https://wasiai.io/api/inference/1 \
-H "Content-Type: application/json" \
-H "X-PAYMENT: <base64-encoded-payment>" \
-d '{"input": "Analyze this text"}'
# Response: HTTP 200
{
"ok": true,
"result": { ... },
"payment": {
"txHash": "0x...",
"verified": true
}
}
Get Models¶
curl https://wasiai.io/api/indexed/models
# Response
{
"models": [
{
"modelId": 1,
"name": "Crypto Sentiment Analyzer",
"category": "sentiment-analysis",
"priceInference": "10000"
}
]
}
Detailed Documentation¶
- Inference API: Pay-per-inference endpoint
- Models API: Model CRUD operations
- IPFS API: File upload and retrieval
Error Handling¶
Standard Error Response¶
Common Error Codes¶
| Code | HTTP Status | Description |
|---|---|---|
model_not_found | 404 | Model ID doesn't exist |
rate_limited | 429 | Too many requests |
payment_required | 402 | x402 payment needed |
payment_failed | 402 | Payment verification failed |
unauthorized | 401 | Authentication required |
validation_error | 400 | Invalid request data |
Rate Limiting¶
| Endpoint | Limit | Window |
|---|---|---|
/api/inference/* | 10 requests | 1 minute |
/api/models/* | 30 requests | 1 minute |
/api/ipfs/* | 10 requests | 1 minute |
Rate limit headers: