Delete Routing Rule
Delete Routing Rule
Section titled “Delete Routing Rule”Permanently deletes a routing rule. This action cannot be undone.
Endpoint
Section titled “Endpoint”DELETE /v1/routing-rules/{id}Path Parameters
Section titled “Path Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
id | integer | Yes | The routing rule ID |
Examples
Section titled “Examples”import Tokenrouter from 'tokenrouter';
const client = new Tokenrouter({ apiKey: process.env.TOKENROUTER_API_KEY});
await client.routingRules.delete(123);
console.log('Rule deleted successfully');from tokenrouter import Tokenrouter
client = Tokenrouter( api_key=os.getenv("TOKENROUTER_API_KEY"))
client.routing_rules.delete(123)
print("Rule deleted successfully")curl -X DELETE https://api.tokenrouter.io/v1/routing-rules/123 \ -H "Authorization: Bearer tr_..."Response
Section titled “Response”{ "success": true}Error Responses
Section titled “Error Responses”403 Forbidden - Free Plan
Section titled “403 Forbidden - Free Plan”{ "error": { "message": "Routing rules are not available on the free plan", "type": "authorization_error", "http_status": 403 }}404 Not Found
Section titled “404 Not Found”{ "error": { "message": "Routing rule not found", "type": "not_found_error", "http_status": 404 }}Safe Deletion Pattern
Section titled “Safe Deletion Pattern”Always verify before deleting:
// Get rule details firstconst rule = await client.routingRules.retrieve(ruleId);
console.log(`About to delete: ${rule.data.name}`);console.log(`Priority: ${rule.data.priority}`);
// Confirm deletionconst confirmed = confirm('Delete this rule?');
if (confirmed) { await client.routingRules.delete(ruleId); console.log('Rule deleted');}# Get rule details firstrule = client.routing_rules.retrieve(rule_id)
print(f"About to delete: {rule.data.name}")print(f"Priority: {rule.data.priority}")
# Confirm deletionconfirmed = input("Delete this rule? (y/n): ").lower() == 'y'
if confirmed: client.routing_rules.delete(rule_id) print("Rule deleted")Bulk Deletion
Section titled “Bulk Deletion”Delete multiple rules:
// Delete all disabled rulesconst rules = await client.routingRules.list();
const disabledRules = rules.data.filter(r => !r.is_enabled);
for (const rule of disabledRules) { await client.routingRules.delete(rule.id); console.log(`Deleted: ${rule.name}`);}# Delete all disabled rulesrules = client.routing_rules.list()
disabled_rules = [r for r in rules.data if not r.is_enabled]
for rule in disabled_rules: client.routing_rules.delete(rule.id) print(f"Deleted: {rule.name}")Delete with Backup
Section titled “Delete with Backup”Save rule before deleting:
// Backup rule before deletingconst rule = await client.routingRules.retrieve(ruleId);
const backup = { name: rule.data.name, priority: rule.data.priority, is_enabled: rule.data.is_enabled, match_json: rule.data.match_json, action_json: rule.data.action_json};
// Save to file/databaseconsole.log('Backup:', JSON.stringify(backup, null, 2));
// Deleteawait client.routingRules.delete(ruleId);import json
# Backup rule before deletingrule = client.routing_rules.retrieve(rule_id)
backup = { "name": rule.data.name, "priority": rule.data.priority, "is_enabled": rule.data.is_enabled, "match_json": rule.data.match_json, "action_json": rule.data.action_json}
# Save to file/databaseprint("Backup:", json.dumps(backup, indent=2))
# Deleteclient.routing_rules.delete(rule_id)Alternative: Disable Instead
Section titled “Alternative: Disable Instead”Consider disabling rules instead of deleting:
// Instead of deleting, disable the ruleawait client.routingRules.update(ruleId, { is_enabled: false});
// Can be re-enabled later if neededawait client.routingRules.update(ruleId, { is_enabled: true});# Instead of deleting, disable the ruleclient.routing_rules.update(rule_id, is_enabled=False)
# Can be re-enabled later if neededclient.routing_rules.update(rule_id, is_enabled=True)When to Delete vs Disable
Section titled “When to Delete vs Disable”| Scenario | Recommendation |
|---|---|
| Testing a rule | Disable it |
| Seasonal rule (e.g., holiday promotions) | Disable it |
| Temporary override | Disable it |
| Deprecated provider | Delete it |
| Duplicate rule | Delete it |
| Experimental rule that failed | Delete it |
Best Practices
Section titled “Best Practices”- Always get rule details before deleting
- Backup important rules before deletion
- Prefer disabling over deleting when unsure
- Delete in batches carefully to avoid accidents
- Document deletion reasons in your change log