← Blog

Claude API Multi-Model Router Setup Guide

2026-11-18 · 5 min read · SubToAPI Team

A multi-model router sits between your application and the Claude API, deciding which model handles each request based on cost, latency, task complexity, or fallback needs. Instead of hardcoding claude-opus-4 everywhere, you send requests to a single internal endpoint that picks the right model dynamically — Haiku for quick classification, Sonnet for general chat, Opus for complex reasoning.

This matters because real applications rarely need the same model for every call. A support bot answering FAQs doesn't need Opus-level reasoning, but an escalation path that drafts a legal summary does. Setting up a router correctly means you get cost savings on the easy 80% of traffic without sacrificing quality on the hard 20%. Below is a practical setup you can implement directly.

What a router actually needs to do

A working multi-model router handles four things:

  1. Model selection logic — rules or heuristics that pick a model per request
  2. Unified request/response shape — your app code shouldn't change when the model changes
  3. Fallback handling — if the primary model is rate-limited or errors out, retry on a secondary model
  4. Usage tracking per model — so you can see cost and volume broken down by which model actually ran

None of this requires a separate microservice for small-to-medium apps. A single module with a switch statement and a shared client is enough to start.

Step 1: Define your routing rules

Start simple. Most teams route on one of three signals:

function selectModel({ taskType, inputLength }) {
  if (taskType === "classification" || inputLength < 200) {
    return "claude-haiku-4";
  }
  if (taskType === "reasoning" || taskType === "codegen") {
    return "claude-opus-4";
  }
  return "claude-sonnet-4"; // default
}

Keep this function pure and testable. Routing logic that's tangled into your API call code becomes unmaintainable once you add a fourth or fifth model.

Step 2: Build a single client wrapper

Wrap all outbound Claude calls in one function so model selection, retries, and logging live in one place:

async function callClaude({ taskType, inputLength, messages }) {
  const model = selectModel({ taskType, inputLength });

  try {
    return await sendRequest(model, messages);
  } catch (err) {
    if (isRetryable(err) && model !== "claude-opus-4") {
      return await sendRequest("claude-opus-4", messages);
    }
    throw err;
  }
}

The fallback here is deliberately conservative — only escalate to a stronger model on failure, never silently downgrade a request that already specified a strong model.

Step 3: Decide where routing lives — client-side vs. gateway

You have two architectural options:

Client-side routing: the model-selection logic lives in your application code, and you call the Claude API (or a proxy in front of it) directly with whichever model you picked. This is simple but means every service that talks to Claude needs to carry the same routing logic, and key management is duplicated across services.

Gateway-side routing: a single HTTPS endpoint accepts requests, applies routing rules server-side, and forwards to the right model. Your application code stays model-agnostic — it just calls one API with a task hint, and the gateway decides.

If you're running multiple services (a web app, a Slack bot, a batch job) that all need Claude access, gateway-side routing avoids re-implementing the same logic three times. This is also where a hosted layer like SubToAPI is useful: it gives you a standard API key (sub_live_...) and a single endpoint, so your router logic can live in one place and every service just sends requests with Authorization: Bearer $SUBTOAPI_KEY. You still choose the model per request — the gateway doesn't lock you into one — but you get streaming, usage metadata per key, and team seats without building that layer yourself. See the quickstart for the request format.

Step 4: Track usage per model

Once requests are routed across multiple models, flat token counts stop being useful — you need to know cost and volume broken down by model. At minimum, log:

function logUsage({ model, taskType, usage, latencyMs, fellBack }) {
  metrics.record("claude_request", {
    model,
    taskType,
    inputTokens: usage.input_tokens,
    outputTokens: usage.output_tokens,
    latencyMs,
    fellBack,
  });
}

If you're on SubToAPI, usage metadata is already returned per request and visible in the dashboard broken down by key — useful if you give each service or team its own key and want to see which one is driving Opus costs. See /docs/messages for the response fields.

Step 5: Add streaming where it matters

Routing decisions shouldn't block streaming. Whichever model you pick, the client should support streamed responses the same way regardless of model, so your UI code doesn't need per-model branches:

const stream = await callClaude({
  taskType: "chat",
  messages,
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.delta ?? "");
}

Check /docs/streaming if you're implementing this against a gateway — the event format should be identical no matter which underlying model served the request.

Step 6: Handle tool use consistently across models

If some of your routed models call tools and others don't, keep the tool schema identical across all of them. Define tools once, pass the same definitions regardless of which model handles the request, and let the model decide whether to invoke them. See /docs/tools for the tool-calling request shape — consistency here is what makes model swapping safe.

Common mistakes to avoid

Questions

Do I need a separate API key per model? No. A single API key authenticates against the Claude API (or a gateway like SubToAPI); the model is specified per request in the payload, not tied to the key.

Should routing logic live in my app or in a gateway? If you have one application, client-side is fine. If multiple services need Claude access with consistent routing, a gateway endpoint avoids duplicating logic — see /pricing for gateway plan options.

What's the simplest way to start without building a router from scratch? Begin with a two-tier setup (cheap model + fallback to strong model) using the wrapper pattern above, then add task-based rules as you see which requests actually need the stronger model. Sign up at /signup if you want usage tracking per model included from day one.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →