> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xenovia.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Create alert rule

> **Auth:** signed-in organization admin only. Organization API keys are rejected with `403`.

Event rules fire per matching telemetry event; metric rules evaluate a windowed aggregate. At most 25 enabled rules per organization (`400`).



## OpenAPI

````yaml https://cp.xenovia.io/openapi.json post /api/v1/alert-rules
openapi: 3.1.0
info:
  title: Xenovia Control Plane API
  version: 1.0.0
  description: >-
    Management API for proxies, providers, policies, telemetry, alerts and
    organization settings.
servers:
  - url: https://cp.xenovia.io
    description: Production
security:
  - BearerAuth: []
paths:
  /api/v1/alert-rules:
    post:
      tags:
        - alerts
      summary: Create alert rule
      description: >-
        **Auth:** signed-in organization admin only. Organization API keys are
        rejected with `403`.


        Event rules fire per matching telemetry event; metric rules evaluate a
        windowed aggregate. At most 25 enabled rules per organization (`400`).
      operationId: create_alert_rule_route_api_v1_alert_rules_post
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AlertRuleCreate'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AlertRuleRead'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    AlertRuleCreate:
      properties:
        name:
          type: string
          maxLength: 255
          minLength: 1
          title: Name
        kind:
          type: string
          enum:
            - event
            - metric
          title: Kind
          default: event
        trigger_type:
          anyOf:
            - type: string
              enum:
                - policy_block
                - policy_redact
                - policy_escalate
                - guardrail_escalate
                - guardrail_block
                - high_latency
                - high_intent_score
                - run_error
                - turn_blocked
                - turn_escalated
                - turn_error
            - type: 'null'
          title: Trigger Type
        threshold:
          anyOf:
            - type: number
            - type: 'null'
          title: Threshold
        severity:
          type: string
          enum:
            - info
            - warning
            - critical
          title: Severity
          default: warning
        cooldown_seconds:
          type: integer
          maximum: 86400
          minimum: 60
          title: Cooldown Seconds
          default: 300
        metric:
          anyOf:
            - type: string
              enum:
                - turn_error_rate
                - turn_blocked_rate
                - escalation_count
                - turn_count
                - no_traffic
                - token_usage
                - llm_latency_p95_ms
                - ttft_p95_ms
                - llm_cost_usd
                - guardrail_score_avg
                - guardrail_block_count
                - policy_block_rate
            - type: 'null'
          title: Metric
        aggregation:
          anyOf:
            - type: string
            - type: 'null'
          title: Aggregation
        operator:
          anyOf:
            - type: string
              enum:
                - gt
                - gte
                - lt
                - lte
            - type: 'null'
          title: Operator
        window_seconds:
          anyOf:
            - type: integer
              enum:
                - 300
                - 900
                - 3600
                - 86400
            - type: 'null'
          title: Window Seconds
        group_by:
          anyOf:
            - type: string
              enum:
                - proxy_id
                - policy_rule
                - guardrail_name
            - type: 'null'
          title: Group By
        min_samples:
          type: integer
          maximum: 100000
          minimum: 0
          title: Min Samples
          default: 0
        filters:
          additionalProperties:
            type: string
          type: object
          title: Filters
        channels:
          items:
            type: string
            enum:
              - in_app
              - email
              - slack
          type: array
          title: Channels
        proxy_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Proxy Id
        enabled:
          type: boolean
          title: Enabled
          default: true
      type: object
      required:
        - name
      title: AlertRuleCreate
    AlertRuleRead:
      properties:
        id:
          type: string
          format: uuid
          title: Id
        org_id:
          type: string
          format: uuid
          title: Org Id
        proxy_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Proxy Id
        name:
          type: string
          title: Name
        kind:
          type: string
          title: Kind
        trigger_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Trigger Type
        threshold:
          anyOf:
            - type: number
            - type: 'null'
          title: Threshold
        severity:
          type: string
          title: Severity
        cooldown_seconds:
          type: integer
          title: Cooldown Seconds
        metric:
          anyOf:
            - type: string
            - type: 'null'
          title: Metric
        aggregation:
          anyOf:
            - type: string
            - type: 'null'
          title: Aggregation
        operator:
          anyOf:
            - type: string
            - type: 'null'
          title: Operator
        window_seconds:
          anyOf:
            - type: integer
            - type: 'null'
          title: Window Seconds
        group_by:
          anyOf:
            - type: string
            - type: 'null'
          title: Group By
        min_samples:
          type: integer
          title: Min Samples
        filters:
          additionalProperties:
            type: string
          type: object
          title: Filters
        channels:
          items:
            type: string
          type: array
          title: Channels
        enabled:
          type: boolean
          title: Enabled
        created_by:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Created By
        created_at:
          type: string
          format: date-time
          title: Created At
        updated_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Updated At
      type: object
      required:
        - id
        - org_id
        - proxy_id
        - name
        - kind
        - trigger_type
        - threshold
        - severity
        - cooldown_seconds
        - metric
        - aggregation
        - operator
        - window_seconds
        - group_by
        - min_samples
        - filters
        - channels
        - enabled
        - created_by
        - created_at
        - updated_at
      title: AlertRuleRead
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer token: an organization API key (`ak_…`) created under Settings →
        API Keys, or a dashboard user session token. Proxy keys (`xe_…`) are not
        accepted here. Endpoints marked as user-only in their description reject
        organization keys with `403`.

````