Guides

AI Model Routing: The Middleware Layer Your Automation Pipeline Is Missing

A practical AI model routing automation pipeline pattern: match each subtask to the cheapest capable model using quality, speed, and cost heuristics.

· · 7 min read
Abstract ink-wash rendering of data routing paths on washi paper.
Abstract ink-wash rendering of data routing paths on washi paper. AI-generated illustration by Carlos Arias .

On July 23, 2026, Runway launched the Media Router — a system that automatically selects among Gen-4.5, Veo 3, GPT Image 2, and other generative media models based on a single input: whether the developer prioritizes quality, speed, or cost. Runway called this the first intelligent router built for generative media. The claim is accurate. What is less obvious is that the identical heuristic — the quality-speed-cost triangle — applies directly to AI model routing in automation pipelines built entirely from text-based LLMs.

If your multi-step automation sends every subtask to the same frontier model, you are solving a routing problem with a pricing strategy instead of an architecture decision.

What Runway’s Media Router Actually Shows

The practical insight in Runway’s announcement is not the product itself — it is the premise behind building it. Token pricing became a visible operational problem in 2026 as enterprises that expanded into agentic AI workflows began receiving token bills that scaled non-linearly with volume. The response from engineering teams was to treat model selection as a runtime decision rather than a deployment-time constant.

For video generation, “quality” means render fidelity and temporal coherence; “speed” means time-to-first-frame; “cost” maps to per-second generation pricing. For text agent pipelines, the variables translate directly: quality is reasoning accuracy on a given subtask, speed is latency for time-sensitive steps, and cost is tokens consumed across the full workflow.

The routing decision structure is identical. The implementation differs only in what the input signals look like.

The Hidden Cost of Hardcoding One Model in Your AI Model Routing Automation Pipeline

The default when building agent-based automation is to pick one model — usually whichever frontier model the team has been using — and apply it uniformly across every step in the workflow. This is a reasonable prototype decision. It is difficult to defend in production.

Consider a five-step document processing pipeline: ingest → classify → extract → summarize → route to downstream system. Each step has a different complexity profile:

  • Classify: binary or few-class intent detection. A small, fast model handles this reliably.
  • Extract: structured field extraction from a known schema. Moderate context required; frontier reasoning is rarely the bottleneck.
  • Summarize: length reduction with fidelity constraints. A mid-tier model performs well on standard documents.
  • Route: rule application against extracted data. This is conditional logic, not language understanding.

If a single frontier model handles all five steps, you are paying frontier prices at four of five steps where a cheaper model produces identical results. As of July 2026, 37% of enterprises use five or more models in production environments — a sign that multi-model architectures are becoming the norm. Teams that implement a tuned routing layer report bill reductions in the 40–85% range without a measurable drop in output quality.

A Task Taxonomy for Model Selection Per Task

The first step in building a routing layer is categorizing the subtasks in your pipeline by their actual complexity requirements. A practical three-tier taxonomy:

Tier 1 — Cheap and fast. Tasks with constrained output space, low ambiguity, or purely mechanical transformation: intent classification, binary routing decisions, format conversion, simple slot-filling from structured input. These rarely benefit from frontier-scale reasoning. Model examples (July 2026): Haiku 4.5, GPT-4o-mini.

Tier 2 — Mid-tier. Tasks that require contextual understanding but follow recognizable patterns: entity extraction over semi-structured text, document summarization, translation, code review against a known style guide, Q&A over a retrieved document. A capable but non-frontier model handles these reliably. Model examples (July 2026): Sonnet 5, Gemini Flash.

Tier 3 — Frontier. Tasks that require sustained multi-step reasoning, novel synthesis across many inputs, or high-stakes judgment with no recoverable fallback: agentic planning, contract analysis, multi-document synthesis, novel code generation, orchestration decisions in complex workflows. As explored in the Opus 5 pricing analysis, frontier models sit at a 2× cost differential from mid-tier — a gap that only makes sense to pay when the task genuinely requires frontier capability.

The models occupying each tier shift quarter by quarter. The taxonomy does not.

Three Approaches to Building the Routing Layer

Once you have a task taxonomy, the routing layer assigns an incoming subtask to a tier at runtime. Three approaches exist, each with a different cost-complexity tradeoff.

Rule-based routing adds under 1 ms of overhead. The dispatcher is a lookup table or conditional tree keyed on a task_type tag attached to each subtask at authoring time. The pipeline developer labels each step explicitly; the router reads the label and dispatches accordingly. Simple, deterministic, easy to audit. The limitation is brittleness: it requires that subtask types are known at design time and that labels are maintained as the pipeline evolves.

