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

# Create a threshold on a metric

> Create a boolean threshold derived from an existing metric. The source metric is addressed by its UUID or its stable `slug`. The threshold fires when the source metric meets the comparison condition. Scope and supported contexts are inherited from the source metric.



## OpenAPI

````yaml /api-reference/openapi.documented.json post /v1/metric/definitions/{idOrSlug}/thresholds
openapi: 3.1.0
info:
  title: Roark Analytics API
  description: >-
    The Roark Analytics API gives you access to the same API that powers the
    award winning Roark Analytics platform.
  version: 1.0.0
servers:
  - description: Production
    url: https://api.roark.ai
security:
  - Bearer: []
tags:
  - name: Agent
  - name: Agent Endpoint
  - name: Call
  - name: Chat
  - name: Metric
  - name: Metric Policy
  - name: Metric Collection Job
  - name: Simulation Persona
  - name: Simulation Scenario
  - name: Simulation Run Plan
  - name: Simulation Run Plan Job
  - name: Simulation Job
  - name: HTTP Request Definition
  - name: Webhook
  - name: Issue
  - name: Knowledge Base
  - name: Call Analysis
  - name: Health
paths:
  /v1/metric/definitions/{idOrSlug}/thresholds:
    post:
      tags:
        - Metric
      summary: Create a threshold on a metric
      description: >-
        Create a boolean threshold derived from an existing metric. The source
        metric is addressed by its UUID or its stable `slug`. The threshold
        fires when the source metric meets the comparison condition. Scope and
        supported contexts are inherited from the source metric.
      operationId: postV1MetricDefinitionsByIdOrSlugThresholds
      parameters:
        - name: idOrSlug
          in: path
          required: true
          description: >-
            The metric definition's Roark ID (UUID) or its stable `slug` (e.g.
            `customer_satisfaction`).
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateThresholdInput'
      responses:
        '201':
          description: The created threshold (as a metric definition)
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/ThresholdMetricResponse'
                required:
                  - data
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Validation error
              example:
                type: validation
                code: invalid_parameter
                message: The request was invalid
                param: email
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Authentication error
              example:
                type: authentication
                code: unauthorized
                message: Authentication required
          description: Unauthorized
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Permission error
              example:
                type: forbidden
                code: permission_denied
                message: You do not have permission to access this resource
          description: Forbidden
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Not found error
              example:
                type: not_found
                code: resource_not_found
                message: The requested resource could not be found
          description: Not Found
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Rate limit error
              example:
                type: rate_limit
                code: too_many_requests
                message: Rate limit exceeded
          description: Too Many Requests
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Server error
              example:
                type: internal
                code: internal_error
                message: Internal server error
          description: Internal Server Error
