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

# Create an alert

> Create an alert in a project. The project is identified by the `project_id` path parameter
alone; the `x-hh-project-id` header does not participate. The alert's `filters` and
`projections` (metrics) are mapped against the project's logged-event schema; if no schema
data matches them — e.g. no events have been logged to the project yet — the request fails
with a 400.




## OpenAPI

````yaml https://raw.githubusercontent.com/honeyhiveai/honeyhive-openapi/main/control_plane_openapi.yaml post /v1/projects/{project_id}/alerts
openapi: 3.1.0
info:
  title: HoneyHive Control Plane API
  description: >
    Manage HoneyHive control-plane resources: projects and alerts.


    Authentication requires a fine-grained control-plane API key (values

    start with `hh_fgcp_`), sent as `Authorization: Bearer <api-key>`.

    Project API keys used with the Data Plane API will not work here. Create

    a key in the HoneyHive app under an organization's or workspace's

    **Settings → API Keys**, or see

    [Authorization](https://docs.honeyhive.ai/v2/control-plane-sdk-reference/typescript#authorization)

    for details.
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
  version: 1.7.0
servers:
  - url: https://api.cp.us.honeyhive.ai
security:
  - BearerAuth: []
tags:
  - name: Alerts
    description: >
      Define and manage alerts. Alerts evaluate event metrics on a schedule and
      trigger notifications when configured thresholds are crossed.
  - name: Projects
    description: >
      Create and manage projects within a workspace. A project is the container
      for the events, datasets, evaluations, and alerts logged against it.
paths:
  /v1/projects/{project_id}/alerts:
    post:
      tags:
        - Alerts
      summary: Create an alert
      description: >
        Create an alert in a project. The project is identified by the
        `project_id` path parameter

        alone; the `x-hh-project-id` header does not participate. The alert's
        `filters` and

        `projections` (metrics) are mapped against the project's logged-event
        schema; if no schema

        data matches them — e.g. no events have been logged to the project yet —
        the request fails

        with a 400.
      operationId: createAlert
      parameters:
        - in: path
          name: project_id
          required: true
          schema:
            type: string
          description: The unique identifier of the project the alert is created in
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PostAlertRequest'
      responses:
        '200':
          description: Alert created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateAlertResponse'
        '400':
          description: >-
            Invalid request body, or no schema data matches the selected
            filters/metrics
        '404':
          description: Project not found
components:
  schemas:
    PostAlertRequest:
      type: object
      properties:
        name:
          type: string
          minLength: 1
        description:
          type: string
        frequency:
          type: string
          enum:
            - HOURLY
            - DAILY
            - WEEKLY
            - MONTHLY
        minimum_sample_size:
          type: integer
          default: 0
        alert_type:
          type: string
          enum:
            - DRIFT
            - AGGREGATE
            - PER_EVENT
          default: AGGREGATE
        aggregation:
          type: string
          enum:
            - AVERAGE
            - COUNT
            - SUM
            - MIN
            - MAX
            - P90
            - P95
            - P99
            - MEDIAN
          default: AVERAGE
        thresholds:
          $ref: '#/components/schemas/PostAlertRequestThresholds'
        filters:
          type: array
          items:
            $ref: '#/components/schemas/SingleFilter'
        projections:
          type: array
          items:
            type: string
        notification_details:
          $ref: '#/components/schemas/PostAlertRequestNotificationDetails'
        status:
          type: string
          enum:
            - ACTIVE
            - TRIGGERED
            - PAUSED
            - RESOLVED
      required:
        - name
        - frequency
        - thresholds
        - filters
        - projections
        - notification_details
      additionalProperties: false
    CreateAlertResponse:
      type: object
      properties:
        success:
          type: boolean
          enum:
            - true
        data:
          $ref: '#/components/schemas/AlertItem'
      required:
        - success
        - data
      additionalProperties: false
      description: The created alert
    PostAlertRequestThresholds:
      type: object
      properties:
        critical:
          $ref: '#/components/schemas/PostAlertRequestThresholdsCritical'
        resolved:
          $ref: '#/components/schemas/PostAlertRequestThresholdsResolved'
      required:
        - critical
        - resolved
      additionalProperties: false
    SingleFilter:
      type: object
      properties:
        field:
          type: string
        operator:
          type: string
          enum:
            - exists
            - not exists
            - is
            - is not
            - contains
            - not contains
            - greater than
            - less than
            - after
            - before
        value:
          anyOf:
            - type: string
            - type: number
            - type: boolean
            - type: 'null'
        type:
          type: string
          enum:
            - string
            - number
            - boolean
            - datetime
      required:
        - field
        - operator
        - value
        - type
    PostAlertRequestNotificationDetails:
      type: object
      properties:
        critical:
          $ref: '#/components/schemas/PostAlertRequestNotificationDetailsCritical'
        resolved:
          $ref: '#/components/schemas/PostAlertRequestNotificationDetailsResolved'
      required:
        - critical
        - resolved
      additionalProperties: false
    AlertItem:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        description:
          type:
            - string
            - 'null'
        status:
          type: string
          enum:
            - ACTIVE
            - TRIGGERED
            - PAUSED
            - RESOLVED
        frequency:
          type: string
          enum:
            - HOURLY
            - DAILY
            - WEEKLY
            - MONTHLY
        minimum_sample_size:
          type: integer
        alert_type:
          type: string
          enum:
            - DRIFT
            - AGGREGATE
            - PER_EVENT
        aggregation:
          type: string
        event_filters:
          type: array
          items:
            $ref: '#/components/schemas/AlertEventFilter'
        event_metrics:
          type: array
          items:
            $ref: '#/components/schemas/AlertEventMetric'
        thresholds:
          $ref: '#/components/schemas/AlertItemThresholds'
        last_run_at:
          anyOf:
            - type: string
              format: date-time
            - type: string
            - type: 'null'
        last_result:
          type:
            - object
            - 'null'
          properties:
            current_bucket_score:
              anyOf:
                - type: number
                - type: boolean
            previous_bucket_score:
              anyOf:
                - type: number
                - type: boolean
            last_triggered_baseline:
              anyOf:
                - type: number
                - type: boolean
            drift_percentage:
              type: number
            thresholds:
              $ref: '#/components/schemas/AlertItemLastResultThresholds'
            event_filters:
              type: array
              items: {}
            event_metrics:
              type: array
              items: {}
            aggregation:
              type: string
          additionalProperties: {}
        trigger_error:
          type:
            - string
            - 'null'
        is_active:
          type: boolean
        is_muted:
          type: boolean
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: string
        updated_at:
          anyOf:
            - type: string
              format: date-time
            - type: string
            - type: 'null'
        last_trigger_id:
          type:
            - string
            - 'null'
        scope_type:
          type: string
        scope_id:
          type: string
        created_by:
          type:
            - string
            - 'null'
        last_trigger:
          $ref: '#/components/schemas/AlertTrigger'
        triggers:
          type: array
          items:
            $ref: '#/components/schemas/AlertTrigger'
        notifications:
          type: array
          items:
            $ref: '#/components/schemas/AlertNotification'
      required:
        - id
        - name
        - status
        - frequency
        - minimum_sample_size
        - alert_type
        - aggregation
        - event_filters
        - event_metrics
        - thresholds
        - is_active
        - is_muted
        - created_at
        - scope_type
        - scope_id
      additionalProperties: false
      description: Alert object
    PostAlertRequestThresholdsCritical:
      type: object
      properties:
        operator:
          type: string
          enum:
            - greater_than
            - less_than
            - equal_to
        value:
          type: number
      required:
        - operator
        - value
      additionalProperties: false
    PostAlertRequestThresholdsResolved:
      type: object
      properties:
        operator:
          type: string
          enum:
            - greater_than
            - less_than
            - equal_to
        value:
          type: number
      required:
        - operator
        - value
      additionalProperties: false
    PostAlertRequestNotificationDetailsCritical:
      type: object
      properties:
        channel:
          type: string
          enum:
            - EMAIL
            - SLACK
            - WEBHOOK
        scope:
          type: string
          enum:
            - ALL_PROJECT_MEMBERS
            - SPECIFIC_MEMBER
        user_ids:
          type: array
          items:
            type: string
        metadata:
          type: object
          additionalProperties: {}
      required:
        - channel
        - scope
        - metadata
      additionalProperties: false
    PostAlertRequestNotificationDetailsResolved:
      type: object
      properties:
        channel:
          type: string
          enum:
            - EMAIL
            - SLACK
            - WEBHOOK
        scope:
          type: string
          enum:
            - ALL_PROJECT_MEMBERS
            - SPECIFIC_MEMBER
        user_ids:
          type: array
          items:
            type: string
        metadata:
          type: object
          additionalProperties: {}
      required:
        - channel
        - scope
        - metadata
      additionalProperties: false
    AlertEventFilter:
      type: object
      properties:
        filter:
          $ref: '#/components/schemas/SingleFilter'
        type:
          type: string
          enum:
            - float
            - numeric
            - boolean
            - string
            - 'null'
      required:
        - filter
        - type
      additionalProperties: false
    AlertEventMetric:
      type: object
      properties:
        projection:
          type: string
          description: Projected field or metric for this entry
        type:
          type: string
          enum:
            - float
            - numeric
            - boolean
            - string
            - 'null'
      required:
        - projection
        - type
      additionalProperties: false
    AlertItemThresholds:
      type: object
      properties:
        critical:
          $ref: '#/components/schemas/AlertItemThresholdsCritical'
        resolved:
          $ref: '#/components/schemas/AlertItemThresholdsResolved'
      required:
        - critical
        - resolved
      additionalProperties: false
    AlertItemLastResultThresholds:
      type: object
      properties:
        critical:
          $ref: '#/components/schemas/AlertItemLastResultThresholdsCritical'
        resolved:
          $ref: '#/components/schemas/AlertItemLastResultThresholdsResolved'
      required:
        - critical
        - resolved
      additionalProperties: false
    AlertTrigger:
      type: object
      properties:
        id:
          type: string
        alert_id:
          type: string
        result:
          $ref: '#/components/schemas/AlertTriggerResult'
        muted:
          type: boolean
        notification_sent:
          type: boolean
        triggered_time:
          anyOf:
            - type: string
              format: date-time
            - type: string
        resolved_time:
          anyOf:
            - type: string
              format: date-time
            - type: string
            - type: 'null'
        resolved_by:
          type:
            - string
            - 'null'
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: string
        updated_at:
          anyOf:
            - type: string
              format: date-time
            - type: string
      required:
        - id
        - alert_id
        - result
        - muted
        - notification_sent
        - triggered_time
        - resolved_time
        - resolved_by
        - created_at
        - updated_at
      additionalProperties: false
    AlertNotification:
      type: object
      properties:
        id:
          type: string
        alert_id:
          type: string
        stage:
          type: string
          enum:
            - CRITICAL
            - RESOLUTION
        channel:
          type: string
          enum:
            - EMAIL
            - SLACK
            - WEBHOOK
        scope:
          type: string
          enum:
            - ALL_PROJECT_MEMBERS
            - SPECIFIC_MEMBER
        membership_id:
          type:
            - string
            - 'null'
        metadata:
          type:
            - object
            - 'null'
          additionalProperties: {}
        last_sent_at:
          anyOf:
            - type: string
              format: date-time
            - type: string
            - type: 'null'
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: string
        membership:
          type:
            - object
            - 'null'
          properties:
            user:
              $ref: '#/components/schemas/AlertNotificationMembershipUser'
          required:
            - user
          additionalProperties: false
      required:
        - id
        - alert_id
        - stage
        - channel
        - scope
        - created_at
      additionalProperties: false
    AlertItemThresholdsCritical:
      type: object
      properties:
        operator:
          type: string
          enum:
            - greater_than
            - less_than
            - equal_to
        value:
          type: number
      required:
        - operator
        - value
      additionalProperties: false
    AlertItemThresholdsResolved:
      type: object
      properties:
        operator:
          type: string
          enum:
            - greater_than
            - less_than
            - equal_to
        value:
          type: number
      required:
        - operator
        - value
      additionalProperties: false
    AlertItemLastResultThresholdsCritical:
      type: object
      properties:
        operator:
          type: string
          enum:
            - greater_than
            - less_than
            - equal_to
        value:
          type: number
      required:
        - operator
        - value
      additionalProperties: false
    AlertItemLastResultThresholdsResolved:
      type: object
      properties:
        operator:
          type: string
          enum:
            - greater_than
            - less_than
            - equal_to
        value:
          type: number
      required:
        - operator
        - value
      additionalProperties: false
    AlertTriggerResult:
      type: object
      properties:
        current_bucket_score:
          anyOf:
            - type: number
            - type: boolean
        previous_bucket_score:
          anyOf:
            - type: number
            - type: boolean
        last_triggered_baseline:
          anyOf:
            - type: number
            - type: boolean
        drift_percentage:
          type: number
        thresholds:
          $ref: '#/components/schemas/AlertTriggerResultThresholds'
        event_filters:
          type: array
          items: {}
        event_metrics:
          type: array
          items: {}
        aggregation:
          type: string
      additionalProperties: {}
    AlertNotificationMembershipUser:
      type: object
      properties:
        id:
          type: string
      required:
        - id
      additionalProperties: false
    AlertTriggerResultThresholds:
      type: object
      properties:
        critical:
          $ref: '#/components/schemas/AlertTriggerResultThresholdsCritical'
        resolved:
          $ref: '#/components/schemas/AlertTriggerResultThresholdsResolved'
      required:
        - critical
        - resolved
      additionalProperties: false
    AlertTriggerResultThresholdsCritical:
      type: object
      properties:
        operator:
          type: string
          enum:
            - greater_than
            - less_than
            - equal_to
        value:
          type: number
      required:
        - operator
        - value
      additionalProperties: false
    AlertTriggerResultThresholdsResolved:
      type: object
      properties:
        operator:
          type: string
          enum:
            - greater_than
            - less_than
            - equal_to
        value:
          type: number
      required:
        - operator
        - value
      additionalProperties: false
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````