from mixtrain import RouterConstructor
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.
| Parameter | Type | Description |
|---|---|---|
name | str | Router name |
router = Router("image-gen-router")Properties
| Property | Type | Description |
|---|---|---|
name | str | Router name |
config | dict | Full configuration (cached) |
rules | list | List of routing rules |
versions | list | Version history |
active_version | int | Currently deployed version number |
Methods
route()
Route a request based on configured rules.
router.route(data: dict) -> RouteResult| Parameter | Type | Description |
|---|---|---|
data | dict | Request 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]| Parameter | Type | Description |
|---|---|---|
limit | int | Maximum 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| Parameter | Type | Description |
|---|---|---|
request_id | str | Request ID |
Returns: dict with request details
update()
Update router rules.
router.update(rules: list = None, **kwargs) -> None| Parameter | Type | Description |
|---|---|---|
rules | list | New routing rules |
deploy()
Deploy a specific version.
router.deploy(version: int) -> None| Parameter | Type | Description |
|---|---|---|
version | int | Version number to deploy |
router.deploy(version=3)delete()
Delete the router.
router.delete() -> Nonerefresh()
Clear cached data.
router.refresh() -> NoneRouteResult
Return type from router.route().
Properties
| Property | Type | Description |
|---|---|---|
matched_rule | Rule | The rule that matched |
selected_targets | list[Target] | Selected target models |
Rule
| Property | Type | Description |
|---|---|---|
name | str | Rule name |
priority | int | Rule priority |
Target
| Property | Type | Description |
|---|---|---|
model_name | str | Target model name |
weight | float | Traffic weight (for SPLIT strategy) |
Routing Strategies
| Strategy | Description |
|---|---|
SINGLE | Route to a single target |
SPLIT | A/B testing with weighted distribution |
SHADOW | Primary + test targets for comparison |
FALLBACK | Sequential fallback if primary fails |
Condition Operators
| Operator | Description | Example |
|---|---|---|
equals | Exact match | {"field": "tier", "operator": "equals", "value": "premium"} |
not_equals | Not equal | {"field": "status", "operator": "not_equals", "value": "blocked"} |
greater_than | Greater than | {"field": "credits", "operator": "greater_than", "value": 100} |
less_than | Less than | {"field": "tokens", "operator": "less_than", "value": 1000} |
is_in | In list | {"field": "region", "operator": "is_in", "value": ["us-east", "us-west"]} |
contains | String contains | {"field": "query", "operator": "contains", "value": "urgent"} |
regex_match | Regex match | {"field": "id", "operator": "regex_match", "value": "^prod_"} |