> ## 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.

# Update metric

> Partial update of metric fields. Only provided fields are updated.



## OpenAPI

````yaml /api-reference/v1/metrics-v1.yaml patch /metrics/{metric_id}
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}:
    patch:
      tags:
        - Metrics
      summary: Update metric
      description: Partial update of metric fields. Only provided fields are updated.
      operationId: updateMetric
      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/UpdateMetricRequest'
            examples:
              updatePrompt:
                summary: Update prompt
                value:
                  prompt: Updated evaluation prompt
              updateRange:
                summary: Update numerical range
                value:
                  min_value: 0
                  max_value: 100
      responses:
        '200':
          description: Metric updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetMetricResponse'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unknownModel:
                  summary: Unknown model version
                  value:
                    error:
                      code: INVALID_ARGUMENT
                      message: >-
                        'openai:gpt-999' is not a supported model. Use GET
                        /v1/models/metric to list available models.
                      details:
                        - field: runtime_config.model_version
                          description: UNKNOWN_MODEL
                thinkingNotSupported:
                  summary: Thinking not supported on model
                  value:
                    error:
                      code: INVALID_ARGUMENT
                      message: >-
                        Model 'openai:gpt-4.1-mini-2025-04-14' does not support
                        thinking mode.
                      details:
                        - field: runtime_config.thinking_enabled
                          description: THINKING_NOT_SUPPORTED
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: Enterprise model access denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: PERMISSION_DENIED
                  message: >-
                    Model 'anthropic:claude-sonnet-4-6' requires an Enterprise
                    plan. Contact sales@coval.dev to upgrade.
                  details:
                    - field: runtime_config.model_version
                      description: MODEL_TIER_ACCESS_DENIED
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    UpdateMetricRequest:
      type: object
      description: Update metric request (partial update)
      properties:
        metric_name:
          type: string
          minLength: 1
          maxLength: 200
        description:
          type: string
          minLength: 1
          maxLength: 1000
        metric_type:
          $ref: '#/components/schemas/MetricType'
        prompt:
          type: string
        categories:
          type: array
          items:
            type: string
          minItems: 2
          maxItems: 50
        min_value:
          type: number
        max_value:
          type: number
        metadata_field_type:
          $ref: '#/components/schemas/MetadataFieldType'
        metadata_field_key:
          type: string
        regex_pattern:
          type: string
        role:
          type: string
          enum:
            - agent
            - user
        min_pause_duration_seconds:
          type: number
          minimum: 0.5
        include_traces:
          type: boolean
          nullable: true
          description: >
            Inject OTel trace context into the LLM judge prompt during
            evaluation.

            Supported for LLM judge metric types only.
        runtime_config:
          type: object
          allOf:
            - $ref: '#/components/schemas/MetricRuntimeConfig'
          nullable: true
          description: >
            Override the LLM model used for metric evaluation. Set to `null` to
            revert to

            the platform default. Use `GET /v1/models/metric` to list available
            models.

            Not supported for audio metric types (`METRIC_AUDIO_LLM_BINARY`,

            `METRIC_AUDIO_LLM_CATEGORICAL`, `METRIC_AUDIO_LLM_NUMERICAL`),

            which always use the platform-default audio model.
        target_condition:
          allOf:
            - $ref: '#/components/schemas/TargetCondition'
          description: Target condition for metric evaluation
        tags:
          type: array
          nullable: true
          description: >-
            Tags to associate with this metric. Null or omitted leaves tags
            unchanged. Pass [] to clear all tags.
          items:
            type: string
          example:
            - production
    GetMetricResponse:
      type: object
      required:
        - metric
      properties:
        metric:
          $ref: '#/components/schemas/MetricResource'
    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
    MetricType:
      type: string
      description: |
        Metric evaluation type.

        - `METRIC_LLM_BINARY` - Yes/no LLM evaluation
        - `METRIC_CATEGORICAL` - Multi-class classification
        - `METRIC_NUMERICAL_LLM_JUDGE` - Numerical scoring (1-N)
        - `METRIC_AUDIO_LLM_BINARY` - Audio-based yes/no
        - `METRIC_AUDIO_LLM_CATEGORICAL` - Audio-based classification
        - `METRIC_AUDIO_LLM_NUMERICAL` - Audio-based scoring
        - `METRIC_TOOLCALL` - Tool/function call evaluation
        - `METRIC_METADATA_FIELD` - Extract metadata field
        - `METRIC_TRANSCRIPT_REGEX` - Regex pattern matching
        - `METRIC_PAUSE_ANALYSIS` - Speech pause detection
      enum:
        - METRIC_LLM_BINARY
        - METRIC_CATEGORICAL
        - METRIC_NUMERICAL_LLM_JUDGE
        - METRIC_AUDIO_LLM_BINARY
        - METRIC_AUDIO_LLM_CATEGORICAL
        - METRIC_AUDIO_LLM_NUMERICAL
        - METRIC_TOOLCALL
        - METRIC_METADATA_FIELD
        - METRIC_TRANSCRIPT_REGEX
        - METRIC_PAUSE_ANALYSIS
    MetadataFieldType:
      type: string
      description: Data type for metadata field extraction
      enum:
        - STRING
        - NUMBER
        - BOOLEAN
    MetricRuntimeConfig:
      type: object
      description: LLM model and thinking configuration for metric execution
      properties:
        model_version:
          type: string
          description: >
            Model identifier in canonical colon-separated format (e.g.

            `"openai:gpt-4.1-mini-2025-04-14"`). Use `GET /v1/models/metric` to
            list

            available models and their identifiers.
          example: openai:gpt-4.1-mini-2025-04-14
        thinking_enabled:
          type: boolean
          nullable: true
          description: >
            Enable extended thinking / reasoning mode. Only supported on select
            enterprise

            models (`supports_thinking: true` in the model list). Attempting to
            enable this

            on an unsupported model returns `400 THINKING_NOT_SUPPORTED`.
    TargetCondition:
      type: object
      description: >-
        The metric's success criteria — the rule that decides which output value
        counts as a pass/success. It is a comparison operator plus a target
        value, stored in the metric's config and used to compute pass/fail and
        dashboard success rates. Set it via create or update so no manual UI
        step is needed. For a yes/no (binary) metric where "YES" is a pass, use
        `{"comparison_operator": "in", "target_values": ["YES"]}`; for a 1-5
        numeric metric where >= 4 is a pass, use `{"comparison_operator": "gte",
        "target_float": 4}`.
      required:
        - comparison_operator
      oneOf:
        - required:
            - target_float
        - required:
            - target_values
      properties:
        comparison_operator:
          type: string
          description: >-
            How the metric output is compared to the target. Use a numeric
            operator (`eq`/`neq`/`gt`/`gte`/`lt`/`lte`) with `target_float`, or
            a membership operator (`in`/`nin`) with `target_values`.
          enum:
            - eq
            - neq
            - gt
            - gte
            - lt
            - lte
            - in
            - nin
        target_float:
          type: number
          nullable: true
          description: Target number for the numeric operators (eq/neq/gt/gte/lt/lte).
        target_values:
          type: array
          items:
            type: string
          minItems: 1
          maxItems: 50
          nullable: true
          description: >-
            Target value(s) for the membership operators (in/nin), e.g.
            `["YES"]`.
          example:
            - 'YES'
      example:
        comparison_operator: in
        target_values:
          - 'YES'
    MetricResource:
      type: object
      description: Metric resource
      properties:
        name:
          type: string
          description: Resource name
          example: metrics/abc123def456ghi789jklm
        id:
          type: string
          description: Metric ID
          example: abc123def456ghi789jklm
        metric_name:
          type: string
          description: Display name
          example: Customer Satisfaction
        description:
          type: string
          description: Metric description
          example: Evaluates customer satisfaction
        metric_type:
          $ref: '#/components/schemas/MetricType'
        prompt:
          type: string
          nullable: true
          description: LLM evaluation prompt (for LLM-based metrics)
          example: Did the agent resolve the issue?
        categories:
          type: array
          nullable: true
          items:
            type: string
          maxItems: 50
          description: Classification categories (for categorical metrics)
          example:
            - positive
            - neutral
            - negative
        min_value:
          type: number
          nullable: true
          description: Minimum score value (for numerical metrics)
          example: 1
        max_value:
          type: number
          nullable: true
          description: Maximum score value (for numerical metrics)
          example: 10
        metadata_field_type:
          allOf:
            - $ref: '#/components/schemas/MetadataFieldType'
          nullable: true
          description: Field type (for METRIC_METADATA_FIELD)
        metadata_field_key:
          type: string
          nullable: true
          description: Metadata key to extract (for METRIC_METADATA_FIELD)
          example: satisfaction_score
        regex_pattern:
          type: string
          nullable: true
          description: Regex pattern (for METRIC_TRANSCRIPT_REGEX)
          example: (hello|hi)
        role:
          type: string
          nullable: true
          description: Speaker role filter (for METRIC_TRANSCRIPT_REGEX)
          enum:
            - agent
            - user
          example: agent
        min_pause_duration_seconds:
          type: number
          nullable: true
          description: Minimum pause duration (for METRIC_PAUSE_ANALYSIS)
          example: 0.5
        include_traces:
          type: boolean
          nullable: true
          description: >
            Whether OTel trace context is injected into the LLM judge prompt
            during evaluation.

            Supported for LLM judge metric types only (`METRIC_LLM_BINARY`,
            `METRIC_CATEGORICAL`,

            `METRIC_NUMERICAL_LLM_JUDGE`, `METRIC_AUDIO_LLM_BINARY`,
            `METRIC_AUDIO_LLM_CATEGORICAL`,

            `METRIC_AUDIO_LLM_NUMERICAL`).
        runtime_config:
          allOf:
            - $ref: '#/components/schemas/MetricRuntimeConfig'
          description: |
            LLM model and thinking configuration for this metric.
            Not supported for audio metric types (`METRIC_AUDIO_LLM_BINARY`,
            `METRIC_AUDIO_LLM_CATEGORICAL`, `METRIC_AUDIO_LLM_NUMERICAL`),
            which always use the platform-default audio model.
        target_condition:
          allOf:
            - $ref: '#/components/schemas/TargetCondition'
          description: Target condition for metric evaluation
        tags:
          type: array
          description: Tags associated with this metric
          items:
            type: string
          default: []
          example:
            - production
            - llm
        created_by:
          type: string
          nullable: true
          description: Creator email
        create_time:
          type: string
          format: date-time
          description: Creation timestamp
        update_time:
          type: string
          format: date-time
          nullable: true
          description: Last update timestamp
        current_version:
          allOf:
            - $ref: '#/components/schemas/CurrentMetricVersion'
          nullable: true
          description: >-
            The metric's live version. Null for pre-versioning metrics that have
            not yet been saved or run under the versioning system. Full history
            at GET /v1/metrics/{metric_id}/versions.
    CurrentMetricVersion:
      type: object
      description: The metric's live version, embedded on MetricResource.
      required:
        - ulid
        - version_number
        - change_type
      properties:
        ulid:
          type: string
          description: Identifier of the current version row (26-char ULID)
          example: 01KKWQYSF737ZN6X1Q1RYX8M2D
        version_number:
          type: integer
          description: Per-metric monotonic version number, 1-based
          example: 3
        change_type:
          $ref: '#/components/schemas/MetricVersionChangeType'
    MetricVersionChangeType:
      type: string
      description: >-
        How a metric version came about. A revert is a save whose new state
        mirrors an older version.
      enum:
        - save
        - revert
  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

````