MixtrainDocs
from mixtrain import Router

Constructor

Router(name: str)

Creates a reference to an existing router. This is a lazy operation - no API call is made until you access properties or call methods.

ParameterTypeDescription
namestrRouter name
router = Router("image-gen-router")

Properties

PropertyTypeDescription
namestrRouter name
configdictFull configuration (cached)
ruleslistList of routing rules
versionslistVersion history
active_versionintCurrently deployed version number

Methods

route()

Route a request based on configured rules.

router.route(data: dict) -> RouteResult
ParameterTypeDescription
datadictRequest data to match against rules

Returns: RouteResult

result = router.route({"user": {"tier": "premium"}, "prompt": "A sunset"})
print(f"Matched rule: {result.matched_rule.name}")
print(f"Target: {result.selected_targets[0].model_name}")

list_requests()

Get routing request history.

router.list_requests(limit: int = 100) -> list[dict]
ParameterTypeDescription
limitintMaximum number of requests to return

Returns: list[dict]

requests = router.list_requests(limit=50)
for req in requests:
    print(f"{req['matched_rule']}: {req['selected_target']}")

get_request()

Get details for a specific request.

router.get_request(request_id: str) -> dict
ParameterTypeDescription
request_idstrRequest ID

Returns: dict with request details

update()

Update router rules.

router.update(rules: list = None, **kwargs) -> None
ParameterTypeDescription
ruleslistNew routing rules

deploy()

Deploy a specific version.

router.deploy(version: int) -> None
ParameterTypeDescription
versionintVersion number to deploy
router.deploy(version=3)

delete()

Delete the router.

router.delete() -> None

refresh()

Clear cached data.

router.refresh() -> None

RouteResult

Return type from router.route().

Properties

PropertyTypeDescription
matched_ruleRuleThe rule that matched
selected_targetslist[Target]Selected target models

Rule

PropertyTypeDescription
namestrRule name
priorityintRule priority

Target

PropertyTypeDescription
model_namestrTarget model name
weightfloatTraffic weight (for SPLIT strategy)

Routing Strategies

StrategyDescription
SINGLERoute to a single target
SPLITA/B testing with weighted distribution
SHADOWPrimary + test targets for comparison
FALLBACKSequential fallback if primary fails

Condition Operators

OperatorDescriptionExample
equalsExact match{"field": "tier", "operator": "equals", "value": "premium"}
not_equalsNot equal{"field": "status", "operator": "not_equals", "value": "blocked"}
greater_thanGreater than{"field": "credits", "operator": "greater_than", "value": 100}
less_thanLess than{"field": "tokens", "operator": "less_than", "value": 1000}
is_inIn list{"field": "region", "operator": "is_in", "value": ["us-east", "us-west"]}
containsString contains{"field": "query", "operator": "contains", "value": "urgent"}
regex_matchRegex match{"field": "id", "operator": "regex_match", "value": "^prod_"}

On this page