title: Create a new rule keywords: - create a new rule - post - create - new - rule # Create a new rule Create a new rule within an organization. The creator automatically receives owner access. #### Path Parameters **`org_id`** string required The org id parameter. #### Request Body **`name`** string required Rule name **`content`** string required Rule content (max 50KB) **`description`** string optional Rule description **`category`** RuleCategory optional Rule category **`rule_type`** RuleType optional Rule type **`scope`** RuleScopeAPI optional Rule scope (global scope restricted - admin only) **`apply_mode`** ApplyMode optional Rule apply mode **`is_public`** boolean optional · Defaults to `false` Whether rule is public **`is_active`** boolean optional · Defaults to `true` Whether rule is active **`attachments`** array of AttachmentCreateInline optional Optional list of entities to attach to this rule upon creation ## Returns **`id`** string Rule ID with rule_ prefix **`name`** string Rule name **`description`** string or null Rule description **`content`** string Full rule content **`content_length`** integer Total character count of content **`category`** string or null Rule category **`rule_type`** string or null Rule type **`scope`** string or null Rule scope **`apply_mode`** string or null Rule apply mode **`organization_id`** string Organization ID **`created_by`** string User ID who created the rule **`is_public`** boolean Whether rule is public **`is_active`** boolean Whether rule is active **`version`** integer Rule version number **`usage_count`** integer Number of active attachments **`can_edit`** boolean Whether current user can edit this rule **`created_at`** string Creation timestamp **`updated_at`** string Last update timestamp **`attached_entities`** array of object or null List of attached entities Example ```bash cURL curl -X POST "https://api.aitronos.com/v1/organizations/{org_id}/rules" \ -H "X-API-Key: $FREDDY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "your_name", "content": "your_content" }' ``` ```python Python SDK from aitronos import Aitronos client = Aitronos(api_key="your-api-key") rule = client.rules.create_rule( "org_abc123", name="Customer Support Guidelines", content="Always be polite and professional.", ) print(rule.id) ``` ```python Python import os import requests api_key = os.environ["FREDDY_API_KEY"] response = requests.post( "https://api.aitronos.com/v1/organizations/{org_id}/rules", headers={"X-API-Key": api_key}, json={'name': 'your_name', 'content': 'your_content'} ) print(response.json()) ``` ```javascript JavaScript const apiKey = process.env.FREDDY_API_KEY; const response = await fetch('https://api.aitronos.com/v1/organizations/{org_id}/rules', { method: 'POST', headers: { 'X-API-Key': apiKey, 'Content-Type': 'application/json' }, body: JSON.stringify({"name": "your_name", "content": "your_content"}) }); const data = await response.json(); console.log(data); ``` **Response:** ```json 201 OK { "id": "rule_abc123def456", "name": "My Resource", "description": "A description of the resource", "content": "Response content", "content_length": 1, "category": "general", "rule_type": "default", "scope": "organization", "apply_mode": "default", "organization_id": "org_abc123def456", "created_by": "example_created_by", "is_public": true, "is_active": true, "version": 1, "usage_count": 42, "can_edit": false, "created_at": "2025-11-15T10:30:00Z", "updated_at": "2025-11-15T10:30:00Z", "attached_entities": [ { "id": "abc123def456", "entity_type": "default", "entity_id": "abc123def456", "priority": 1, "is_active": true } ] } ``` Errors ```json 401 Unauthorized { "success": false, "error": { "code": "AUTHENTICATION_REQUIRED", "message": "Authentication required. Please provide a valid API key.", "system_message": "Missing or invalid authorization header", "type": "authentication_error", "status": 401, "trace_id": "req_abc123xyz", "timestamp": "2025-11-11T10:30:00Z", "details": {} } } ``` ```json 403 Forbidden { "success": false, "error": { "code": "INSUFFICIENT_PERMISSIONS", "message": "You do not have permission to access this resource.", "system_message": "Insufficient permissions for this operation", "type": "authorization_error", "status": 403, "trace_id": "req_def456uvw", "timestamp": "2025-11-11T10:30:00Z", "details": {} } } ``` ## Related Resources - [Create Rule](/docs/api-reference/rules/create) - [List Rules](/docs/api-reference/rules/list)