Developer Documentation

OpenAI-compatible protocol · streaming · per-token & per-call billing · Claude native protocol supported

Quick start · signup to first token in 5 minutes

Change one line of base_url — existing AI apps work with zero rewrites

15 min

Register

Business email / phone number, auto-approved within 5 minutes.

21 min

Create an app

Pick models, set quotas, get your API Key in one click.

30 min

Swap base_url

Point your SDK at TuneRouter and go live instantly.

quickstart.py — Python / OpenAI SDK
from openai import OpenAI

client = OpenAI(
    api_key="sk-tr-your-token",
    base_url="https://api.tunerouter.com/v1"  # the only line you change
)

resp = client.chat.completions.create(
    model="auto",  # TuneRouter picks the best model; or pin one like glm-5.3 / claude-opus-4-8
    messages=[{"role": "user", "content": "Hello!"}]
)
print(resp.choices[0].message.content)
Cursor Dify LangChain OpenAI SDK Anthropic SDK ChatGPT-Next-Web
Private intranet deployment and dedicated gateway addresses available for finance, government and other compliance-driven scenarios

API Reference

Everything you need to integrate, debug and go to production

01API basics
Base URLhttps://api.tunerouter.com/v1
AuthenticationAuthorization: Bearer sk-tr-your-token
EndpointsPOST /v1/chat/completions · POST /v1/messages (Claude native) · POST /v1/images/generations · GET /v1/models
StreamingSupported — set "stream": true (SSE passthrough)
02cURL
chat.sh — streaming request
curl https://api.tunerouter.com/v1/chat/completions \
  -H "Authorization: Bearer sk-tr-your-token" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "glm-5.3",
    "stream": true,
    "messages": [{"role": "user", "content": "Hello, introduce yourself"}]
  }'
03Python (OpenAI SDK)
chat.py
from openai import OpenAI

client = OpenAI(
    api_key="sk-tr-your-token",
    base_url="https://api.tunerouter.com/v1"
)

resp = client.chat.completions.create(
    model="glm-5.3",
    messages=[{"role": "user", "content": "1+1=?"}]
)
print(resp.choices[0].message.content)
04Claude native (Anthropic SDK)

The official Anthropic SDK connects directly — no OpenAI conversion layer. Streaming and cache-aware billing supported. Note the base URL carries no /v1 suffix; the SDK appends it.

claude.py
from anthropic import Anthropic

client = Anthropic(
    api_key="sk-tr-your-token",
    base_url="https://api.tunerouter.com"
)

msg = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}]
)
print(msg.content[0].text)
05Image generation

Per-call billed image models (glm-image / seedream / wan-image and more) go through /v1/images/generations.

image.sh
curl https://api.tunerouter.com/v1/images/generations \
  -H "Authorization: Bearer sk-tr-your-token" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "glm-image",
    "prompt": "An orange cat wearing glasses, cartoon style"
  }'
06Billing rules
07Error codes
HTTPMeaning
401Token invalid or disabled
402Insufficient balance (pre-deduction check failed)
404Model not found or no available channel
4xxUpstream parameter error, passed through as-is (not billed)
502All channels failed (pre-deducted fee refunded)

FAQ

Common questions on billing, private deployment and new models

What does model="auto" mean?

In auto mode, TuneRouter matches the best model per request by cost, latency and capability, and intelligently tunes call parameters. You can also explicitly pin a model (e.g. glm-5.3, claude-opus-4-8) in the request.

How is billing settled? Is there a minimum spend?

Pay-as-you-go: metered by model input / output tokens, all models uniformly at ~15% off official list price; consolidated monthly bills, no minimum spend, no hidden fees, monthly or quarterly settlement, volume negotiable with tiered rebates. Failed requests are never billed — see the error-code table above.

Is private deployment supported?

Yes. TuneRouter supports private intranet deployment and dedicated gateway addresses, with multi-tenant isolation, tiered API Keys and full audit logs — meeting the compliance needs of finance, government and similar scenarios.

How fast are new models available? What if a provider fails?

New releases from DeepSeek, Qwen, Claude, GPT and other major vendors are callable the day they launch, guaranteed within 72 hours. If a provider times out or errors, requests automatically retry on the next best model — business stays unaffected, no manual firefighting.

Ready to integrate?

Contact account manager → tenant provisioning → get API Key → go live

Contact Our Team
mail@TuneRouter.com