IX · Routing & CompositionEmerging

Provider-String Routing

also known as Provider/Model String, Unified Model Identifier, Single-String Model Selection

Select the model and provider for a request through a single namespaced string (`provider/model`) backed by env-var credentials, so the caller specifies what to run with one parameter rather than a typed provider object.

Context

A team is building an application that needs to talk to several language-model providers and many model variants — OpenAI, Anthropic, Google, xAI, OpenRouter, and others — possibly choosing between them on a per-request basis for cost lanes, experiments, or tenant-specific routing. The application is otherwise model-agnostic; it does not need to depend on the typed object hierarchy of any one provider's software development kit. The team controls the call sites where each model invocation happens.

Problem

When the call site is written as a typed provider object such as `OpenAI(...)` or `Anthropic(...)`, the provider becomes part of the application's source code and switching between them requires conditional construction at every call site. Per-request, per-tenant, or per-experiment routing across providers turns into a tangle of imports and adapter classes, and adding a new provider means another typed branch wherever models are invoked. The application ends up coupled to provider SDK shapes that have no business in its core logic.

Forces

  • A `provider/model` string is the cheapest possible call-site signature for cross-provider routing.
  • Env-var-driven credentials let the deployment pick keys without code changes.
  • Capability differences across providers (tool calls, structured output, vision, max-context) must still be discoverable at runtime.
  • Per-call provider selection lets experiments, A/B routing, and cost lanes share a single call site.
  • String-typed identifiers lose compile-time checking of valid combinations.

Example

A team builds an agent that should route easy tasks to a cheap small model, hard tasks to a frontier model, and a long-context task to a third provider entirely. With a typed provider object hierarchy, each lane needs its own client construction and credential plumbing. The team switches to provider-string routing: the agent receives a `model` string (`'openai/gpt-5-mini'`, `'anthropic/claude-opus-4-7'`, `'google/gemini-2.5-pro'`) and the registry handles credentials and capability discovery. Adding a new provider for one experiment is a string change plus an env-var.

Diagram

Solution

Therefore:

Define a unified language-model interface and a registry of providers keyed by short prefix (`openai/`, `anthropic/`, `google/`, `xai/`, `openrouter/...`). Each provider implementation knows how to read its credentials from environment variables. The call site takes a single string (`'anthropic/claude-sonnet-4-6'`) and the runtime resolves provider, credentials, and capability flags. Pair with provider-fallback (chain strings for resilience), multi-model-routing (pick a string by quality/cost), and vendor-lock-in (this is its mirror — the un-locked version).

What this pattern forbids. Application code is not allowed to import provider-specific SDK classes at call sites; all model invocations must go through the `provider/model` string interface and the central registry.

The smaller patterns that complete this one —

  • usesTranslation Layer★★Insert a typed boundary between the agent's clean domain model and a messy or legacy external API.

And the patterns that stand alongside it, or against it —

  • complementsMulti-Model Routing★★Send each request to the cheapest model that can handle it well.
  • complementsProvider Fallback★★When one provider's API errors mid-stream, transparently switch to another provider while preserving state.
  • alternative-toVendor Lock-InAnti-pattern: couple application code directly to one model provider's SDK, request shape, and proprietary features so that switching providers requires rewriting application code rather than swapping an adapter.
  • complementsUnified Voice InterfaceExpose text-to-speech, speech-to-text, and real-time speech-to-speech through a single interface so a voice agent can swap providers without rewriting the loop.
  • complementsComplexity-Based RoutingEstimate a request's difficulty up front and bind it to the cheapest model tier that can answer well, using an explicit complexity classifier as the routing key.

Neighbourhood

Click any neighbour to follow the language. Scroll to zoom, drag to pan.