# Create Rule div strong 🔨 In Development — This section is still being developed and may change. Create a new rule that defines AI behavior, formatting guidelines, safety constraints, or other instructions that can be applied to assistants. Rules are reusable instruction sets that control AI assistant behavior. They support priority-based application, context-aware selection, and automatic compression to fit within neuron budgets. #### Request Body **`name`** string required Human-readable name for the rule. Used for identification in lists and logs. Example: `"Professional Communication Standard"`, `"Safety Guidelines"`. **`content`** string required The actual rule content or instructions. Can be plain text or markdown. This content is injected into the system message when the rule is applied. Maximum length: 50,000 characters. **`category`** string optional Categorizes the rule for organization and filtering. Common categories: `safety`, `professional`, `creative`, `technical`, `formatting`, `compliance`, `custom`. **`description`** string optional Optional description explaining the rule's purpose, use cases, and when it should be applied. Helps with rule management and team collaboration. **`priority`** integer optional · Defaults to `3` Rule priority level (1-5) determining application strategy. Lower numbers = higher priority. Values: `1` (Critical - always applied), `2` (High - thread-sticky), `3` (Standard - contextual), `4` (Low - budget-dependent), `5` (Optional - opportunistic). **`characterLimit`** integer optional · Defaults to `10000` Maximum characters allowed for this rule's content. Used for automatic truncation and compression when context budget is limited. Range: 100-50000. **`scope`** string optional · Defaults to `organization` Visibility and access scope for the rule. Values: `organization` (all users in org), `team` (specific team), `user` (private to creator). **`metadata`** object optional Custom key-value pairs for tagging, filtering, and organizing rules. Example: `{"department": "legal", "version": "2.1", "language": "en"}`. Safety Rule ```bash curl https://api.freddy.aitronos.com/v1/rules \ -H "Authorization: Bearer $FREDDY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Content Safety Guidelines", "category": "safety", "priority": 1, "content": "You must never generate content that:\n- Contains harmful or dangerous information\n- Violates privacy or confidentiality\n- Includes discriminatory or offensive language\n- Promotes illegal activities\n\nAlways prioritize user safety and ethical guidelines.", "description": "Critical safety rules that must always be applied" }' ``` ```python import requests response = requests.post( "https://api.freddy.aitronos.com/v1/rules", headers={ "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" }, json={ "name": "Content Safety Guidelines", "category": "safety", "priority": 1, "content": """You must never generate content that: - Contains harmful or dangerous information - Violates privacy or confidentiality - Includes discriminatory or offensive language - Promotes illegal activities Always prioritize user safety and ethical guidelines.""", "description": "Critical safety rules that must always be applied" } ) rule = response.json() print(f"Created rule: {rule['id']}") ``` ```javascript const response = await fetch('https://api.freddy.aitronos.com/v1/rules', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Content Safety Guidelines', category: 'safety', priority: 1, content: `You must never generate content that: - Contains harmful or dangerous information - Violates privacy or confidentiality - Includes discriminatory or offensive language - Promotes illegal activities Always prioritize user safety and ethical guidelines.`, description: 'Critical safety rules that must always be applied' }) }); const rule = await response.json(); console.log(`Created rule: ${rule.id}`); ``` Professional Tone ```bash curl https://api.freddy.aitronos.com/v1/rules \ -H "Authorization: Bearer $FREDDY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Professional Communication Standard", "category": "professional", "priority": 2, "content": "Maintain a professional, courteous tone in all communications:\n- Use proper grammar and punctuation\n- Avoid slang and casual language\n- Be respectful and empathetic\n- Provide clear, structured responses\n- Use appropriate salutations and closings", "characterLimit": 5000, "metadata": { "department": "customer_success", "version": "1.0" } }' ``` ```python import requests response = requests.post( "https://api.freddy.aitronos.com/v1/rules", headers={ "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" }, json={ "name": "Professional Communication Standard", "category": "professional", "priority": 2, "content": """Maintain a professional, courteous tone in all communications: - Use proper grammar and punctuation - Avoid slang and casual language - Be respectful and empathetic - Provide clear, structured responses - Use appropriate salutations and closings""", "characterLimit": 5000, "metadata": { "department": "customer_success", "version": "1.0" } } ) print(f"Rule ID: {response.json()['id']}") ``` ```javascript const response = await fetch('https://api.freddy.aitronos.com/v1/rules', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Professional Communication Standard', category: 'professional', priority: 2, content: `Maintain a professional, courteous tone in all communications: - Use proper grammar and punctuation - Avoid slang and casual language - Be respectful and empathetic - Provide clear, structured responses - Use appropriate salutations and closings`, characterLimit: 5000, metadata: { department: 'customer_success', version: '1.0' } }) }); console.log(`Rule ID: ${(await response.json()).id}`); ``` Technical Documentation ```bash curl https://api.freddy.aitronos.com/v1/rules \ -H "Authorization: Bearer $FREDDY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Technical Documentation Style", "category": "technical", "priority": 3, "content": "When generating technical documentation:\n\n1. **Structure**: Use clear headings and sections\n2. **Code Examples**: Always include working code snippets\n3. **Explanations**: Explain both what and why\n4. **Prerequisites**: List requirements upfront\n5. **Error Handling**: Document common errors and solutions\n6. **Best Practices**: Include tips and recommendations\n\nFormat code blocks with proper syntax highlighting.", "scope": "team", "metadata": { "team": "engineering", "doc_type": "technical" } }' ``` ```python import requests response = requests.post( "https://api.freddy.aitronos.com/v1/rules", headers={ "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" }, json={ "name": "Technical Documentation Style", "category": "technical", "priority": 3, "content": """When generating technical documentation: 1. **Structure**: Use clear headings and sections 2. **Code Examples**: Always include working code snippets 3. **Explanations**: Explain both what and why 4. **Prerequisites**: List requirements upfront 5. **Error Handling**: Document common errors and solutions 6. **Best Practices**: Include tips and recommendations Format code blocks with proper syntax highlighting.""", "scope": "team", "metadata": { "team": "engineering", "doc_type": "technical" } } ) ``` ```javascript const response = await fetch('https://api.freddy.aitronos.com/v1/rules', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Technical Documentation Style', category: 'technical', priority: 3, content: `When generating technical documentation: 1. **Structure**: Use clear headings and sections 2. **Code Examples**: Always include working code snippets 3. **Explanations**: Explain both what and why 4. **Prerequisites**: List requirements upfront 5. **Error Handling**: Document common errors and solutions 6. **Best Practices**: Include tips and recommendations Format code blocks with proper syntax highlighting.`, scope: 'team', metadata: { team: 'engineering', doc_type: 'technical' } }) }); ``` ## Response 201 Created ```json { "id": "rule_abc123", "object": "rule", "name": "Content Safety Guidelines", "category": "safety", "content": "You must never generate content that...", "description": "Critical safety rules that must always be applied", "priority": 1, "characterLimit": 10000, "scope": "organization", "metadata": {}, "organizationId": "org_xyz789", "createdBy": "user_123", "createdAt": "2024-10-04T12:00:00Z", "updatedAt": "2024-10-04T12:00:00Z", "processingStatus": "completed", "validationStatus": "valid", "rulesCount": 5, "characterCount": 342 } ``` Errors ```json { "error": { "type": "invalid_request_error", "message": "Rule content exceeds maximum length of 50,000 characters", "code": "content_too_long", "param": "content" } } ``` ```json { "error": { "type": "invalid_request_error", "message": "Invalid priority value. Must be between 1 and 5", "code": "invalid_priority", "param": "priority" } } ``` ```json { "error": { "type": "authentication_error", "message": "Invalid API key", "code": "invalid_api_key" } } ```