Skip to content

Update Routing Rule

Updates an existing routing rule. All fields are optional - only provide the fields you want to change.

PATCH /v1/routing-rules/{id}
ParameterTypeRequiredDescription
idintegerYesThe routing rule ID

All fields are optional. Only include fields you want to update:

ParameterTypeDescription
namestringHuman-readable name (max 128 characters)
is_enabledbooleanWhether the rule is active
priorityintegerRule priority (-1000 to 1000)
match_jsonobject|stringMatch conditions
action_jsonobject|stringActions to apply
import Tokenrouter from 'tokenrouter';
const client = new Tokenrouter({
apiKey: process.env.TOKENROUTER_API_KEY
});
// Disable a rule
await client.routingRules.update(123, {
is_enabled: false
});
// Enable a rule
await client.routingRules.update(123, {
is_enabled: true
});
// Increase rule priority to execute it earlier
await client.routingRules.update(123, {
priority: 200
});
// Change match conditions
await client.routingRules.update(123, {
match_json: {
task: 'code_review',
mode: 'quality' // Add additional condition
}
});
// Change from forcing provider to just overriding mode
await client.routingRules.update(123, {
action_json: {
set_mode: 'cost'
}
});
await client.routingRules.update(123, {
name: 'Updated Rule Name',
priority: 150,
is_enabled: true,
match_json: {
contains: 'analyze'
},
action_json: {
set_provider: 'anthropic',
set_mode: 'quality'
}
});
{
"data": {
"id": 123,
"user_id": 456,
"name": "Updated Rule Name",
"is_enabled": true,
"priority": 150,
"match_json": {
"contains": "analyze"
},
"action_json": {
"set_provider": "anthropic",
"set_mode": "quality"
},
"created_at": "2025-11-10T12:00:00Z",
"updated_at": "2025-11-10T15:30:00Z"
}
}
{
"error": {
"message": "Routing rules are not available on the free plan",
"type": "authorization_error",
"http_status": 403
}
}
{
"error": {
"message": "Routing rule not found",
"type": "not_found_error",
"http_status": 404
}
}
{
"error": {
"message": "Validation failed",
"type": "validation_error",
"http_status": 422,
"errors": {
"priority": ["The priority must be between -1000 and 1000"]
}
}
}
// Disable temporarily for testing
const original = await client.routingRules.retrieve(ruleId);
await client.routingRules.update(ruleId, {
is_enabled: false
});
// Test your requests...
// Re-enable
await client.routingRules.update(ruleId, {
is_enabled: true
});
// Get all rules
const rules = await client.routingRules.list();
// Find highest priority
const highestPriority = Math.max(...rules.data.map(r => r.priority));
// Make this rule highest priority
await client.routingRules.update(ruleId, {
priority: highestPriority + 10
});
// Swap priorities between two rules
const rule1 = await client.routingRules.retrieve(id1);
const rule2 = await client.routingRules.retrieve(id2);
await client.routingRules.update(id1, {
priority: rule2.data.priority
});
await client.routingRules.update(id2, {
priority: rule1.data.priority
});
  1. Update one field at a time when testing changes
  2. Disable before major changes to prevent unexpected routing
  3. Use descriptive names when renaming rules
  4. Test priority changes by listing rules after update
  5. Keep match conditions simple - complex logic can be split into multiple rules