Skip to main content

Route requests through a virtual model (preview)

Enterprise Tier

A virtual model is one model name that Agent Router resolves, for each request, to an Efficient or a Capable model. Virtual models are a preview from 0.14.0 and are off by default.


Preview

Virtual models are off by default in 0.14.0. The switch is a Helm value on the management plane. No Admin Console pages for virtual models exist in 0.14.0. Virtual models are managed through the policy API or the tetrate agentrouter api policy virtual-models commands. Only /v1/chat/completions serves virtual model names, and only the start-efficient strategy is served.

For the other smart-routing mechanisms, see Understand smart routing options.

Before starting​

  • The smart routing switch is on, and the management API is restarted after the change (see Step 1). On a Tetrate-hosted management plane, Tetrate sets the switch on request.
  • The project is attached to a data plane.
  • Every data plane serving the project runs 0.14.0 or later.
  • Both models are enabled and assigned to the project, and each responds to a direct call.
  • The task is run by an Organization admin, or by the project owner. Listing model tiers requires the admin scope. A project owner who is not an Organization admin needs the two tier ids from an Organization admin.

Step 1: turn on smart routing​

Set smartRouting.enabled to true in the api-helm chart values:

smartRouting:
enabled: true

Through manage-helm, the same value is api.smartRouting.enabled.

Restart the management API. The management plane reads the value once at start, so a restart is required after the change.

Step 2: look up the tier ids​

Each Organization has two built-in model tiers, Efficient and Capable. Look up their ids. The request needs the admin scope.

curl -s "https://<management-plane-host>/v1/policy/model-tiers?customer_id=<organization-id>" \
-H "X-Api-Key: <admin-api-key>"

The response lists the tiers in modelTiers. Each tier has an id and a name:

{
"modelTiers": [
{"id": "<efficient-tier-id>", "name": "Efficient"},
{"id": "<capable-tier-id>", "name": "Capable"}
]
}

Use the id values, not the names, in the create request in Step 3.

Step 3: create the virtual model​

Send a POST request to the project's virtual model path. The request body holds one virtual_model object:

curl -s -X POST "https://<management-plane-host>/v1/customers/<organization-id>/projects/<project-id>/policy/virtual-models" \
-H "X-Api-Key: <api-key>" \
-H "Content-Type: application/json" \
-d '{
"virtual_model": {
"name": "<virtual-model-name>",
"models": [
{"model": "<efficient-model>", "provider": "<provider>", "tier": "<efficient-tier-id>"},
{"model": "<capable-model>", "provider": "<provider>", "tier": "<capable-tier-id>"}
],
"strategy": {"type": "VIRTUAL_MODEL_STRATEGY_START_EFFICIENT"}
}
}'

The same request can be sent through the CLI with tetrate agentrouter api policy virtual-models create, the --customer-id and --project-id flags, and the JSON object in the --virtual-model flag.

These rules apply to the request:

  • The name is unique in the Organization. It cannot match the name of any catalog model, enabled or not. The name cannot change after creation.
  • The models list holds exactly one Efficient model and one Capable model. Every model is an enabled model of the project.
  • The strategy is VIRTUAL_MODEL_STRATEGY_START_EFFICIENT. This is the only strategy served in 0.14.0.
  • A virtual model can be created from a routing strategy in the Organization's library. Send strategy_id in place of models and strategy. Sending both is refused. Changing or deleting a routing strategy never changes a virtual model already created from it.

A successful request returns 200. The virtualModel object holds the id, the status (POLICY_STATUS_ACTIVE), and the two models.

Step 4: check the data planes​

List the project's virtual models. The response includes the data planes that serve the project:

curl -s "https://<management-plane-host>/v1/policy/virtual-models?customer_id=<organization-id>&project_id=<project-id>" \
-H "X-Api-Key: <api-key>"

The dataplanes list shows each data plane with its dataplaneId, reportedVersion, servesVirtualModels, and minVersion. An empty list means no data plane serves the project.

The version check runs when a virtual model is created, changed, or turned on. It does not run again for a data plane attached later. Check the list again after any data plane is attached.

Step 5: send a request​

Send a chat completion request to the data plane. Use the virtual model name in the model field:

curl -i "https://<data-plane-host>/v1/chat/completions" \
-H "Authorization: Bearer <project-api-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "<virtual-model-name>",
"messages": [{"role": "user", "content": "Hello, world!"}]
}'

The response headers show the routing result:

  • x-model-requested holds the virtual model name.
  • x-model-effective holds the model that answered. This header appears on buffered responses only.

