AI Gateway Model routing

Routing

Routing finds a cheaper model for each agent, proven on its own traffic. It works per agent, in one of two modes:

ShadowSemantic
What it doesWatches the agent's real calls, tests cheaper models side by side, and recommends onePicks a model for each call from a fixed list you confirm, and serves it
Changes what is servedOnly after an admin approves the switchYes, as soon as you turn it on
Use it toFind the right base model for an agent, with evidenceSend each call to the model that fits its task, from models you already allow

An agent runs one mode at a time. For retries and fallbacks when a provider is down, see Gateway.

Permissions: routing:view to open Routing; routing:evaluate or agents:write to start or stop a Shadow window. Semantic, limits and the routing budget are admin-only.

The Routing page

The Agents and Decisions tabs are available to members with Routing access. Recommend and Benchmarks appear only in workspaces enabled for them by the deployment.

TabWhat it shows
AgentsEvery agent's routing state. Click a row to open that agent's routing page.
ImpactOne report per agent: what routing changed over the last 30 days, measured against the model the agent was built on. See Impact.
DecisionsThe recommender applied to real traffic. For each governed call, what routing would have picked and what that would have cost at the same token counts. The call is still served by the model the caller asked for. Open a call to see its candidates.
RecommendA ranked catalog for a prompt you paste, with evidence. It does not execute the recommended task. The UI uses a governed classifier call, which can be billed.

Filter agents by Ready, In progress, Needs attention or Idle. Start opens the start dialog; New route profile creates a route profile.

Routing → Agents: every agent's state, with filters and Start
Routing → Agents: every agent's state, with filters and Start

Agent states

StateMeaning
OffNo window running, not on Semantic.
ObservingA Shadow window is collecting evidence.
Checking the judgeThe quality judge's checks haven't passed yet. See The quality judge.
ReadyA cheaper model qualified. Request approval to switch.
No changeNothing cheaper held quality. The agent keeps its model.
Not enough trafficToo few calls to compare anything.
Held backA candidate looked good but was blocked. The page says why.
Awaiting approvalA switch request is with an admin.
CanaryThe switch is live and being watched for errors.
SwitchedThe canary passed. The new model stays.
Rolled backErrors rose after the switch, so it went back to the previous model.
Reverted: not enough trafficThe canary saw too few calls to confirm the switch, so it was undone.
Reverted: a key rejected the modelOne of the agent's keys isn't allowed to call the new model, so the switch was undone.
Changed manuallySomeone changed the agent's model during the canary, so routing stopped watching.

Impact

Impact shows what routing changed for each agent that had Smart-routed calls in the last 30 days. Everything is measured against the agent's intended model, the model it was built on.

Each row shows the intended model, the day routing started, the cost per session before and after (for example, $0.42 → $0.31), a quality result and what to do next:

QualityMeaning
HeldEnough answers were judged, and the judge did not prefer the intended model.
N worseThe judge preferred the intended model N times. The next step is Send back.
N judgedToo few judged comparisons so far to call it.
Not judgedThe judge hasn't compared any of this agent's answers yet.
NextMeaning
Keep routingCost fell and quality held. Leave routing on.
Keep watchingThere isn't enough evidence yet. Read the report again later.
Send backThe judge preferred the intended model in these comparisons. Turn routing off for the agent so it runs on its intended model again.

Open an agent's row for its report. The cover gives the recommendation and the models routing used. The report then covers cost per session, median call time, the judged comparison, where the work went by model, and Sessions worth reading, the judge's most recent clear calls either way. How this was measured explains each figure. A figure that can't be measured, such as cost when no call had a price for the intended model, is shown as unavailable and isn't estimated.

You need a signed-in member identity to open Impact, because the report is about whose calls these were. A key with no identity sees a message saying so.

