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.

Base URLhttps://tao-gateway.fly.dev/v1

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.

python
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
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):

json
{
  "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].

python
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 valueRoutes toBest for
autorouter picks per promptRecommended default
gpt-4o / gpt-4DeepSeek V3.2Complex reasoning, code
gpt-4o-miniGemma 4 31B TurboGeneral chat, fast
gpt-3.5-turboMistral NemoSimple, cheapest
deepseek / gemma / mistralthat model directlyPin a specific model
qwen-coderQwen2.5 Coder 32BCode 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-SubnetWhich model/provider served the request, e.g. SN64-Chutes/...-TEE or groq-backstop
X-RateLimit-RemainingRequests left in the current minute window
X-Latency-MsGateway-measured latency for the request

Errors

Standard HTTP status codes. Error bodies are JSON with an error field.

CodeMeaning
401Invalid or missing API key
402Insufficient balance — top up in the dashboard
429Rate limit exceeded — see Retry-After header
502All 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.
Questions? hello@bhairab.aiGet your API key →