Streaming responses carry x-model-requested but not x-model-effective. The model that answered can be read from the x-model-provider header, from the model field of each chunk, or from the request log.

Propagation takes seconds to several minutes. Repeat the request until it succeeds, rather than waiting a fixed time. The first request after a change can answer model_not_found on a client connection opened before the change. Retry on a new connection.

How a model is picked​

With the start-efficient strategy, the model is picked as follows:

  • A first turn with no tool history goes to the Efficient model.
  • A turn whose tool result has a critical error (for example, out of memory) goes to the Capable model.
  • A single hard error (for example, connection refused) or a clean result stays on the Efficient model.
  • The same hard error twice in recent history counts as a repeated failure and goes to the Capable model.

If routing fails, the data plane sends the request to the Capable model. The alerts that report routing failures are described in Route data plane alerts.

The rest of the request path applies to the picked model:

  • Attribute-based routing and budget fallback still run on the picked model and can replace it.
  • Guardrails apply to the picked model.
  • Rate limits count a virtual model request once against the key's limits, whichever model is picked.
  • The request log records the served model as the model, and the virtual model name as the requested model. Usage and cost use the price of the served model. In 0.14.0, the request log has no smart-routing decision fields, such as tier or reason.

Change, turn off, or delete a virtual model​

Change a virtual model with a PATCH request to the virtual model's path. A non-empty models list replaces both models. A field left out of the request keeps its stored value. The name cannot change.

curl -s -X PATCH "https://<management-plane-host>/v1/customers/<organization-id>/projects/<project-id>/policy/virtual-models/<virtual-model-id>" \
-H "X-Api-Key: <api-key>" \
-H "Content-Type: application/json" \
-d '{"virtual_model": {"id": "<virtual-model-id>", "models": [{"model": "<efficient-model>", "provider": "<provider>", "tier": "<efficient-tier-id>"}, {"model": "<capable-model>", "provider": "<provider>", "tier": "<capable-tier-id>"}]}}'

Turn a virtual model on or off with a POST request to the status path. Use POLICY_STATUS_ACTIVE or POLICY_STATUS_INACTIVE:

curl -s -X POST "https://<management-plane-host>/v1/customers/<organization-id>/projects/<project-id>/policy/virtual-models/<virtual-model-id>/status" \
-H "X-Api-Key: <api-key>" \
-H "Content-Type: application/json" \
-d '{"status": "POLICY_STATUS_INACTIVE"}'

Delete a virtual model with a DELETE request to its path:

curl -s -X DELETE "https://<management-plane-host>/v1/customers/<organization-id>/projects/<project-id>/policy/virtual-models/<virtual-model-id>" \
-H "X-Api-Key: <api-key>"

Turning a virtual model off and deleting it are never refused, whatever the state of the switch or the data planes. An admin can always clear a virtual model this way.

These effects apply to changes:

  • Turning the switch off does not stop a served name at once. To stop names, turn the virtual models off while the switch is still on.
  • Stored virtual models are kept when the switch is turned off. Active virtual models are served again when the switch is turned back on.
  • Each change replaces the data plane's egress listener. The old listener drains for 300 seconds, so a request that runs longer than that can be cut.

Manage model tiers, routing profiles, and routing strategies​

Model tiers, routing profiles, and routing strategies belong to the Organization, so every project uses the same ones. Writes need the Organization admin scope. A virtual model is created from a strategy by sending strategy_id, as Step 3 describes.

ObjectWhat it holdsFields
Model tierA label for what a model is used for, such as Efficient or Capable.name, description, builtIn (output only)
Routing profileA named set of Organization models, each in a model tier, and an optional judge.name, description, models (each entry has model, provider, and tier, the model tier id), judge (optional)
Routing strategyHow the data plane picks a model, with one routing profile.name, description, type (VIRTUAL_MODEL_STRATEGY_START_EFFICIENT or VIRTUAL_MODEL_STRATEGY_JUDGE), routingProfileId

