Hosted API
Don't want to install the SDK? Use InferShrink as a hosted API. Pay per call with USDC on Base chain — no API key, no account, no signup.
For AI agents: The hosted API uses x402 — an open protocol for machine-to-machine payments. Your agent hits the endpoint, gets a 402 response with payment instructions, pays on-chain, and gets access. Fully autonomous.
Base URL
https://musashi-runtime.musashi-labs.workers.dev
Endpoints
| Endpoint | Method | Price | Description |
|---|---|---|---|
/classify |
POST | $0.001 | Classify prompt complexity — Coming soon |
/route |
POST | $0.001 | Get optimal model routing — Coming soon |
/subscribe |
POST | $1.01 | Buy 1,000 credits (7-day expiry) |
/health |
GET | Free | Health check |
How x402 Payment Works
Every paid endpoint returns HTTP 402 Payment Required with a Payment-Required header containing a base64-encoded JSON object. Here's the flow:
1. Make a request
curl -X POST https://musashi-runtime.musashi-labs.workers.dev/classify \
-H "Content-Type: application/json" \
-d '{"prompt": "What is 2+2?"}'
2. Get the 402 response
HTTP/2 402
Payment-Required: eyJ4NDAyVmVyc2lvbi... (base64)
{
"error": "Payment required",
"price": "$0.001 USDC",
"network": "eip155:8453",
"description": "InferShrink: Classify prompt complexity"
}
3. Decode the payment instructions
Base64-decode the Payment-Required header to get:
{
"x402Version": 2,
"resource": {
"url": "https://musashi-runtime.musashi-labs.workers.dev/classify",
"description": "InferShrink: Classify prompt complexity",
"mimeType": "application/json"
},
"accepts": [{
"scheme": "exact",
"network": "eip155:8453",
"amount": "1000",
"payTo": "0xbdF05e6E011a7E032821a6026A9d47D10C8b9848",
"maxTimeoutSeconds": 300,
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"extra": { "name": "USD Coin", "version": "2" }
}]
}
4. Pay on Base chain
Send USDC to the payTo address on Base (chain ID 8453):
- Token: USDC (
0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913) - Network: Base (eip155:8453)
- Amount:
1000= $0.001 USDC (6 decimals) - Recipient:
0xbdF05e6E011a7E032821a6026A9d47D10C8b9848
5. Include payment proof
After the on-chain transaction confirms, re-send your original request with the transaction hash:
curl -X POST https://musashi-runtime.musashi-labs.workers.dev/classify \
-H "Content-Type: application/json" \
-H "X-Payment-Tx: 0xabc123..." \
-d '{"prompt": "What is 2+2?"}'
Bulk option: Use /subscribe to buy 1,000 credits for $1.01 USDC. Each subsequent call deducts 1 credit instead of requiring a new payment. Credits expire after 7 days.
Python Client
The SDK includes a hosted API client:
from infershrink.hosted import InferShrinkClient, PaymentRequired
client = InferShrinkClient()
try:
result = client.classify("What is 2+2?")
print(result) # {"complexity": "SIMPLE", ...}
except PaymentRequired as e:
print(e.details)
# {"price": "$0.001 USDC", "network": "eip155:8453", ...}
# Your agent can parse this and pay automatically
For Agent Developers
If you're building an AI agent that needs to classify prompt complexity or route models, the x402 flow is designed for you:
- Your agent calls
/classifyor/route - Gets 402 with structured payment instructions
- Agent's wallet signs a USDC transfer on Base
- Agent retries with tx proof — gets the classification result
- No API keys to manage, no accounts to create, no rate limits to hit
Prefer the SDK? If you're running Python, pip install infershrink gives you the same classification locally for free — no API calls, no payments. The hosted API is for agents and services that can't install Python packages.
API Reference
POST /classify
// Request
{"prompt": "What is 2+2?"}
// Response (after payment)
{
"complexity": "SIMPLE",
"reason": "short prompt, no complex keywords",
"signals": {
"estimated_tokens": 6,
"complex_keywords": [],
"code_blocks": 0
}
}
POST /route
// Request
{"model": "gpt-4o", "prompt": "What is 2+2?"}
// Response (after payment)
{
"original_model": "gpt-4o",
"routed_model": "gpt-4o-mini",
"was_downgraded": true,
"complexity": "SIMPLE",
"estimated_savings_pct": 95
}
POST /subscribe
// Request (empty body)
{}
// Response (after $1.01 USDC payment)
{
"credits": 1000,
"expires_at": "2026-03-10T17:00:00Z",
"token": "isk_abc123..."
}
// Use token in subsequent requests:
// -H "Authorization: Bearer isk_abc123..."