InferenceAI

Enter at least two characters to search.

Start free

Model Fallback Router

mediumProduction AI20 min25 XP

A production endpoint has models represented by [name, cost_cents, latency_ms, healthy]. Implement route_model(models, max_cost_cents, max_latency_ms). Return the name of the cheapest healthy model within both budgets. Break equal-cost ties by lower latency, then by input order. Return None if none qualify. All numeric values are nonnegative.

Examples

EXAMPLE WALKTHROUGHcheapest eligible

A guided view of the published example, not a trace of your code.

INPUT[[["large",8,300,true],["small",2,120,true],["backup",1,500,true]],8,350]
TASKroute_model()
EXPECTED OUTPUT"small"

Start with the input values shown in this example.

Example 1 of 2

Input: models = [["large",8,300,true],["small",2,120,true],["backup",1,500,true]], max_cost_cents = 8, max_latency_ms = 350

Output: "small"

Explanation: cheapest eligible

Input: models = [["a",3,100,true],["b",3,80,true]], max_cost_cents = 3, max_latency_ms = 200

Output: "b"

Explanation: latency tie break

Hint 1

Apply health and both budgets before ranking.

Hint 2

Compare cost first, then latency.

Topics

PythonModel RoutingReliabilityCost Optimization