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

# Create metric definitions metric definitions

> Requires scopes: reports:write



## OpenAPI

````yaml /api-reference/openapi.json post /api/metric-definitions
openapi: 3.1.0
info:
  title: EvalGate API
  version: 3.7.6
  description: EvalGate API. See docs/api-contract.md for stability commitments.
servers:
  - url: https://evalgate.com
    description: Production
  - url: http://localhost:3000
    description: Local
security: []
paths:
  /api/metric-definitions:
    post:
      tags:
        - metric definitions
      summary: Create metric definitions metric definitions
      description: 'Requires scopes: reports:write'
      operationId: post_metric_definitions
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PostApiMetricDefinitionsRequest'
      responses:
        '201':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/PostApiMetricDefinitionsResponse201ApplicationJson
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
      security:
        - bearerAuth:
            - reports:write
components:
  schemas:
    PostApiMetricDefinitionsRequest:
      type: object
      properties:
        source:
          oneOf:
            - type: string
              enum:
                - traces
            - type: string
              enum:
                - experiments
            - type: string
              enum:
                - model_calls
            - type: string
              enum:
                - eval_runs
            - type: string
              enum:
                - online_evals
            - type: string
              enum:
                - review
        metricKey:
          type: string
        measure:
          type: string
        aggregation:
          oneOf:
            - type: string
              enum:
                - max
            - type: string
              enum:
                - count
            - type: string
              enum:
                - sum
            - type: string
              enum:
                - avg
            - type: string
              enum:
                - min
            - type: string
              enum:
                - p50
            - type: string
              enum:
                - p95
            - type: string
              enum:
                - p99
            - type: string
              enum:
                - rate
        window:
          oneOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - relative
                lookbackSeconds:
                  type: number
                timezone:
                  type: string
              additionalProperties: false
              required:
                - type
                - lookbackSeconds
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - absolute
                from:
                  type: string
                to:
                  type: string
                timezone:
                  type: string
              additionalProperties: false
              required:
                - type
                - from
                - to
        unknownPolicy:
          oneOf:
            - type: string
              enum:
                - fail
            - type: string
              enum:
                - exclude
            - type: string
              enum:
                - include_as_zero
        calibrationBoundary:
          oneOf:
            - type: object
              properties:
                state:
                  type: string
                  enum:
                    - not_applicable
              additionalProperties: false
              required:
                - state
            - type: object
              properties:
                state:
                  type: string
                  enum:
                    - exact
              additionalProperties: false
              required:
                - state
            - type: object
              properties:
                state:
                  type: string
                  enum:
                    - calibrated
                mappingVersionId:
                  type: string
              additionalProperties: false
              required:
                - state
                - mappingVersionId
            - type: object
              properties:
                reason:
                  type: string
                state:
                  type: string
                  enum:
                    - not_comparable
              additionalProperties: false
              required:
                - reason
                - state
        filters:
          type: array
          items:
            type: object
            properties:
              operator:
                oneOf:
                  - type: string
                    enum:
                      - exists
                  - type: string
                    enum:
                      - in
                  - type: string
                    enum:
                      - not_in
                  - type: string
                    enum:
                      - gte
                  - type: string
                    enum:
                      - lte
                  - type: string
                    enum:
                      - eq
                  - type: string
                    enum:
                      - neq
                  - type: string
                    enum:
                      - gt
                  - type: string
                    enum:
                      - lt
                  - type: string
                    enum:
                      - contains
              field:
                type: string
              value:
                $ref: '#/components/schemas/JsonValue'
            additionalProperties: false
            required:
              - operator
              - field
        groupBy:
          type: array
          items:
            type: string
        timeGrain:
          oneOf:
            - type: string
              enum:
                - minute
            - type: string
              enum:
                - hour
            - type: string
              enum:
                - day
            - type: string
              enum:
                - week
      additionalProperties: false
      required:
        - source
        - metricKey
        - measure
        - aggregation
        - window
        - unknownPolicy
        - calibrationBoundary
    PostApiMetricDefinitionsResponse201ApplicationJson:
      type: object
      properties:
        status:
          type: string
        id:
          type: string
        createdAt:
          type: string
          format: date-time
        organizationId:
          $ref: '#/components/schemas/OrganizationId'
        createdBy:
          type: string
        version:
          type: number
        approvedBy:
          oneOf:
            - type: 'null'
            - type: string
        source:
          type: string
        approvedAt:
          oneOf:
            - type: 'null'
            - type: string
              format: date-time
        metricKey:
          type: string
        measure:
          type: string
        aggregation:
          type: string
        filters:
          type: array
          items:
            type: object
            properties:
              operator:
                oneOf:
                  - type: string
                    enum:
                      - exists
                  - type: string
                    enum:
                      - in
                  - type: string
                    enum:
                      - not_in
                  - type: string
                    enum:
                      - gte
                  - type: string
                    enum:
                      - lte
                  - type: string
                    enum:
                      - eq
                  - type: string
                    enum:
                      - neq
                  - type: string
                    enum:
                      - gt
                  - type: string
                    enum:
                      - lt
                  - type: string
                    enum:
                      - contains
              field:
                type: string
              value:
                $ref: '#/components/schemas/JsonValue'
            additionalProperties: false
            required:
              - operator
              - field
        groupBy:
          type: array
          items:
            type: string
        timeGrain:
          oneOf:
            - type: 'null'
            - type: string
        unknownPolicy:
          type: string
        calibrationBoundary:
          oneOf:
            - type: object
              properties:
                state:
                  type: string
                  enum:
                    - not_applicable
              additionalProperties: false
              required:
                - state
            - type: object
              properties:
                state:
                  type: string
                  enum:
                    - exact
              additionalProperties: false
              required:
                - state
            - type: object
              properties:
                state:
                  type: string
                  enum:
                    - calibrated
                mappingVersionId:
                  type: string
              additionalProperties: false
              required:
                - state
                - mappingVersionId
            - type: object
              properties:
                reason:
                  type: string
                state:
                  type: string
                  enum:
                    - not_comparable
              additionalProperties: false
              required:
                - reason
                - state
        windowJson:
          oneOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - relative
                lookbackSeconds:
                  type: number
                timezone:
                  type: string
              additionalProperties: false
              required:
                - type
                - lookbackSeconds
                - timezone
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - absolute
                timezone:
                  type: string
                from:
                  type: string
                to:
                  type: string
              additionalProperties: false
              required:
                - type
                - timezone
                - from
                - to
        definitionHash:
          type: string
        parentVersionId:
          oneOf:
            - type: 'null'
            - type: string
      additionalProperties: false
      required:
        - status
        - id
        - createdAt
        - organizationId
        - createdBy
        - version
        - approvedBy
        - source
        - approvedAt
        - metricKey
        - measure
        - aggregation
        - filters
        - groupBy
        - timeGrain
        - unknownPolicy
        - calibrationBoundary
        - windowJson
        - definitionHash
        - parentVersionId
    JsonValue:
      oneOf:
        - type: 'null'
        - type: boolean
        - type: number
        - type: string
        - type: array
          items:
            $ref: '#/components/schemas/JsonValue'
        - type: object
          additionalProperties:
            $ref: '#/components/schemas/JsonValue'
    OrganizationId:
      type: string
      format: uuid
    ApiError:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - UNAUTHORIZED
                - FORBIDDEN
                - NOT_FOUND
                - VALIDATION_ERROR
                - RATE_LIMITED
                - CONFLICT
                - INTERNAL_ERROR
                - SERVICE_UNAVAILABLE
                - QUOTA_EXCEEDED
                - NO_ORG_MEMBERSHIP
                - CROSS_ORG_REFERENCE
                - INCOMPLETE
                - MALFORMED
            message:
              type: string
            details: {}
            requestId:
              type: string
              format: uuid
          required:
            - code
            - message
      required:
        - error
  responses:
    ValidationError:
      description: Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    Conflict:
      description: Conflict
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    RateLimited:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key or Session Token

````