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

# Create metric baseline

> Create a new anomaly-detection baseline for a specific metric.



## OpenAPI

````yaml /api-reference/v1/metrics-v1.yaml post /metrics/{metric_id}/baselines
openapi: 3.0.3
info:
  title: Coval Metrics API
  version: 1.0.0
  description: |
    Manage custom evaluation metrics for agent testing and monitoring.
  contact:
    name: Coval API Support
    email: support@coval.dev
    url: https://docs.coval.ai
  license:
    name: Proprietary
    url: https://coval.dev/terms
servers:
  - url: https://api.coval.dev/v1
    description: Production API
security:
  - ApiKeyAuth: []
tags:
  - name: Metrics
    description: CRUD operations for custom evaluation metrics
paths:
  /metrics/{metric_id}/baselines:
    post:
      tags:
        - Metrics
      summary: Create metric baseline
      description: Create a new anomaly-detection baseline for a specific metric.
      operationId: createMetricBaseline
      parameters:
        - name: metric_id
          in: path
          required: true
          schema:
            type: string
            pattern: ^[a-zA-Z0-9]{22}$
          description: 22-character metric ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMetricBaselineRequest'
            examples:
              ewmaBaseline:
                summary: EWMA baseline (above-threshold anomalies)
                value:
                  agent_id: gk3jK9mPq2xRt5vW8yZaBc
                  test_set_id: 01HXKZ4M5N6P7Q8R9TESTSET01
                  display_name: Resolution rate baseline
                  status: ACTIVE
                  detection_method: EWMA
                  sigma_threshold: 2.5
                  direction: ABOVE
                  config:
                    time_constant_seconds: 604800
              monitoringBaseline:
                summary: Monitoring baseline (no test set)
                value:
                  agent_id: gk3jK9mPq2xRt5vW8yZaBc
                  display_name: Production sentiment baseline
                  status: STANDBY
                  sigma_threshold: 3
                  direction: BOTH
      responses:
        '201':
          description: Baseline created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Baseline'
              examples:
                ewmaBaseline:
                  summary: Newly created EWMA baseline
                  value:
                    ulid: 01HXKZ4M5N6P7Q8R9STVWXYZAB
                    metric_id: abc123def456ghi789jklm
                    agent_id: gk3jK9mPq2xRt5vW8yZaBc
                    test_set_id: 01HXKZ4M5N6P7Q8R9TESTSET01
                    persona_id: null
                    display_name: Resolution rate baseline
                    status: ACTIVE
                    detection_method: EWMA
                    baseline_float: null
                    baseline_sigma: null
                    observation_count: 0
                    sigma_threshold: 2.5
                    direction: ABOVE
                    sigma_bands: null
                    last_processed_run_completed_at: null
                    created_at: '2026-04-23T17:00:00Z'
                    last_updated_at: '2026-04-23T17:00:00Z'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    CreateMetricBaselineRequest:
      type: object
      description: Request body for creating a baseline. All fields optional.
      properties:
        agent_id:
          type: string
          nullable: true
          description: Agent ID. Null for org-wide baselines.
        test_set_id:
          type: string
          nullable: true
          description: Test set ULID. Null for monitoring.
        persona_id:
          type: string
          nullable: true
          description: Persona ULID. Null when the baseline covers all personas.
        display_name:
          type: string
          nullable: true
          maxLength: 200
          description: User-facing label.
        status:
          allOf:
            - $ref: '#/components/schemas/BaselineStatus'
          description: Initial status. Defaults to STANDBY.
        detection_method:
          allOf:
            - $ref: '#/components/schemas/BaselineDetectionMethod'
          description: Algorithm. Defaults to EWMA.
        sigma_threshold:
          type: number
          nullable: true
          minimum: 0
          exclusiveMinimum: true
          description: >-
            Sigmas from the baseline that constitute an anomaly. Defaults to
            2.0.
        direction:
          allOf:
            - $ref: '#/components/schemas/BaselineDirection'
          description: >-
            Which direction(s) of deviation count as anomalous. Defaults to
            BOTH.
        config:
          allOf:
            - $ref: '#/components/schemas/BaselineConfig'
    Baseline:
      type: object
      description: Anomaly-detection baseline for a metric.
      required:
        - ulid
        - status
        - detection_method
        - sigma_threshold
        - direction
        - created_at
        - last_updated_at
      properties:
        ulid:
          type: string
          description: Baseline ULID.
          example: 01HXKZ4M5N6P7Q8R9STVWXYZAB
        metric_id:
          type: string
          nullable: true
          description: Metric ULID.
        agent_id:
          type: string
          nullable: true
          description: Agent ID. Null for org-wide baselines.
        test_set_id:
          type: string
          nullable: true
          description: Test set ULID. Null for monitoring.
        persona_id:
          type: string
          nullable: true
          description: Persona ULID. Null when the baseline covers all personas.
        display_name:
          type: string
          nullable: true
          description: User-facing label.
        status:
          $ref: '#/components/schemas/BaselineStatus'
        detection_method:
          $ref: '#/components/schemas/BaselineDetectionMethod'
        baseline_float:
          type: number
          nullable: true
          description: Current baseline mean estimate.
        baseline_sigma:
          type: number
          nullable: true
          description: Current baseline standard deviation estimate.
        observation_count:
          type: integer
          default: 0
          description: Number of observations processed.
        sigma_threshold:
          type: number
          description: Sigmas from the baseline that constitute an anomaly.
        direction:
          $ref: '#/components/schemas/BaselineDirection'
        sigma_bands:
          type: object
          nullable: true
          additionalProperties:
            type: number
          description: >
            Computed sigma bands keyed by level (e.g. `upper_1sigma`,
            `lower_2sigma`,

            `upper_2sigma`). Null when baseline stats are not yet populated.
            Levels

            controlled by the `sigma_levels` query param.
        last_processed_run_completed_at:
          type: string
          format: date-time
          nullable: true
          description: 'Cursor: when the last processed run completed.'
        created_at:
          type: string
          format: date-time
        last_updated_at:
          type: string
          format: date-time
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              enum:
                - INVALID_ARGUMENT
                - UNAUTHENTICATED
                - PERMISSION_DENIED
                - NOT_FOUND
                - ALREADY_EXISTS
                - INTERNAL
            message:
              type: string
            details:
              type: array
              items:
                type: object
                properties:
                  field:
                    type: string
                    nullable: true
                  description:
                    type: string
    BaselineStatus:
      type: string
      description: Baseline lifecycle status.
      enum:
        - ACTIVE
        - STANDBY
        - ARCHIVED
    BaselineDetectionMethod:
      type: string
      description: Anomaly detection algorithm. Currently only EWMA.
      enum:
        - EWMA
    BaselineDirection:
      type: string
      description: Which direction(s) of deviation count as anomalous.
      enum:
        - BOTH
        - ABOVE
        - BELOW
    BaselineConfig:
      type: object
      description: >-
        Algorithm-specific configuration. Currently only the EWMA detector is
        supported.
      properties:
        time_constant_seconds:
          type: integer
          default: 604800
          description: >-
            EWMA time constant in seconds; controls decay rate. Default 604800
            (7 days).
  responses:
    Unauthorized:
      description: Authentication failed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: UNAUTHENTICATED
              message: Authentication failed
              details:
                - field: X-API-Key
                  description: Invalid or missing API key
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: NOT_FOUND
              message: Metric not found
              details:
                - field: metric_id
                  description: No metric found with this ID
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: INTERNAL
              message: Internal server error
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: API key for authentication

````