Embedding-based routing adds roughly 5 ms. The router encodes the task prompt into a vector and compares it to cluster centroids representing each tier. This handles unlabeled subtasks and degrades gracefully when new task types appear. It requires an embedding model — which can itself be a cheap Tier 1 call — and an initial calibration pass to define the cluster centroids.

ML classifier routing adds 50–100 ms. A fine-tuned classifier reads the full task context and predicts the appropriate tier. This is the right choice when task prompts vary widely and the cost of misrouting is high, but the latency overhead rules it out for time-sensitive paths. Latency figures as of mid-2026.

For most production pipelines, rule-based routing covers 80% of cases. Embedding-based routing handles the remainder. ML classifiers are worth evaluating only when the routing decision is itself a complex inference problem.

A Reference Routing Table

The following maps common automation subtask types to tiers and example models as of July 2026. Treat model assignments as perishable; treat tier assignments as stable.

Subtask typeTierExample models (July 2026)
Intent classification1Haiku 4.5, GPT-4o-mini
Binary routing decision1Haiku 4.5
Format conversion / normalization1Haiku 4.5
Entity extraction (structured schema)2Sonnet 5, Gemini Flash
Document summarization2Sonnet 5
Code review (style / convention)2Sonnet 5
Translation2Sonnet 5
Multi-document synthesis3Opus 5
Agentic planning3Opus 5
Novel code generation3Opus 5
Contract / legal analysis3Opus 5, Fable 5

One anti-pattern worth naming explicitly: the routing decision itself — determining which tier an incoming subtask belongs to — should always be a Tier 1 call. Spending Tier 3 tokens to decide where to spend Tier 1 tokens is a common mistake in early routing implementations.

What a Routing Layer Looks Like in Production

The router belongs in the pipeline as a first-class node, not as inline logic scattered across individual step definitions. In a LangGraph-based multi-agent pipeline, this maps naturally to a dedicated dispatch node that receives the task payload, reads the task_type label (or runs a Tier 1 classification call), and returns a model identifier that downstream nodes use to initialize their LLM client.

The operational requirements that make a router useful rather than ornamental:

Log every routing decision. Capture task_type, tier_assigned, model_used, and tokens_consumed on every call. This is your cost attribution data and the primary input for tuning the taxonomy over time. Without it, you have a router but no feedback loop.

Build escalation logic. If a Tier 1 model returns a malformed response or a low-confidence extraction, escalate to Tier 2 before returning to the caller. Define “low confidence” in measurable terms — a confidence score threshold, a schema validation failure, a missing required field — not as a judgment call inside the prompt.

Decouple model identifiers from routing logic. The router should reference a configuration object (TIER_1_MODEL, TIER_2_MODEL, TIER_3_MODEL) rather than hardcoded model strings. When Haiku 4.5 is superseded by a cheaper model with equivalent capability, a one-line config change propagates through the entire pipeline.

Set token budgets per tier. A Tier 1 classification call that consumes 2,000 output tokens is misrouted, not merely slow. Token budget violations surface routing errors as measurable anomalies rather than silent quality degradations.

OpenRouter currently indexes 623+ models under a single endpoint (as of July 2026), which simplifies the infrastructure side: one client, one authentication layer, routing decisions that stay in your application code rather than spread across multiple provider SDKs.

The Reusable Pattern

Model routing is infrastructure, not configuration. Runway built a dedicated routing layer for generative media because selecting the right model at runtime is architecturally distinct from calling any specific model. The same separation applies to text-based automation pipelines.

The reusable pattern is three components: a task taxonomy that maps subtask types to capability tiers, a dispatch function that reads a task’s type label and returns a model identifier, and a logging layer that turns every routing decision into tuning data. None of these components are specific to a framework, a model provider, or a particular pipeline architecture. All three are the same whether you are running five steps or fifty.

What varies by pipeline is which tasks land in which tier. What does not vary is that routing the wrong task to the wrong tier costs either money (over-routing to frontier) or quality (under-routing to cheap). The routing layer is the only place in the system where you can address both failure modes at once — and it is the component most automation pipelines are currently missing.

Share
Comments

Hook this up to your favourite commenting platform — Giscus, Disqus, or your own.

Continue reading

Stay in the loop.

One email when it’s worth it — new posts and updates, no spam.

Free. Unsubscribe in one click.