These rules apply:

  • No request is routed by these objects unless smartRouting.enabled is true in the api-helm values and an active virtual model uses them.
  • The built-in tiers, Efficient and Capable, cannot be renamed or deleted. Only their description can change.
  • A tier added by an Organization admin cannot be deleted while a routing profile or virtual model uses it. The refusal names the tier and the profiles or virtual models that use it, and asks for them to be changed first.
  • A profile can list any number of models in any tier. Whether a project can use them is checked when a strategy is applied to a virtual model, not when the profile is saved.
  • The judge of a profile is either a catalog chat model, named by model and provider, or a decision model of the Organization, named by decision_model_id. Decision models are added in a later release.
  • A strategy's profile holds exactly one Efficient and one Capable model. A change to a strategy or its profile that breaks this rule is refused. The refusal message contains needs a profile with exactly one Efficient and one Capable model.
  • A strategy of type VIRTUAL_MODEL_STRATEGY_JUDGE needs a profile with a judge. The refusal message contains uses the judge strategy and needs a profile with a judge.
  • A non-empty models list in a profile update replaces the whole list. A judge that is sent replaces the stored judge.
  • A profile used by a routing strategy cannot be deleted. The refusal names the profile and the strategies that use it, and asks for those strategies to be deleted or changed first.
  • Editing a profile never changes a virtual model. Applying a strategy copies the profile's models and judge into the virtual model.

Lists are GET requests to /v1/policy/model-tiers, /v1/policy/routing-profiles, and /v1/policy/routing-strategies, with customer_id as a query parameter, as in Step 2. Writes use these paths, where {id} is the object id:

POST /v1/customers/{customer_id}/policy/model-tiers
PATCH /v1/customers/{customer_id}/policy/model-tiers/{id}
DELETE /v1/customers/{customer_id}/policy/model-tiers/{id}

The routing profile and routing strategy objects use the same paths with routing-profiles or routing-strategies in place of model-tiers. The CLI has matching command groups: tetrate agentrouter api policy model-tiers, tetrate agentrouter api policy routing-profiles, and tetrate agentrouter api policy routing-strategies.

Troubleshooting​

Refusals use the problem+json format. The detail field holds the message, reason holds the gRPC code, and status holds the HTTP code.

Symptom or answerCauseFix
400 FAILED_PRECONDITION, message smart routing is off on this installThe switch is offSet smartRouting.enabled to true, then restart the management API (Step 1).
400 FAILED_PRECONDITION, message names a data planeA data plane serving the project runs a build older than 0.14.0, has not reported its version in 24 hours, or reported a build that cannot be readUpgrade the named data plane to 0.14.0 or later, and check that it reports its version.
400 INVALID_ARGUMENT, message contains is not an enabled model in projectThe model is missing from the catalog, disabled, or not assigned to the projectEnable the model and assign it to the project, or use another model.
400 INVALID_ARGUMENT, message contains is also served by providerTwo enabled providers serve the same model nameUse a model that only one enabled provider serves.
400 INVALID_ARGUMENT, message contains serves the and request APIThe two models serve different request APIs. Chat and responses count as one API.Use two models that serve the same request API.
400 INVALID_ARGUMENT, message contains has no Capable model, has no Efficient model, or is a second Efficient modelThe virtual_model.models list does not hold exactly one model of each tierInclude exactly one Efficient model and one Capable model.
400 INVALID_ARGUMENT, message contains does not exist in organizationA tier name was used in place of a tier id, or the id belongs to another OrganizationUse the tier id from Step 2 for this Organization.
409 ALREADY_EXISTSThe name is used by another virtual model in the Organization, or by a catalog modelChoose another name.
400 INVALID_ARGUMENT, message names a refused fieldThe data plane would refuse the settings, so nothing is storedCorrect the named field.
403 PERMISSION_DENIEDThe caller is neither an Organization admin nor the project owner, or the key belongs to another projectUse a key from an Organization admin or the project owner.
dataplanes list is emptyNo data plane serves the projectAttach a data plane to the project, then check the list again.
model_not_found on /v1/responses or /v1/messagesVirtual models work only on /v1/chat/completionsSend the request to /v1/chat/completions.
model_not_found on /v1/chat/completions for a name from another projectThe data plane resolves virtual models only for the caller's projectSend the request with a key from the project that owns the virtual model.
model_not_found for a virtual model with the judge strategyOnly the start-efficient strategy is servedCreate the virtual model with VIRTUAL_MODEL_STRATEGY_START_EFFICIENT.
model_not_found from a data planeThe data plane runs a build older than 0.14.0Upgrade the data plane to 0.14.0 or later.
model_not_found directly after a changeThe change has not reached the data plane yetRepeat the request after seconds to a few minutes.
model_not_found on a connection opened before a changeThe client connection predates the changeRetry the request on a new connection.

What 0.14.0 does not do​

  • Serve virtual model names on /v1/responses or /v1/messages.
  • List virtual model names on /v1/models.
  • Serve the judge strategy. A judge-strategy virtual model can be stored, but it is not sent to data planes.
  • Provide Admin Console pages for virtual models.
  • Record smart-routing decision fields, such as tier or reason, in the request log.