Skip to content

Update Firewall Rule

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

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

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

ParameterTypeDescription
namestringRule name (max 128 characters)
is_enabledbooleanWhether rule is active
priorityintegerRule priority (-1000 to 1000)
scopestringprompt or response
typestringsubstring or regex
patternstringPattern to match
actionstringblock, mask, or warn
replacementstringReplacement text for mask action
import Tokenrouter from 'tokenrouter';
const client = new Tokenrouter({
apiKey: process.env.TOKENROUTER_API_KEY
});
// Disable a rule
await client.firewallRules.update(123, {
is_enabled: false
});
// Enable a rule
await client.firewallRules.update(123, {
is_enabled: true
});
// Increase priority to make rule execute earlier
await client.firewallRules.update(123, {
priority: 200
});
// Decrease priority
await client.firewallRules.update(123, {
priority: 50
});
// Update pattern to be more specific
await client.firewallRules.update(123, {
pattern: '\\d{4}-\\d{4}-\\d{4}-\\d{4}' // More specific credit card format
});

Example 4: Change Action from Block to Mask

Section titled “Example 4: Change Action from Block to Mask”
// Change from blocking to masking
await client.firewallRules.update(123, {
action: 'mask',
replacement: '[SENSITIVE_DATA_REDACTED]'
});
// Move rule from prompt to response filtering
await client.firewallRules.update(123, {
scope: 'response'
});
await client.firewallRules.update(123, {
name: 'Updated Rule Name',
priority: 150,
is_enabled: true,
pattern: 'new-pattern',
action: 'warn'
});
{
"data": {
"id": 123,
"user_id": 456,
"name": "Updated Rule Name",
"is_enabled": true,
"priority": 150,
"scope": "prompt",
"type": "regex",
"pattern": "new-pattern",
"action": "warn",
"replacement": null,
"created_at": "2025-11-10T12:00:00Z",
"updated_at": "2025-11-10T15:30:00Z"
}
}
{
"error": {
"message": "Firewall rules are not available on the free plan",
"type": "authorization_error",
"http_status": 403
}
}
{
"error": {
"message": "Firewall 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"],
"scope": ["The scope must be either 'prompt' or 'response'"]
}
}
}
// Disable temporarily
await client.firewallRules.update(ruleId, {
is_enabled: false
});
// Test your requests...
// Re-enable
await client.firewallRules.update(ruleId, {
is_enabled: true
});
// Get all rules
const rules = await client.firewallRules.list();
// Find highest priority
const highestPriority = Math.max(...rules.data.map(r => r.priority));
// Make this rule highest priority
await client.firewallRules.update(ruleId, {
priority: highestPriority + 10
});

Gradually soften rule enforcement:

// Step 1: Change from block to warn (test phase)
await client.firewallRules.update(ruleId, {
action: 'warn'
});
// Monitor warnings for a period...
// Step 2: If safe, disable entirely
await client.firewallRules.update(ruleId, {
is_enabled: false
});
// Make replacement text more specific
await client.firewallRules.update(maskRuleId, {
replacement: '[PII_REDACTED_' + new Date().toISOString() + ']'
});
  1. Update one field at a time when testing changes
  2. Disable before major changes to prevent unexpected blocking
  3. Test pattern changes carefully - invalid regex can cause errors
  4. Document changes in your version control or change log
  5. Use descriptive names when renaming rules
  6. Monitor after updates - check logs for unexpected matches
  7. Keep replacement text clear - describe what was masked

Update multiple rules with the same change:

// Disable all warn-action rules
const rules = await client.firewallRules.list();
const warnRules = rules.data.filter(r => r.action === 'warn');
for (const rule of warnRules) {
await client.firewallRules.update(rule.id, {
is_enabled: false
});
console.log(`Disabled: ${rule.name}`);
}