Intelligent Routing

How Xantly analyzes each request across 15 parameters and selects the optimal model from 10,000+ options with 99.999% routing reliability.

Xantly's routing engine automatically selects the optimal model for each request based on task complexity, latency requirements, cost constraints, and historical performance. No configuration required, but full control when you want it.


Why routing matters

LLMs vary dramatically in cost, speed, and capability:

Speed TierValue TierQuality Tier
Latency100-300ms300-800ms800-3000ms
Cost$0.10-0.50/M tokens$0.50-3.00/M tokens.00-15.00/M tokens
Best forSimple queries, chat, classificationCode, summarization, extractionComplex reasoning, analysis

Sending every request to GPT-4o wastes money on simple tasks. Sending everything to a cheap model degrades quality on hard ones. Intelligent routing solves this by matching each request to the right tier automatically.


How auto-routing works

When you send model: "auto", the gateway runs a three-step process:

Step 1: Task analysis

The request is classified by type and complexity:

This classification happens in under 2ms and never adds perceptible latency.

Step 2: Model selection

A machine learning model evaluates the classified request against the available model pool. It considers:

The selection model improves continuously, it learns from every request which model performs best for which task type and tenant workload.

Step 3: Execution with fallback

The selected model receives the request. If the primary provider fails or times out, the gateway automatically falls back to the next best option. This waterfall mechanism ensures high availability without any client-side retry logic.

Request → Primary model → ✓ Response
                        → ✗ Timeout → Fallback model → ✓ Response
                                                      → ✗ Error → Second fallback → Response

Routing tiers

Every model in the catalog is assigned to a tier:

Speed tier

Fast, cost-efficient models for straightforward tasks. Typical latency: 100-300ms.

Value tier

Balanced models that handle most production workloads. Typical latency: 300-800ms.

Quality tier

Frontier models for the hardest tasks. Typical latency: 800-3000ms.


Controlling routing

Auto-routing works out of the box, but you can influence or override it.

Presets (simplest)

{
  "model": "auto",
  "routing_hints": { "mode": "cost_optimized" }
}
ModeEffect
fastBias toward speed tier
balancedLet the engine decide (default)
qualityBias toward quality tier
cost_optimizedMinimize cost aggressively

Fine-grained hints

{
  "model": "auto",
  "routing_hints": {
    "preference_dial": 0.2,
    "max_latency_ms": 500,
    "task_complexity": "standard"
  }
}

Direct model selection

Skip routing entirely by specifying a model:

{
  "model": "openai/gpt-4o",
  "messages": [...]
}

This bypasses the routing engine and sends directly to the specified model.


Continuous learning

The routing engine improves with every request:

  1. Each response generates a feedback signal: latency, cost, success/failure, and quality indicators
  2. The model selection algorithm updates online: no batch retraining, no downtime
  3. Per-tenant adaptation: the system learns your specific workload patterns
  4. Drift detection: if a model's performance changes, the router adapts automatically

After processing a few hundred requests, the routing engine is typically 30-50% more cost-efficient than static model selection, while maintaining equivalent or better output quality.


Workflow routing for agent loops

Most LLM gateways route every API call in isolation. Agent frameworks like Claude Code, deepagents, and Cline fire dozens of related calls for a single user task, and routing each one without context wastes money and produces inconsistent quality.

Xantly's routing engine supports workflow-level routing: tell the gateway which calls belong to one agent task, and it will route them as a coordinated unit.

How it works

Add three optional headers to mark a call as part of a workflow:

x-xantly-agent-framework: deepagents          # any string identifier
x-xantly-agent-session:   sess-abc-123        # client-generated, stable across calls
x-xantly-workflow-budget-usd: 1.00            # optional per-workflow budget

You can also signal the workflow phase explicitly so the router biases tier selection accordingly:

x-xantly-workflow-phase: exploration          # cheap exploration calls
x-xantly-workflow-phase: refinement           # mid-workflow refinement
x-xantly-workflow-phase: synthesis            # final answer / synthesis turn
x-xantly-workflow-end: true                   # finalize after this call

When the gateway sees these headers, it:

Why this matters

