{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/api-reference/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["api-container","api-content","endpoint","api-examples","tabs","tab","code-group"]},"redocly_category":"API Reference","searchWeight":130,"type":"markdown"},"seo":{"title":"Path parameters","description":"Complete API reference and documentation for Freddy AI-powered backend system by Aitronos","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"ApiContainer","attributes":{},"children":[{"$$mdtype":"Tag","name":"ApiContent","attributes":{},"children":[{"$$mdtype":"Tag","name":"Endpoint","attributes":{"method":"PUT","path":"https://api.aitronos.com/v1/organizations/{org_id}/rules-stack"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Atomically replace the organisation's rule stack. Entries are processed in list order — index 0 compiles first. At most one entry may carry ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["is_entity_default=true"]},". Every assistant in the organisation has its rule cache invalidated after the operation."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"path-parameters","__idx":0},"children":["Path parameters"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["org_id"]}]}," string ",{"$$mdtype":"Tag","name":"em","attributes":{"style":{"color":"#ef4444 !important","fontWeight":"600 !important","fontStyle":"normal !important"}},"children":["required"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Organisation ID (prefixed with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["org_"]},")."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"body-parameters","__idx":1},"children":["Body parameters"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["entries"]}]}," array ",{"$$mdtype":"Tag","name":"em","attributes":{"style":{"color":"#9ca3af !important","fontWeight":"500 !important","fontStyle":"normal !important"}},"children":["optional"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["List of stack entries (max 50). Omitting or sending an empty list clears the stack. Each entry is an object with:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["rule_id"]}]}," string ",{"$$mdtype":"Tag","name":"em","attributes":{"style":{"color":"#ef4444 !important","fontWeight":"600 !important","fontStyle":"normal !important"}},"children":["required"]}," — Rule ID to include in the stack (prefixed with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["rule_"]},")."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["priority"]}]}," integer ",{"$$mdtype":"Tag","name":"em","attributes":{"style":{"color":"#9ca3af !important","fontWeight":"500 !important","fontStyle":"normal !important"}},"children":["optional"]}," — Attachment priority (0–100). When omitted, priorities are auto-assigned from list order (index × 10)."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["is_entity_default"]}]}," boolean ",{"$$mdtype":"Tag","name":"em","attributes":{"style":{"color":"#9ca3af !important","fontWeight":"500 !important","fontStyle":"normal !important"}},"children":["optional"]}," — Mark as the org's default rule. At most one entry may be ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["true"]},". Default: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["false"]},"."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"returns","__idx":2},"children":["Returns"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Returns the full updated stack as an array of stack items."]}]},{"$$mdtype":"Tag","name":"ApiExamples","attributes":{},"children":[{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"Request","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeGroup","attributes":{"mode":"dropdown"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -X PUT https://api.aitronos.com/v1/organizations/org_abc123/rules-stack \\\n  -H \"X-API-Key: $FREDDY_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"entries\": [\n      {\"rule_id\": \"rule_xyz\", \"priority\": 0, \"is_entity_default\": true},\n      {\"rule_id\": \"rule_abc\", \"priority\": 10}\n    ]\n  }'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","data-title":"Python SDK","header":{"title":"Python SDK","controls":{"copy":{}}},"source":"from aitronos import Aitronos\n\nclient = Aitronos(api_key=\"your-api-key\")\n\nresult = client.org_rule_stack.replace(\n    org_id=\"org_abc123\",\n    entries=[\n        {\"rule_id\": \"rule_xyz\", \"priority\": 0, \"is_entity_default\": True},\n        {\"rule_id\": \"rule_abc\", \"priority\": 10},\n    ],\n)\nprint(f\"Stack now has {result.total} rules\")\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"import os\nimport requests\n\napi_key = os.environ[\"FREDDY_API_KEY\"]\nresponse = requests.put(\n    \"https://api.aitronos.com/v1/organizations/org_abc123/rules-stack\",\n    headers={\"X-API-Key\": api_key, \"Content-Type\": \"application/json\"},\n    json={\n        \"entries\": [\n            {\"rule_id\": \"rule_xyz\", \"priority\": 0, \"is_entity_default\": True},\n            {\"rule_id\": \"rule_abc\", \"priority\": 10},\n        ]\n    },\n)\nprint(response.json())\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const apiKey = process.env.FREDDY_API_KEY;\n\nconst response = await fetch(\n  \"https://api.aitronos.com/v1/organizations/org_abc123/rules-stack\",\n  {\n    method: \"PUT\",\n    headers: {\n      \"X-API-Key\": apiKey,\n      \"Content-Type\": \"application/json\"\n    },\n    body: JSON.stringify({\n      entries: [\n        { rule_id: \"rule_xyz\", priority: 0, is_entity_default: true },\n        { rule_id: \"rule_abc\", priority: 10 }\n      ]\n    })\n  }\n);\n\nconst data = await response.json();\nconsole.log(data);\n","lang":"javascript"},"children":[]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"Response","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n  \"items\": [\n    {\n      \"attachment_id\": \"att_001\",\n      \"rule_id\": \"rule_xyz\",\n      \"name\": \"Professional Tone\",\n      \"description\": \"Enforce professional language across all assistants\",\n      \"scope\": \"organization\",\n      \"priority\": 0,\n      \"is_active\": true,\n      \"is_entity_default\": true,\n      \"organization_id\": \"org_abc123\"\n    },\n    {\n      \"attachment_id\": \"att_002\",\n      \"rule_id\": \"rule_abc\",\n      \"name\": \"Concise Responses\",\n      \"description\": null,\n      \"scope\": \"organization\",\n      \"priority\": 10,\n      \"is_active\": true,\n      \"is_entity_default\": false,\n      \"organization_id\": \"org_abc123\"\n    }\n  ],\n  \"total\": 2\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"Error","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"RULE_STACK_MULTIPLE_DEFAULTS\",\n    \"message\": \"At most one stack entry may be marked as the default.\",\n    \"type\": \"client_error\",\n    \"status\": 422,\n    \"details\": {\n      \"default_count\": 2\n    },\n    \"trace_id\": \"abc123\",\n    \"timestamp\": \"2025-01-15T10:00:00Z\",\n    \"system_message\": \"Technical error detail for diagnostics\"\n  }\n}\n","lang":"json"},"children":[]}]}]}]}]}]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"related-resources","__idx":3},"children":["Related Resources"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/api-reference/rules/org-stack-list"},"children":["List organisation rule stack"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/api-reference/rules/org-stack-add"},"children":["Add rule to organisation stack"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/api-reference/rules/org-stack-remove"},"children":["Remove rule from organisation stack"]}]}]}]},"headings":[{"value":"Path parameters","id":"path-parameters","depth":2},{"value":"Body parameters","id":"body-parameters","depth":2},{"value":"Returns","id":"returns","depth":2},{"value":"Related Resources","id":"related-resources","depth":2}],"frontmatter":{"title":"Replace organisation rule stack","seo":{"title":"Path parameters"}},"lastModified":"2026-06-29T06:17:30.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/api-reference/rules/org-stack-replace","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}