components:
  schemas:
    CreateThresholdInput:
      type: object
      properties:
        slug:
          type: string
          minLength: 1
          maxLength: 50
          description: Stable slug for the metric. Auto-generated from name if omitted.
          example: customer_satisfaction
        metricId:
          type: string
          minLength: 1
          maxLength: 50
          description: >-
            Alias of `slug` accepted for backwards compatibility. Use `slug` for
            new integrations.
          example: customer_satisfaction
        operator:
          type: string
          enum:
            - GREATER_THAN
            - GREATER_THAN_OR_EQUALS
            - LESS_THAN
            - LESS_THAN_OR_EQUALS
            - EQUALS
            - NOT_EQUALS
          description: Comparison operator
          example: GREATER_THAN_OR_EQUALS
        value:
          type: string
          minLength: 1
          description: Value to compare the source metric against (as a string)
          example: '4'
        aggregationMode:
          type: string
          enum:
            - EACH
            - COUNT
            - AVERAGE
            - MIN
            - MAX
            - MEDIAN
            - P95
            - P99
            - SUM
          default: EACH
          description: >-
            How to aggregate the source metric before applying the comparison
            (default: EACH)
        countThreshold:
          type: integer
          minimum: 0
          description: >-
            Required when aggregationMode is COUNT. The threshold fires when the
            count is met.
        sourceParticipantRole:
          type: string
          enum:
            - AGENT
            - CUSTOMER
            - SIMULATED_CUSTOMER
            - BACKGROUND_SPEAKER
          description: >-
            When the source metric is per-participant, restrict evaluation to
            this role. Only valid for sources with TURN/SEGMENT contexts.
        sourceVariantId:
          type: string
          format: uuid
          description: Variant of the source metric to use
      required:
        - operator
        - value
      description: Input for creating a new threshold derived from a source metric.
    ThresholdMetricResponse:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Unique identifier for the metric definition
        slug:
          type: string
          description: Stable metric slug (e.g. "call_reason", "customer_satisfaction")
        metricId:
          type: string
          description: >-
            Alias of `slug` retained for backwards compatibility. Same value as
            `slug`.
        variantId:
          type: string
          format: uuid
          description: >-
            The resolved variant this response reflects (org-scoped Default if
            the org has customized it, otherwise the system Default). Pass this
            as sourceVariantId when building a derived metric off this one to
            pin the exact config.
        versionId:
          type: string
          format: uuid
          description: >-
            The variant's current version. Immutable snapshot of the config —
            editing the metric produces a new versionId. Use it to detect config
            changes.
        name:
          type: string
          description: Name of the metric
        description:
          type: string
          description: Description of what the metric measures
        type:
          type: string
          enum:
            - COUNT
            - NUMERIC
            - BOOLEAN
            - SCALE
            - TEXT
            - CLASSIFICATION
            - OFFSET
          description: Type of value this metric produces
        scope:
          type: string
          enum:
            - GLOBAL
            - PER_PARTICIPANT
          description: Whether metric is global or per-participant
        supportedContexts:
          type: array
          items:
            type: string
            enum:
              - CALL
              - SEGMENT
              - TURN
          description: Which levels this metric can produce values at
        unit:
          type: object
          properties:
            name:
              type: string
              description: Name of the unit
            symbol:
              type:
                - string
                - 'null'
              description: Symbol for the unit
          required:
            - name
            - symbol
          description: Unit information if applicable
        calculationType:
          type: string
          const: THRESHOLD
          description: >-
            Boolean metric derived by comparing a source metric against a
            threshold.
        threshold:
          $ref: '#/components/schemas/ThresholdMetricDetails'
          description: Threshold configuration.
      required:
        - id
        - slug
        - metricId
        - variantId
        - versionId
        - name
        - description
        - type
        - scope
        - supportedContexts
        - calculationType
      title: Threshold metric
    ErrorResponse:
      type: object
      properties:
        type:
          type: string
          enum:
            - validation
            - authentication
            - forbidden
            - not_found
            - conflict
            - rate_limit
            - internal
          description: The error type category
          examples:
            - validation
            - authentication
        code:
          type: string
          description: Machine-readable error code identifier
          examples:
            - invalid_parameter
            - missing_required_field
            - unauthorized
        message:
          type: string
          description: Human-readable error message
          examples:
            - The request was invalid
            - Authentication required
        param:
          type: string
          description: The parameter that caused the error (if applicable)
          examples:
            - email
            - user_id
        details:
          description: Additional error context information
      required:
        - type
        - code
        - message
    ThresholdMetricDetails:
      type: object
      properties:
        sourceMetricDefinitionId:
          type: string
          format: uuid
        operator:
          type: string
          enum:
            - GREATER_THAN
            - GREATER_THAN_OR_EQUALS
            - LESS_THAN
            - LESS_THAN_OR_EQUALS
            - EQUALS
            - NOT_EQUALS
        thresholdValue:
          type: string
        aggregationMode:
          type: string
          enum:
            - EACH
            - COUNT
            - AVERAGE
            - MIN
            - MAX
            - MEDIAN
            - P95
            - P99
            - SUM
        countThreshold:
          type:
            - integer
            - 'null'
        sourceParticipantRole:
          type:
            - string
            - 'null'
          enum:
            - AGENT
            - CUSTOMER
            - SIMULATED_CUSTOMER
            - BACKGROUND_SPEAKER
        sourceVariantId:
          type:
            - string
            - 'null'
          format: uuid
      required:
        - sourceMetricDefinitionId
        - operator
        - thresholdValue
        - aggregationMode
        - countThreshold
        - sourceParticipantRole
        - sourceVariantId
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer
      bearerFormat: JWT

````