Bittensor Integration
Build pay-per-inference services for decentralized AI using x402 micropayments and the Bittensor network.
What is Bittensor?
Bittensor is a decentralized network where AI models compete for TAO token rewards based on the quality of their outputs. With 64+ active subnets processing everything from language models to image generation, it's become the infrastructure layer for permissionless AI.
The x402 SDK provides templates for building payment proxies that wrap Bittensor subnet APIs, allowing you to accept USDC payments instead of requiring users to hold TAO.
Chutes (Subnet 64)
Chutes is one of Bittensor's largest subnets, processing over 160 billion tokens daily. It provides OpenAI-compatible API access to models including DeepSeek-V3, Llama, Qwen, and more.
Why Chutes + x402?
- No TAO required - Users pay with USDC on Base instead of needing Bittensor tokens
- No subscriptions - True pay-per-request micropayments
- Decentralized AI - Access Bittensor's distributed inference network
- Your margin - Set your own pricing above Chutes' cost
- Standard API - OpenAI-compatible endpoints work with existing integrations
Quick Start
TypeScript
npx @primersystems/x402 create chutes-proxy my-ai-proxy
cd my-ai-proxy
npm install
cp .env.example .env
# Edit .env with your Chutes API key and wallet address
npm run dev
Python
pip install primer-x402
x402 create chutes-proxy my-ai-proxy
cd my-ai-proxy
pip install -r requirements.txt
cp .env.example .env
# Edit .env with your Chutes API key and wallet address
uvicorn main:app --reload
Configuration
The generated project requires these environment variables:
| Variable | Description |
|---|---|
CHUTES_API_KEY |
Your Chutes API key from chutes.ai |
WALLET_ADDRESS |
Your wallet address to receive USDC payments |
PRICE_PER_1K_TOKENS |
Price in USD per 1000 tokens (default: 0.001) |
FACILITATOR_URL |
x402 facilitator URL (default: Primer's facilitator) |
How It Works
- Client sends a chat completion request to your proxy
- Proxy estimates token count and calculates price
- If no payment header, returns
402 Payment Requiredwith price - Client signs USDC payment authorization (gasless)
- Client retries with
PAYMENT-SIGNATUREheader - Proxy verifies payment via x402 facilitator
- Proxy forwards request to Chutes API
- Returns AI response with payment receipt
Deployment
TypeScript (Cloudflare Workers)
The TypeScript template deploys to Cloudflare Workers for free:
wrangler login
wrangler secret put CHUTES_API_KEY
wrangler secret put WALLET_ADDRESS
npm run deploy
Python (Docker)
The Python template includes a Dockerfile:
docker build -t chutes-x402-proxy .
docker run -p 8000:8000 --env-file .env chutes-x402-proxy
API Reference
POST /v1/chat/completions
OpenAI-compatible chat completions endpoint. Requires x402 payment.
curl -X POST https://your-proxy.example.com/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "Hello"}]}'
# Returns 402 with payment requirements
# Use x402 SDK to handle payment automatically
GET /v1/models
List available models (pass-through to Chutes). No payment required.
Use Cases
- AI agent operators - Give agents access to decentralized AI without managing API keys
- API resellers - Wrap Chutes with your own pricing and branding
- Privacy-focused services - Offer AI access without accounts or KYC
Coming Soon
Chutes is the first of several planned Bittensor integrations:
- SN58 (Handshake) - Micropayments subnet
- Other inference subnets - Image generation, embeddings, specialized models
- Direct TAO payment support
Resources
- Bittensor - The decentralized AI network
- Chutes - Subnet 64 for AI inference
- TAO Stats - Bittensor network statistics
- x402 SDK on GitHub