360 Secure SkillHub
360 安全技能中心

Bittensor Chutes x402

指导用户用 x402 CLI 脚手架生成 Node.js 或 Python 代理服务,按次收取 USDC 并转发请求到 Chutes/Bittensor 推理网络,包含环境变量配置、部署到 Cloudflare Workers 或 Docker 的步骤,以及流式与计费方面的限制说明。

primer-dev
primer-dev
热度 36.08
最近更新 2026-05-11 17:36:07
分类:开发依赖:代码执行 / 第三方 API应用场景:API 集成 / 代码生成 / DevOps

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add chutes-x402
Metadata
name
primer-chutes
description
Build a pay-per-inference proxy for Bittensor Chutes AI. Accept USDC payments for decentralized AI inference using x402.
metadata
{"openclaw":{"emoji":"🧠","requires":{"anyBins":["node","npx","python3","pip"]}}}

Chutes AI Proxy (x402)

Build a pay-per-inference proxy for Bittensor Chutes (Subnet 64). Accept USDC payments on Base and forward requests to Chutes' decentralized AI network.

When to Use This Skill

Use this skill when the user wants to:

  • Build an AI inference API that accepts crypto payments
  • Wrap Chutes/Bittensor with their own pricing
  • Create a pay-per-request AI service without subscriptions
  • Monetize AI access using stablecoins
  • Set up a Bittensor-powered AI endpoint

How to Respond

User Says/Asks What to Do
"Create a Chutes proxy" Run x402 create chutes-proxy my-proxy
"I want to sell AI inference" Scaffold the proxy, explain the business model
"How do I accept payments for AI?" Explain x402 + Chutes, offer to scaffold
"Set up Bittensor integration" Run the create command
"What models does Chutes support?" List models (DeepSeek, Llama, Qwen, etc.)

Quick Start

Node.js / 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

How It Works

User Request
     |
     v
[Your Proxy] -- No payment? --> Return 402 + price
     |
     v
User signs USDC payment (gasless)
     |
     v
[Your Proxy] -- Verify payment --> [Primer Facilitator]
     |
     v
[Chutes API] -- Forward request --> Bittensor Subnet 64
     |
     v
AI Response returned to user

You pre-pay Chutes with your API credits. Users pay YOU in USDC. You keep the margin.

Configuration

After scaffolding, edit .env:

Variable Description Required
CHUTES_API_KEY Your Chutes API key from chutes.ai Yes
WALLET_ADDRESS Your wallet to receive USDC Yes
PRICE_PER_1K_TOKENS Your price in USD (default: 0.001) No
FACILITATOR_URL x402 facilitator (default: Primer's) No

Getting a Chutes API Key

  1. Go to chutes.ai
  2. Sign up / connect wallet
  3. Subscribe to a tier ($3/month base)
  4. Generate API key (starts with cpk_)

Deployment

Cloudflare Workers (TypeScript - Free)

wrangler login
wrangler secret put CHUTES_API_KEY
wrangler secret put WALLET_ADDRESS
npm run deploy

Docker (Python)

docker build -t chutes-proxy .
docker run -p 8000:8000 --env-file .env chutes-proxy

Other Platforms

  • fly.io: fly launch && fly secrets set CHUTES_API_KEY=xxx
  • Railway/Render: Connect repo, set env vars in dashboard
  • Vercel Edge: Build and deploy TypeScript version

API Endpoints

Your proxy exposes:

Endpoint Description Payment
GET / Health check Free
POST /v1/chat/completions Chat completions (OpenAI-compatible) Required
GET /v1/models List available models Free

Supported Models

Any model on Chutes, including:

  • deepseek-ai/DeepSeek-V3
  • Qwen/Qwen3-235B-A22B
  • meta-llama/Llama-3.1-70B-Instruct
  • meta-llama/Llama-3.1-8B-Instruct

See chutes.ai for the full list.

Pricing Strategy

The proxy estimates tokens and charges upfront:

Price = (estimated_tokens / 1000) * PRICE_PER_1K_TOKENS

Set PRICE_PER_1K_TOKENS higher than Chutes' cost to make margin. Example:

  • Chutes costs you ~$0.0005/1K tokens
  • You charge $0.001/1K tokens
  • You keep 50% margin

Limitations

  • Streaming not supported - Template doesn't handle stream: true
  • Token estimation is approximate - Uses ~4 chars/token heuristic
  • Pre-payment only - No post-inference reconciliation

Use Cases

Who Why
AI agent operators Give agents paid AI access without API keys
API resellers Wrap Chutes with your branding/pricing
Privacy services AI without accounts or KYC
Bittensor miners Add stablecoin revenue stream

Testing Your Proxy

# Should return 402 Payment Required
curl http://localhost:8787/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"Hello"}]}'

# Pay and get response (using x402 CLI)
npx @primersystems/x402 pay http://localhost:8787/v1/chat/completions \
  --max-amount 0.01 \
  --method POST \
  --body '{"messages":[{"role":"user","content":"Hello"}]}'

Links