DEV Community

Cover image for How to Use Bittensor Like OpenAI (3 Lines of Code)
Mr Hamlin
Mr Hamlin

Posted on

How to Use Bittensor Like OpenAI (3 Lines of Code)

Every OpenAI-compatible SDK works with Bittensor now. No wallet. No TAO. No subnet knowledge. Just one line:

const client = new OpenAI({
  baseURL: "https://gateway.spraay.app/bittensor/v1",
});
Enter fullscreen mode Exit fullscreen mode

That's it. You're on decentralized AI.

What this is

Spraay Inference is a drop-in replacement for OpenAI's API that routes to Bittensor's decentralized AI network under the hood. Same /v1/chat/completions endpoint, same request format, same SDK support.

The difference: instead of hitting OpenAI's servers, your requests go to Subnet 64 (Chutes AI) — a decentralized network of GPU miners competing to serve the best inference. Every response is TEE-verified (Trusted Execution Environment), meaning you get cryptographic proof the model actually ran your prompt.

43+ models available today, including:

  • DeepSeek V3.2, DeepSeek R1 (reasoning)
  • Qwen3 32B, Qwen3 235B
  • GPT-OSS 120B (OpenAI's open-source model)
  • Mistral Small 3.1
  • And many more

Why switch from OpenAI?

Cost. Bittensor inference runs 40-85% cheaper than centralized providers because miners compete on price. A typical DeepSeek V3 call costs ~$0.25/M input tokens vs OpenAI's $2.50/M for GPT-4o.

Openness. Every model on Bittensor is open-source. No black boxes.

Permissionless. No one can revoke your access, change your pricing overnight, or censor your outputs.

Verifiable. TEE verification means you can prove the model ran exactly as specified — important for agent pipelines where trust matters.

Full example

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://gateway.spraay.app/bittensor/v1",
  apiKey: "not-needed", // x402 handles payment
});

const response = await client.chat.completions.create({
  model: "deepseek-ai/DeepSeek-V3-0324",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Explain how Bittensor's subnet architecture works." }
  ],
  max_tokens: 512,
  temperature: 0.7,
});

console.log(response.choices[0].message.content);
Enter fullscreen mode Exit fullscreen mode

Python works too:

from openai import OpenAI

client = OpenAI(
    base_url="https://gateway.spraay.app/bittensor/v1",
    api_key="not-needed",
)

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-R1-0528",
    messages=[{"role": "user", "content": "What is proof of intelligence?"}],
)

print(response.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

cURL:

curl -X POST https://gateway.spraay.app/bittensor/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Qwen/Qwen3-32B",
    "messages": [{"role": "user", "content": "Hello from Bittensor"}],
    "max_tokens": 256
  }'
Enter fullscreen mode Exit fullscreen mode

Available endpoints

The API follows OpenAI's specification exactly:

Endpoint Method Description
/bittensor/v1/models GET List all available models
/bittensor/v1/chat/completions POST Chat completions (streaming supported)
/bittensor/v1/images/generations POST Image generation
/bittensor/v1/embeddings POST Text embeddings
/bittensor/v1/health GET Health check

Streaming, function calling, structured output, and tool use all work as expected.

How it works under the hood

Your app (OpenAI SDK)
    ↓ standard HTTP request
Spraay Gateway (gateway.spraay.app)
    ↓ x402 payment verification
    ↓ model → provider routing
Bittensor Subnet 64 (Chutes AI)
    ↓ distributed across GPU miners
    ↓ TEE-verified execution
Response back to your app
Enter fullscreen mode Exit fullscreen mode

The Spraay x402 Gateway handles payment via the x402 protocol — HTTP-native micropayments in USDC on Base. Agents can consume inference autonomously without API keys or accounts. This is designed for the agentic future where software pays for its own compute.

For AI agent developers

If you're building autonomous agents with LangChain, CrewAI, AutoGPT, or any framework that uses OpenAI-compatible endpoints, Spraay Inference is the simplest way to put your agents on decentralized AI:

# LangChain example
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    base_url="https://gateway.spraay.app/bittensor/v1",
    model="deepseek-ai/DeepSeek-V3.2",
    api_key="not-needed",
)

response = llm.invoke("Analyze the top Bittensor subnets by revenue")
Enter fullscreen mode Exit fullscreen mode

The x402 payment model means your agent doesn't need a credit card, an account, or even a human in the loop. It pays per-request in USDC and gets inference back. That's the unlock for truly autonomous AI agents.

Try it now

Live playground (no setup needed): spraay.app/bittensor

Gateway endpoint: gateway.spraay.app/bittensor/v1

Spraay Protocol: spraay.app | Gateway docs


Spraay Inference is part of the Spraay x402 Gateway — 88+ pay-per-call API endpoints for AI, payments, DeFi, and infrastructure on Base. Built for agents.

$TAO 💧

Top comments (0)