> ## 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 a metric flow

> Create a metric flow. Both referenced metrics must be visible to the organization
workspace. Scoped to the `X-Coval-Workspace-Id` header when present.




## OpenAPI

````yaml /api-reference/v1/metrics-v1.yaml post /metrics/flows
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/flows:
    post:
      tags:
        - Metrics
      summary: Create a metric flow
      description: >
        Create a metric flow. Both referenced metrics must be visible to the
        organization

        workspace. Scoped to the `X-Coval-Workspace-Id` header when present.
      operationId: createMetricFlow
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMetricFlowRequest'
      responses:
        '201':
          description: Metric flow created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetricFlowResponse'
        '400':
          description: Invalid request body
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: A referenced metric was not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          $ref: '#/components/responses/InternalError'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
components:
  schemas:
    CreateMetricFlowRequest:
      type: object
      required:
        - trigger_metric_id
        - followup_metric_id
      properties:
        trigger_metric_id:
          type: string
        followup_metric_id:
          type: string
        trigger_criteria:
          type: object
          additionalProperties: true
          nullable: true
        status:
          type: string
          enum:
            - ACTIVE
            - INACTIVE
      additionalProperties: false
    MetricFlowResponse:
      type: object
      required:
        - metric_flow
      properties:
        metric_flow:
          $ref: '#/components/schemas/MetricFlowResource'
    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
    MetricFlowResource:
      type: object
      required:
        - name
        - id
        - trigger_metric_id
        - followup_metric_id
        - status
      properties:
        name:
          type: string
          description: 'Resource name. Format: "metrics/flows/{id}".'
        id:
          type: string
        create_time:
          type: string
          format: date-time
          nullable: true
        trigger_metric_id:
          type: string
        followup_metric_id:
          type: string
        trigger_criteria:
          type: object
          additionalProperties: true
          nullable: true
        status:
          type: string
          enum:
            - ACTIVE
            - INACTIVE
            - DELETED
        trigger_metric_name:
          type: string
          nullable: true
        trigger_metric_display_name:
          type: string
          nullable: true
        followup_metric_name:
          type: string
          nullable: true
        followup_metric_display_name:
          type: string
          nullable: true
  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
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: INTERNAL
              message: Internal server error
    ServiceUnavailable:
      description: Service temporarily unavailable
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: INTERNAL
              message: Service temporarily unavailable
              details:
                - description: Database routing is temporarily unavailable. Please retry.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: API key for authentication

````