API Reference
Bhairab is an OpenAI-compatible API for Bittensor's decentralized AI network. If you've used the OpenAI API, you already know how to use this — change one line (the base URL) and your existing code works.
Quickstart
Get a free API key (100k tokens included, no card required), then make your first call. Use model: "auto" to let the router pick the most cost-efficient model per prompt.
from openai import OpenAI
client = OpenAI(
api_key="sk_live_...",
base_url="https://tao-gateway.fly.dev/v1", # only change from OpenAI
)
resp = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)Authentication
Pass your API key as a Bearer token. Keys start with sk_live_. Manage and revoke keys from your dashboard.
Authorization: Bearer sk_live_your_key_here
Chat completions
POST /v1/chat/completions — accepts and returns the standard OpenAI chat-completions shape.
curl https://tao-gateway.fly.dev/v1/chat/completions \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"messages": [
{"role": "system", "content": "You are concise."},
{"role": "user", "content": "What is Bittensor?"}
]
}'Response (OpenAI-compatible):
{
"id": "chatcmpl-...",
"object": "chat.completion",
"model": "deepseek-ai/DeepSeek-V3.2-TEE", // the model that served it
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "Bittensor is..." },
"finish_reason": "stop"
}],
"usage": { "prompt_tokens": 18, "completion_tokens": 92, "total_tokens": 110 }
}Streaming
Set stream: true to receive tokens as Server-Sent Events, exactly like OpenAI. The stream ends with data: [DONE].
stream = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "Write a haiku"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)Models & routing
Pass model: "auto" and the router classifies each prompt and sends it to the cheapest capable model. Or pin a specific model. OpenAI model names are accepted and mapped to equivalents.
| model value | Routes to | Best for |
|---|---|---|
| auto | router picks per prompt | Recommended default |
| gpt-4o / gpt-4 | DeepSeek V3.2 | Complex reasoning, code |
| gpt-4o-mini | Gemma 4 31B Turbo | General chat, fast |
| gpt-3.5-turbo | Mistral Nemo | Simple, cheapest |
| deepseek / gemma / mistral | that model directly | Pin a specific model |
| qwen-coder | Qwen2.5 Coder 32B | Code generation |
Inference runs on Bittensor SN64 (Chutes). If the decentralized network is at capacity, requests transparently fail over to a centralized backstop so your app never sees an outage — the X-Routed-Subnet header tells you exactly where each request ran.
Response headers
| X-Routed-Subnet | Which model/provider served the request, e.g. SN64-Chutes/...-TEE or groq-backstop |
| X-RateLimit-Remaining | Requests left in the current minute window |
| X-Latency-Ms | Gateway-measured latency for the request |
Errors
Standard HTTP status codes. Error bodies are JSON with an error field.
| Code | Meaning |
|---|---|
| 401 | Invalid or missing API key |
| 402 | Insufficient balance — top up in the dashboard |
| 429 | Rate limit exceeded — see Retry-After header |
| 502 | All providers at capacity — retry in a moment |
Rate limits & billing
- ◆Free tier: 100k tokens to start, no card required.
- ◆Rate limit: 60 requests/minute by default. X-RateLimit-Remaining tracks your window.
- ◆Pricing: $0.50 / 1M input tokens, $1.50 / 1M output tokens — billed against your prepaid balance. ~10× cheaper than OpenAI GPT-4o.
- ◆Top up: credit packs via Stripe from your dashboard.