Update Firewall Rule
Update Firewall Rule
Section titled “Update Firewall Rule”Updates an existing firewall rule. All fields are optional - only provide the fields you want to change.
Endpoint
Section titled “Endpoint”PATCH /v1/firewall-rules/{id}Path Parameters
Section titled “Path Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
id | integer | Yes | The firewall rule ID |
Request Body
Section titled “Request Body”All fields are optional. Only include fields you want to update:
| Parameter | Type | Description |
|---|---|---|
name | string | Rule name (max 128 characters) |
is_enabled | boolean | Whether rule is active |
priority | integer | Rule priority (-1000 to 1000) |
scope | string | prompt or response |
type | string | substring or regex |
pattern | string | Pattern to match |
action | string | block, mask, or warn |
replacement | string | Replacement text for mask action |
Examples
Section titled “Examples”Example 1: Enable/Disable Rule
Section titled “Example 1: Enable/Disable Rule”import Tokenrouter from 'tokenrouter';
const client = new Tokenrouter({ apiKey: process.env.TOKENROUTER_API_KEY});
// Disable a ruleawait client.firewallRules.update(123, { is_enabled: false});
// Enable a ruleawait client.firewallRules.update(123, { is_enabled: true});from tokenrouter import Tokenrouter
client = Tokenrouter( api_key=os.getenv("TOKENROUTER_API_KEY"))
# Disable a ruleclient.firewall_rules.update(123, is_enabled=False)
# Enable a ruleclient.firewall_rules.update(123, is_enabled=True)# Disable a rulecurl -X PATCH https://api.tokenrouter.io/v1/firewall-rules/123 \ -H "Content-Type: application/json" \ -H "Authorization: Bearer tr_..." \ -d '{"is_enabled": false}'Example 2: Change Priority
Section titled “Example 2: Change Priority”// Increase priority to make rule execute earlierawait client.firewallRules.update(123, { priority: 200});
// Decrease priorityawait client.firewallRules.update(123, { priority: 50});# Increase priority to make rule execute earlierclient.firewall_rules.update(123, priority=200)
# Decrease priorityclient.firewall_rules.update(123, priority=50)curl -X PATCH https://api.tokenrouter.io/v1/firewall-rules/123 \ -H "Content-Type: application/json" \ -H "Authorization: Bearer tr_..." \ -d '{"priority": 200}'Example 3: Update Pattern
Section titled “Example 3: Update Pattern”// Update pattern to be more specificawait client.firewallRules.update(123, { pattern: '\\d{4}-\\d{4}-\\d{4}-\\d{4}' // More specific credit card format});# Update pattern to be more specificclient.firewall_rules.update( 123, pattern=r"\d{4}-\d{4}-\d{4}-\d{4}" # More specific credit card format)curl -X PATCH https://api.tokenrouter.io/v1/firewall-rules/123 \ -H "Content-Type: application/json" \ -H "Authorization: Bearer tr_..." \ -d '{"pattern": "\\d{4}-\\d{4}-\\d{4}-\\d{4}"}'Example 4: Change Action from Block to Mask
Section titled “Example 4: Change Action from Block to Mask”// Change from blocking to maskingawait client.firewallRules.update(123, { action: 'mask', replacement: '[SENSITIVE_DATA_REDACTED]'});# Change from blocking to maskingclient.firewall_rules.update( 123, action="mask", replacement="[SENSITIVE_DATA_REDACTED]")curl -X PATCH https://api.tokenrouter.io/v1/firewall-rules/123 \ -H "Content-Type: application/json" \ -H "Authorization: Bearer tr_..." \ -d '{ "action": "mask", "replacement": "[SENSITIVE_DATA_REDACTED]" }'Example 5: Change Scope
Section titled “Example 5: Change Scope”// Move rule from prompt to response filteringawait client.firewallRules.update(123, { scope: 'response'});# Move rule from prompt to response filteringclient.firewall_rules.update(123, scope="response")curl -X PATCH https://api.tokenrouter.io/v1/firewall-rules/123 \ -H "Content-Type: application/json" \ -H "Authorization: Bearer tr_..." \ -d '{"scope": "response"}'Example 6: Update Multiple Fields
Section titled “Example 6: Update Multiple Fields”await client.firewallRules.update(123, { name: 'Updated Rule Name', priority: 150, is_enabled: true, pattern: 'new-pattern', action: 'warn'});client.firewall_rules.update( 123, name="Updated Rule Name", priority=150, is_enabled=True, pattern="new-pattern", action="warn")curl -X PATCH https://api.tokenrouter.io/v1/firewall-rules/123 \ -H "Content-Type: application/json" \ -H "Authorization: Bearer tr_..." \ -d '{ "name": "Updated Rule Name", "priority": 150, "is_enabled": true, "pattern": "new-pattern", "action": "warn" }'Response
Section titled “Response”{ "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 Responses
Section titled “Error Responses”403 Forbidden - Free Plan
Section titled “403 Forbidden - Free Plan”{ "error": { "message": "Firewall rules are not available on the free plan", "type": "authorization_error", "http_status": 403 }}404 Not Found
Section titled “404 Not Found”{ "error": { "message": "Firewall rule not found", "type": "not_found_error", "http_status": 404 }}422 Validation Error
Section titled “422 Validation Error”{ "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'"] } }}Practical Patterns
Section titled “Practical Patterns”Temporarily Disable for Testing
Section titled “Temporarily Disable for Testing”// Disable temporarilyawait client.firewallRules.update(ruleId, { is_enabled: false});
// Test your requests...
// Re-enableawait client.firewallRules.update(ruleId, { is_enabled: true});# Disable temporarilyclient.firewall_rules.update(rule_id, is_enabled=False)
# Test your requests...
# Re-enableclient.firewall_rules.update(rule_id, is_enabled=True)Adjust Priority Relative to Others
Section titled “Adjust Priority Relative to Others”// Get all rulesconst rules = await client.firewallRules.list();
// Find highest priorityconst highestPriority = Math.max(...rules.data.map(r => r.priority));
// Make this rule highest priorityawait client.firewallRules.update(ruleId, { priority: highestPriority + 10});# Get all rulesrules = client.firewall_rules.list()
# Find highest priorityhighest_priority = max(rule.priority for rule in rules.data)
# Make this rule highest priorityclient.firewall_rules.update(rule_id, priority=highest_priority + 10)Transition from Block to Warn
Section titled “Transition from Block to Warn”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 entirelyawait client.firewallRules.update(ruleId, { is_enabled: false});# Step 1: Change from block to warn (test phase)client.firewall_rules.update(rule_id, action="warn")
# Monitor warnings for a period...
# Step 2: If safe, disable entirelyclient.firewall_rules.update(rule_id, is_enabled=False)Update Replacement Text
Section titled “Update Replacement Text”// Make replacement text more specificawait client.firewallRules.update(maskRuleId, { replacement: '[PII_REDACTED_' + new Date().toISOString() + ']'});from datetime import datetime
# Make replacement text more specificclient.firewall_rules.update( mask_rule_id, replacement=f"[PII_REDACTED_{datetime.now().isoformat()}]")Best Practices
Section titled “Best Practices”- Update one field at a time when testing changes
- Disable before major changes to prevent unexpected blocking
- Test pattern changes carefully - invalid regex can cause errors
- Document changes in your version control or change log
- Use descriptive names when renaming rules
- Monitor after updates - check logs for unexpected matches
- Keep replacement text clear - describe what was masked
Bulk Updates
Section titled “Bulk Updates”Update multiple rules with the same change:
// Disable all warn-action rulesconst 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}`);}# Disable all warn-action rulesrules = client.firewall_rules.list()
warn_rules = [r for r in rules.data if r.action == "warn"]
for rule in warn_rules: client.firewall_rules.update(rule.id, is_enabled=False) print(f"Disabled: {rule.name}")