Create Firewall Rule
Create Firewall Rule
Section titled “Create Firewall Rule”Create a new firewall rule for the authenticated user.
Endpoint
Section titled “Endpoint”POST /v1/firewall-rulesRequest Body
Section titled “Request Body”| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Rule name (max 128 characters) |
is_enabled | boolean | Yes | Whether rule is active |
priority | integer | Yes | Priority (-1000 to 1000, higher = first) |
scope | string | Yes | prompt or response |
type | string | Yes | substring or regex |
pattern | string | Yes | Pattern to match |
action | string | Yes | block, mask, or warn |
replacement | string | No | Replacement text for mask action (default: [redacted]) |
Examples
Section titled “Examples”const rule = await client.firewallRules.create({ name: 'Block Credit Cards', priority: 100, is_enabled: true, scope: 'prompt', type: 'regex', pattern: '\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}', action: 'block'});rule = client.firewall_rules.create( name="Block Credit Cards", priority=100, is_enabled=True, scope="prompt", type="regex", pattern=r"\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}", action="block")curl -X POST https://api.tokenrouter.io/v1/firewall-rules \ -H "Content-Type: application/json" \ -H "Authorization: Bearer tr_..." \ -d '{ "name": "Block Credit Cards", "priority": 100, "is_enabled": true, "scope": "prompt", "type": "regex", "pattern": "\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}", "action": "block" }'Response
Section titled “Response”{ "data": { "id": 123, "user_id": 456, "name": "Block Credit Cards", "is_enabled": true, "priority": 100, "scope": "prompt", "type": "regex", "pattern": "\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}", "action": "block", "replacement": null, "created_at": "2025-11-10T12:00:00Z", "updated_at": "2025-11-10T12:00:00Z" }}Common Patterns
Section titled “Common Patterns”Social Security Numbers
Section titled “Social Security Numbers”pattern: '\\d{3}-\\d{2}-\\d{4}'Email Addresses
Section titled “Email Addresses”pattern: '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}'API Keys
Section titled “API Keys”pattern: '(sk-[a-zA-Z0-9]{32,}|Bearer [a-zA-Z0-9]{32,})'Phone Numbers
Section titled “Phone Numbers”pattern: '\\+?1?\\d{9,15}'