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

# Create a monitor alert rule

> Adds a rule that opens an alert on this monitor when its sessions cross a threshold over a trailing window. The rule watches one metric family or one bound Specification, never both. A Specification rule counts a session once when any metric the Specification brings fails. BAD_SESSION_COUNT and NO_SCORE_RATE are accepted.



## OpenAPI

````yaml https://api.galtea.ai/openapi.json post /monitors/{monitorId}/alert-rules
openapi: 3.0.0
info:
  version: 1.0.0
  title: Product Management Service API
  description: API documentation for Product Management Service
  contact:
    name: Galtea AI
servers:
  - url: https://api.galtea.ai
security:
  - bearerAuth: []
tags: []
externalDocs:
  description: Galtea Platform Documentation
  url: https://docs.galtea.ai
paths:
  /monitors/{monitorId}/alert-rules:
    post:
      tags:
        - monitors
      summary: Create a monitor alert rule
      description: >-
        Adds a rule that opens an alert on this monitor when its sessions cross
        a threshold over a trailing window. The rule watches one metric family
        or one bound Specification, never both. A Specification rule counts a
        session once when any metric the Specification brings fails.
        BAD_SESSION_COUNT and NO_SCORE_RATE are accepted.
      operationId: createMonitorAlertRule
      parameters:
        - schema:
            type: string
            description: Monitor ID
            example: monitor_123
          required: true
          description: Monitor ID
          name: monitorId
          in: path
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMonitorAlertRuleRequest'
      responses:
        '201':
          description: >-
            Alert rule created successfully. The body holds only its id; read
            the rule from the Location path.
          headers:
            Location:
              schema:
                type: string
                description: The path of the new alert rule
              required: true
              description: The path of the new alert rule
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MonitorAlertRuleCreated'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  schemas:
    CreateMonitorAlertRuleRequest:
      type: object
      properties:
        type:
          type: string
          enum:
            - BAD_SESSION_COUNT
            - NO_SCORE_RATE
            - AVERAGE_SCORE
          description: The condition that opens the alert
          example: BAD_SESSION_COUNT
        metricGroupId:
          type: string
          minLength: 1
          description: >-
            A metric family this monitor scores. Mutually exclusive with
            specificationId.
          example: metricGroup_123
        specificationId:
          type: string
          minLength: 1
          description: >-
            A Specification this monitor binds. The rule counts the sessions
            that fail any metric the Specification brings into the monitor.
            Mutually exclusive with metricGroupId.
          example: specification_123
        window:
          type: string
          enum:
            - FIFTEEN_MINUTES
            - ONE_HOUR
            - SIX_HOURS
            - TWENTY_FOUR_HOURS
          description: The trailing window the rule evaluates
          example: ONE_HOUR
        badSessionScore:
          type: number
          nullable: true
          description: >-
            BAD_SESSION_COUNT only: a session counts as bad at or below this
            score. Must be null or left out for NO_SCORE_RATE.
          example: 0.5
        threshold:
          type: number
          description: >-
            The value the rule fires on, by type: a whole count of bad sessions
            for BAD_SESSION_COUNT, a percent above 0 and at most 100 for
            NO_SCORE_RATE
          example: 3
        recipients:
          type: array
          items:
            type: string
          maxItems: 20
          default: []
          description: >-
            Email addresses notified when the rule fires (0 to 20). A rule needs
            at least one address or a webhookUrl.
          example:
            - team@example.com
        webhookUrl:
          type: string
          nullable: true
          minLength: 1
          maxLength: 2048
          description: >-
            URL that receives a signed POST when an alert opens or recovers. It
            must use https, unless the deployment allows http. A Slack
            incoming-webhook URL posts a message to its channel. Write-only:
            responses show only its host and port. On update, null removes it
            and leaving it out keeps it. Read the signing secret with
            regenerate-alert-rule-webhook-secret.
          example: https://hooks.slack.com/services/T000/B000/XXXX
      required:
        - type
        - window
        - threshold
    MonitorAlertRuleCreated:
      type: object
      properties:
        id:
          type: string
          description: The new alert rule
          example: monitorAlertRule_123
      required:
        - id
    Error:
      type: object
      properties:
        error:
          type: string
          example: Error type
        message:
          type: string
          example: Error message description
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        API key authorization. Pass your API key in the Authorization header as
        a Bearer token. Both new (`gsk_*`) and legacy (`gsk-`) API keys are
        accepted, e.g. `Authorization: Bearer gsk_...` or `Authorization: Bearer
        gsk-...`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.