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

# Create an alert rule



## OpenAPI

````yaml POST /v1/alert-rules
openapi: 3.1.0
info:
  title: PolyAI Alerts API
  version: 1.0.0
  description: >-
    Create alert rules, inspect active alerts, register webhook endpoints, and
    receive signed webhook notifications when alert thresholds are breached.
servers:
  - url: https://api.us.poly.ai
    description: US region
  - url: https://api.uk.poly.ai
    description: UK region
  - url: https://api.eu.poly.ai
    description: EU region
security:
  - ApiKeyAuth: []
paths:
  /v1/alert-rules:
    post:
      summary: Create an alert rule
      operationId: createAlertRule
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAlertRuleRequest'
      responses:
        '201':
          description: Alert rule created successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AlertRule'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '409':
          $ref: '#/components/responses/Conflict'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '502':
          $ref: '#/components/responses/BadGateway'
components:
  schemas:
    CreateAlertRuleRequest:
      type: object
      required:
        - name
        - metric
        - operator
        - threshold_value
        - window_duration
      properties:
        name:
          type: string
        project_id:
          type:
            - string
            - 'null'
        metric:
          $ref: '#/components/schemas/Metric'
        operator:
          $ref: '#/components/schemas/ComparisonOperator'
        threshold_value:
          type: integer
          minimum: 0
        window_duration:
          $ref: '#/components/schemas/WindowDuration'
        enabled:
          type: boolean
          default: true
      additionalProperties: false
      example:
        name: High turn latency (p95)
        project_id: proj_abc123
        metric: turn_latency_p95
        operator: '>='
        threshold_value: 1500
        window_duration: 5m
        enabled: true
    AlertRule:
      type: object
      required:
        - id
        - name
        - metric
        - operator
        - threshold_value
        - window_duration
        - enabled
        - current_state
        - created_at
        - updated_at
      properties:
        id:
          type: string
          pattern: ^ar_[A-Za-z0-9]+$
          example: ar_0Kx4mNpQ8rWvYb2dFgHjLs
        name:
          type: string
        project_id:
          type:
            - string
            - 'null'
        metric:
          $ref: '#/components/schemas/Metric'
        operator:
          $ref: '#/components/schemas/ComparisonOperator'
        threshold_value:
          type: integer
          minimum: 0
        window_duration:
          $ref: '#/components/schemas/WindowDuration'
        enabled:
          type: boolean
          default: true
        current_state:
          $ref: '#/components/schemas/AlertState'
        since:
          type:
            - string
            - 'null'
          format: date-time
        last_evaluated_at:
          type:
            - string
            - 'null'
          format: date-time
        current_value:
          type:
            - integer
            - 'null'
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    Metric:
      type: string
      enum:
        - turn_latency_p50
        - turn_latency_p95
        - api_errors
        - function_errors
        - call_crashes
        - call_volume
    ComparisonOperator:
      type: string
      enum:
        - '>'
        - <
        - '>='
        - <=
    WindowDuration:
      type: string
      description: Evaluation window duration
      enum:
        - 5m
        - 10m
        - 60m
    AlertState:
      type: string
      enum:
        - ok
        - alert
        - no_data
        - unknown
    Error:
      type: object
      properties:
        message:
          type: string
  responses:
    BadRequest:
      description: Validation error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Conflict:
      description: >-
        Resource limit exceeded (e.g. maximum number of alert rules or webhook
        endpoints reached).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    UnprocessableEntity:
      description: Validation error or malformed resource ID.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalServerError:
      description: Internal server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    BadGateway:
      description: Monitoring backend sync failure.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````