A typical agent task (50+ calls, $0.40 budget) routed call-by-call wastes 30-40% on overspecified models for cheap exploration steps. Workflow routing flips this: cheap-fast for the legwork, frontier-quality for the synthesis. Equal or better task completion at 60-70% of the cost.

No SDK changes required, just three HTTP headers from your agent framework.


Self-improving model selection

The routing engine continuously updates an internal capability matrix that estimates each model's strengths across multiple dimensions, reasoning, coding, tool use, structured output, knowledge, and others. The matrix refreshes weekly from public benchmark scores plus operator-curated data, and updates instantly when new models land in your catalog.

What this means in practice:

You don't configure any of this, it happens in the background. The dashboard surfaces what the router learned about your traffic if you want to inspect it.


Decision audit and observability

Every routing decision generates a structured audit record visible in the dashboard:

For Pro and Enterprise plans, the Mission Control → Routing Intelligence dashboard surfaces this end-to-end:

Enterprise auditors can trace any individual call from request → decision → score breakdown → outcome without leaving the dashboard.


Response headers

Every response includes routing metadata:

HeaderDescription
x-xantly-tier-usedT1 (quality), T2 (value), or T3 (speed)
x-xantly-lane-usedturbo or smart
x-xantly-providerWhich provider served the request
x-xantly-modelExact model identifier
x-xantly-cost-usdCost of this specific request
x-xantly-latency-msEnd-to-end latency

Use these headers to monitor routing decisions and tune your hints.


What's next


Frequently Asked Questions

How does intelligent routing work?

When you send model: "auto", the routing engine analyzes 15 request parameters, including task type, complexity, message length, conversation depth, schema requirements, tool definitions, and required capabilities, classifies the request in under 2ms, and selects the optimal model from the available pool based on task-model fit, latency budget, cost efficiency, memory context, and real-time provider health.

What routing modes are available?

Xantly offers six routing modes: auto (the engine decides based on request analysis), fast (biases toward speed-tier models with 100-300ms latency), balanced (default, lets the engine weigh all factors), quality (biases toward frontier models for complex reasoning), cost_optimized (minimizes cost aggressively), and free_models_only (routes exclusively to zero-cost open-weight models). You can also fine-tune with a preference_dial (0.0-1.0) for continuous control between cost and quality.

Can I force a specific model?

Yes. Set the model field to any provider/model identifier (e.g., openai/gpt-4o or anthropic/claude-3.5-sonnet) and the request bypasses the routing engine entirely, going directly to that specific model. You can also use routing_override.model for hard overrides while keeping other routing features like failover and caching active.

How reliable is the routing?

Xantly's routing engine achieves 99.999% routing reliability through waterfall fallback with 36+ API keys, automatic circuit breakers that proactively route around degraded providers, and multi-key rotation that handles billing exhaustion without request failures. If the primary model fails or times out, the gateway automatically falls back to the next best option, ensuring high availability with zero client-side retry logic.

How do I route an agent workflow as a unit instead of one call at a time?

Add the x-xantly-agent-framework, x-xantly-agent-session, and (optionally) x-xantly-workflow-budget-usd headers from your agent framework. The gateway tracks per-workflow state, call count, cumulative cost, phase signal, keyed by (tenant + framework + session), biases tier selection based on workflow phase (exploration/refinement/synthesis), and issues retroactive credit at workflow end so cheap exploration calls that lead to successful synthesis turns get rewarded. Typical agent workloads see 30-40% cost reduction at equal or better task completion. No SDK changes, just three HTTP headers.

Can I see why a specific request was routed where it was?

Yes. The Mission Control → Routing Intelligence dashboard (Pro and Enterprise plans) shows every routing decision with a per-term score breakdown, capability match, cost penalty, latency penalty, reliability, policy compliance, plus the alternatives the router considered, the models it filtered out (and why), and the capability matrix version active at decision time. Every call is auditable end-to-end without leaving the dashboard.

Does the routing engine adapt to my specific workload?

Yes, automatically. The selection algorithm updates online with every response, no batch retraining, no downtime. A tenant whose traffic is 90% code generation learns within roughly 50 requests to prefer code-tuned models for code calls. The internal capability matrix refreshes weekly to incorporate new public benchmark scores and any updates to your model catalog. If a model silently degrades (a provider pushes a bad update), the router notices via online performance monitoring and routes away from it within ~20 observations.