Auto-Switch (complexity routing)

Auto-Switch is the routing engine — the reason Coco Router exists.

How a request flows

app request (model: anything)
   │
   ├─ non-chat endpoint (audio/embeddings)? → pass through unchanged
   ├─ auto key, or model is auto/smart-ai/default?
   │        │ no → pass through unchanged
   │        ▼ yes
   │  classifier (gpt-4o-mini) reads the prompt → SIMPLE | MEDIUM | COMPLEX | REASONING
   │        ▼
   │  tier's model pool: try model #1 → on error/429 fall back to #2 → #3 …
   │        ▼
   └─ response, with ai_router: {tier, model} injected in the body
      and x-ai-router-tier / x-ai-router-model response headers

The tiers and current defaults

TierFires forDefault model pool (first = primary)
SIMPLEgreetings, basic facts, trivial Q&Allama-3.3-70b-instruct:freellama-3.1-8b-instructgemini-2.5-flash-lite
MEDIUMeveryday writing, summaries, simple codegemini-2.5-flashdeepseek-chat
COMPLEXnon-trivial coding, SQL, system designclaude-sonnet-4gpt-4o
REASONINGmath/proofs, multi-step logic, planningdeepseek-r1o3-mini

(All via OpenRouter model ids; the pools are fully editable in the Control Panel.)

Multi-model fallback

Each tier holds a priority list. The router requests the first model; if it fails or rate-limits (free models frequently 429), it fails fast — no retries on the same model — and falls to the next in the list. A typical fallback completes in ~3 seconds. This is what makes "free model first, cheap paid model as backup" a safe production pattern.

The classifier

  • Default judge: gpt-4o-mini (configurable in the Control Panel).
  • Cost ≈ $0.00002 per classification; latency ≈ 200–400 ms.
  • The judge sees only the latest user message (truncated to 4,000 chars).
  • If classification fails for any reason, the request defaults to the MEDIUM tier — requests never fail because of the judge.

Reading routing decisions

Every routed response carries the decision in two places:

  • Response body — an ai_router object: {"tier": "COMPLEX", "model": "openrouter/anthropic/claude-sonnet-4"}. The body's model field is also rewritten to the real backend model.
  • Response headersx-ai-router-tier and x-ai-router-model (server-to-server; browsers cannot read custom headers cross-origin, hence the body field).

Cost impact

Routing means a trivial question costs fractions of a cent on Llama-8B (~$0.000002/request) instead of frontier-model prices, while hard tasks still get Claude-class quality. Typical blended savings versus sending everything to a frontier model: 40–80%, depending on traffic mix.