Shadow routing

  1. Start observing

    On the agent's routing page, choose Start observing, keep Routing mode on Shadow, and set:

    • Profile: a saved routing profile. It fills the fields below, and you can still change any of them. Shown only when a profile exists. An agent's default profile is picked for you.
    • Objective: Cost first, Quality first, Latency first or Balanced. With Balanced, set Weights for cost, quality and speed.
    • How long: 7, 14 or 30 days, or Custom from 1 to 60.
    • Stop after N calls: optional, 10 to 10,000. The window ends at this many calls or when time runs out, whichever comes first.
    • Test on: 5%, 10% or 25% of calls. These are re-sent to candidate models in the background as side-by-side tests.
    • Models to test: the candidates.
    • Quality judge: the model that grades the side-by-side answers.

    Evaluation intersects the agent's routing limits and credential policy. The registration model pin is treated as bookkeeping for Shadow replay; an explicitly configured allowlist remains a restriction.

  2. Evidence builds up

    Real calls are served as normal. The judge grades each sampled candidate answer against the current model's. Users never see candidate answers.

  3. Read the result

    Overview shows the decision: calls observed, models compared, what a switch would save per 30 days, the speed change, and the judge's tally ("29 of 30 at least as good"). Evidence lists every side-by-side test. Preview result computes the recommendation from what has been seen so far; Finish now, in the ⋯ menu, ends the window early.

    The Recommendation card lists the top three models that passed every check, best first for the window's objective, each with its cost, quality and speed change. Show all qualifying lists the rest.

  4. Request approval

    Choose Request approval on the model you want. Each model has its own button, and any listed model can be requested. An admin approves the change, then it goes live as a canary. To end the window with no change, choose Keep current model. You can add a reason.

An agent on day 6 of a 14-day Shadow window: calls observed, the judge's checks and the evidence so far
An agent on day 6 of a 14-day Shadow window: calls observed, the judge's checks and the evidence so far

Side-by-side tests and the judge are real, billed calls. They are paid from the agent's routing budget, never its spend cap.

The bars a switch has to clear

A candidate is recommended only if it clears all of these:

BarValue
CapabilityNo more than 5% worse than the current model on its worst task class, not its average.
Quality on real answersA fixed horizon of assigned trials, 30 by default and saved when the window starts. Benchmark mode requires a 95% Wilson lower bound of at least 80% "at least as good". Blended or learned mode uses a non-inferiority probability gate instead.
SavingAt least 10% and $0.10, after the window's own test and judge spend.
ErrorsA candidate failing more than 15% of its side-by-side tests (over 22 or more) is dropped.

These are deployment defaults; the window's stored settings determine its gate. Finishing early does not bypass the fixed trial horizon.

Confidence is Low below 30 calls, Medium from 30, and High from 200 by default. With no quality judge, no candidate can pass.

The quality judge

The judge's verdicts count once it has passed its checks. The automatic check decides: the judge must see no difference between identical answers, and must not favour one side on pairs that should be equal.

You can also check the judge yourself, and it's optional. In Checking the judge, use Label next test to say which of two answers you prefer, up to 30 tests, shown in a fixed random order. The judge's calls are compared with yours. If your answers often differ from the judge's, you're told to keep checking or try another judge. Your deployment can require this check before a recommendation. Until the required checks pass, candidates show "no change".

The canary

After approval the agent switches to the new model, and Forgebench watches its real calls for 24 hours:

  • More than 10% failed calls (over at least 20): it rolls back to the previous model on its own.
  • Too few calls: the watch is extended once, then the switch is reverted.
  • A key that can't call the new model: the switch is reverted.

Routing profiles

A routing profile saves the settings of a test so you can reuse them. Open Routing profiles at the top of the Routing page. These only shape tests. They don't serve calls, and they are not the route profiles below.

An admin or owner can create, edit and delete profiles. Everyone else can read them. Each profile sets:

FieldWhat it does
Name, DescriptionThe name is required.
Models to testThe models a test may use. Empty means any model the agent's key and workspace allow.
ProvidersThe providers a test may use. Empty means any.
Objective, WeightsCost first, Quality first, Latency first or Balanced. Weights apply to Balanced and may use any scale: 50/30/20 is the same as 5/3/2.
Test on5%, 10% or 25% of calls.
Stop after N callsOptional, 10 to 10,000.
How longOptional: Default, 7, 14 or 30 days, or Custom from 1 to 60.
Quality judge, Backup judgeOptional. With none, a test uses the agent's strongest eligible judge. The backup is used only if the judge fails or gives no verdict.

Starting a test from a profile copies its values onto that test, so editing or deleting the profile later doesn't change a test that is running. On an agent's routing page, an admin can set a default Routing profile. It is used when a test starts without one.

Semantic routing

