Skip to main content

Rules

Rules are evaluated in order. The first matching rule that sets a pin_tier wins for that action. Deny rules are cumulative — multiple rules can deny multiple tiers.

deny_tiers

Excludes tiers when the condition is true.
# never route to small models when the conversation is long
Rule(if_context_tokens_gt=4000, deny_tiers=["small"])

# never route to small or medium when cost is a concern
Rule(if_estimated_cost_gt=0.05, deny_tiers=["small", "medium"])

pin_tier

Forces a specific tier regardless of other rules. First pin wins.
# always use the best model for sensitive tasks
Rule(if_task="legal-review", pin_tier="large")
Rule(if_task="medical-advice", pin_tier="large")

prefer_tier

Softly prefers a tier. Overridden by deny rules.
# prefer cheap models when cost is low
Rule(prefer_tier="small", if_estimated_cost_gt=0.001)

escalate on error

Auto-retry on the next tier when a specific error code is received.
Rule(if_error_code=429, escalate=True)   # rate limit → try next tier
Rule(if_error_code=529, escalate=True)   # overloaded → try next tier

Rule conditions reference

ConditionTypeDescription
if_context_tokens_gtintFires when estimated token count exceeds this
if_taskstringFires when task_hint matches exactly
if_error_codeintFires when previous call returned this HTTP status
if_estimated_cost_gtfloatFires when estimated cost (USD) exceeds this
All conditions on a single Rule are AND-ed. Use separate rules for OR logic.