Semantic sends each call to the model that best fits its task, from a list you confirm. The usual fallbacks apply.

  1. Choose Semantic

    On the agent's routing page, choose Start observing and set Routing mode to Semantic.

  2. Pick the models

    Start from a Saved route profile, or pick Models to route across yourself. Models the agent can't use are left out and named.

  3. Confirm and turn it on

    Confirm the list, including the agent's current model. The agent's key must allow every model in it. Semantic routing requires model switching to be enabled for the deployment. Otherwise the API returns 422 model_switching_disabled.

The agent's model becomes profile:<name>. Turn Semantic routing off returns it to its previous model.

If the profile breaks (a model is removed, or a key no longer allows it), calls are refused with 409 rather than sent to another model.

Route profiles

A model profile is a named list of provider/model candidates with failover. An admin manages it through POST /v1/routing/profiles and PATCH /v1/routing/profiles/{profile_id}. Assign profiles with routing rules or the agent's Semantic action before selecting model="profile:<name>". Creating a profile alone does not grant every key access to it.

The old /v1/route-profiles and /v1/smart-routing APIs return 410 route_profiles_consolidated.

A profile's strategy decides how it picks among its models: for example priority (in order, failing over), weighted (split by the weights you give), or round-robin. Additional strategies such as cost-optimized, auto, semantic, and smart depend on deployment settings. Read GET /v1/routing/strategies?kind=chat for the offered strategies. Voice profiles have separate transcription and speech kinds and cannot be assigned to chat rules.

One model on several provider keys

A profile can list the same model more than once, each step on a different key for the same provider. With weighted it splits traffic between the keys (for example 50/50); with priority it fails over from one to the next. A 429 on one key cools down only that key, and the others keep serving.

Each provider has one default key. An admin adds more keys under a label, with the API:

import os
import httpx

r = httpx.put(
  f"{os.environ['FORGEBENCH_BASE_URL']}/v1/secrets/providers",
  headers={"Authorization": f"Bearer {os.environ['FORGEBENCH_ADMIN_KEY']}"},
  json={"provider": "openrouter", "api_key": "sk-or-...", "label": "org-b"},
)
r.raise_for_status()

Then create the profile with a candidates list. Each entry has provider, model, and an optional key label. Omitting key uses the provider's default credential. The weights align with the candidates:

import os
import httpx

r = httpx.post(
  f"{os.environ['FORGEBENCH_BASE_URL']}/v1/routing/profiles",
  headers={"Authorization": f"Bearer {os.environ['FORGEBENCH_ADMIN_KEY']}"},
  json={
      "name": "gpt5-two-keys",
      "strategy": "weighted",
      "candidates": [
          {"provider": "openrouter", "model": "openrouter-gpt-5"},
          {"provider": "openrouter", "model": "openrouter-gpt-5", "key": "org-b"},
      ],
      "weights": [50, 50],
  },
)
r.raise_for_status()

Labels are 1 to 64 letters, digits, _, . or -. You can't delete a labelled key while a profile uses it.

Routing limits

Limits narrow what routing may choose; they never widen what a key allows. Set Allowed providers for the workspace on the Routing page, and Allowed models and Allowed providers per agent on its routing page. Empty means no restriction.

Routing budget

Each agent has a Routing budget for side-by-side tests and the judge, separate from its spend cap. It never affects production traffic.

SettingWhat it does
Monthly cap (USD)Empty uses the default. 0 means no evaluation.
Raise the cap for this monthReplaces the cap for the current month only.
Bill evaluation toThe agent's own key by default, or another Forgebench key, so that key's limits and pool apply.
Budget pool (optional)Evaluation also stops when this pool's budget is used up.
When the budget is used upPause evaluation (default) or warn only.
Warn atPercentage of the cap. Default 80%.
Pause evaluationStops tests and the judge now, whatever the budget.

Recommend a model

Paste a prompt and pick what to optimise for (capability, cost, speed or a balanced default). You get a ranked shortlist from the whole catalog, with the task type, difficulty and the benchmark scores behind the pick. Models your workspace can't reach are marked, not hidden.

A recommendation with its shortlist and evidence
A recommendation with its shortlist and evidence

Multi-step apps

Shadow routing treats one key as one agent, so the hardest step of an app blocks savings on the rest. Register each step as its own agent with a workflow.

Next

Cookie settings

Our Cookie Policy lists every cookie and what it does.