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

# Create a test metric

> Creates a metric in your organization.



## OpenAPI

````yaml /openapi/source/external/inference/inference-ai-tests.json post /ai/tests/test_framework/v1/metrics
openapi: 3.1.0
info:
  version: 2.0.0
  title: Telnyx API
  x-latency-category: responsive
  x-endpoint-cost: light
  description: SIP trunking, SMS, MMS, Call Control and Telephony Data Services.
  contact:
    email: support@telnyx.com
servers:
  - url: https://api.telnyx.com/v2
    description: Version 2.0.0 of the Telnyx API
security:
  - bearerAuth: []
tags:
  - name: AI Tests
    description: >-
      Test agents, evaluator scenarios, metrics, and run results for the AI test
      framework.
paths:
  /ai/tests/test_framework/v1/metrics:
    post:
      tags:
        - AI Tests
      summary: Create a test metric
      description: Creates a metric in your organization.
      operationId: create_test_metric
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAiTestMetricRequest'
            example:
              name: Escalates on refund denial
              description: >-
                Returns a score for whether the assistant escalates when the
                caller's refund is denied.
              type: llm_judge
              eval_type: continuous_qualitative
              prompt: Score the assistant's escalation behaviour between 0.0 and 1.0.
              agents:
                - 1259
              add_to_new_agents: false
              simulation_enabled: true
              observability_enabled: true
      responses:
        '200':
          description: Test metric created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AiTestMetric'
              example:
                id: 266881
                slug: ai_interrupting_user
                project: 16003
                agent: null
                agents: []
                agent_names: []
                name: AI interrupting user
                description: >-
                  Tells if the AI (main agent) interrupted user (testing agent)
                  during the interaction.
                function_name: get_main_agent_interruption
                type: custom_code
                eval_type: numeric
                enum_values: []
                audio_enabled: false
                observability_enabled: true
                simulation_enabled: true
                sampling_enabled: false
                sample_rate: null
                prompt: ''
                display_order: 1
                evaluation_trigger: always
                trigger_type: llm_judge
                evaluation_trigger_prompt: ''
                evaluation_trigger_custom_code: ''
                priority_assignment_prompt: ''
                configuration: {}
                overall_score: 0
                total_score: 0
                kb_file_ids: []
                knowledge_base_files: []
                metric_cost: 0
                alert_type: disabled
                significant_change_alert_status: disabled
                significant_change_alert_direction: ''
                window_size: 50
                std_multiplier: 2
                ewma_alpha: 0.1
                add_to_new_agents: true
                alert_filters: {}
                uses_llm_judge: false
                user_defined: false
        '400':
          description: Bad Request. The AI Tests service rejected the request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AiTestsErrorResponse'
              example:
                errors:
                  - code: '10015'
                    title: Bad Request
                    detail: The AI Tests service rejected the request.
        '401':
          description: Unauthorized. Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AiTestsErrorResponse'
              example:
                errors:
                  - code: '10003'
                    title: Unauthorized
                    detail: The API key is missing or invalid.
        '404':
          description: >-
            Not Found. The requested resource does not exist or is not enabled
            for your account.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AiTestsErrorResponse'
              example:
                errors:
                  - code: '10005'
                    title: Not Found
                    detail: The requested resource or URL could not be found.
        '422':
          description: Unprocessable Entity. A validation error occurred.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AiTestsErrorResponse'
              example:
                errors:
                  - code: '10018'
                    title: Unprocessable Entity
                    detail: Validation failed for the request payload.
        '429':
          description: Too Many Requests. The AI Tests service rate-limited the request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AiTestsErrorResponse'
              example:
                errors:
                  - code: '10029'
                    title: Too Many Requests
                    detail: Too many requests; retry later.
        '503':
          description: Service Unavailable. The AI Tests service is unavailable.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AiTestsErrorResponse'
              example:
                errors:
                  - code: '10063'
                    title: Service Unavailable
                    detail: The test framework service is temporarily unavailable.
components:
  schemas:
    CreateAiTestMetricRequest:
      type: object
      properties:
        name:
          type: string
        description:
          type: string
        type:
          type: string
          description: 'How the metric is evaluated: custom_code or llm_judge.'
        eval_type:
          type: string
          description: >-
            What the metric scores: numeric, continuous_qualitative, or
            binary_workflow_adherence.
        prompt:
          type: string
          description: Judge prompt used by llm_judge metrics.
        enum_values:
          type: array
          items:
            type: string
        agents:
          type: array
          items:
            type: integer
        assistant_id:
          type: string
        add_to_new_agents:
          type:
            - boolean
            - 'null'
        simulation_enabled:
          type: boolean
        observability_enabled:
          type: boolean
        sampling_enabled:
          type: boolean
        audio_enabled:
          type: boolean
        display_order:
          type: integer
      required:
        - name
      example:
        name: Escalates on refund denial
        description: >-
          Returns a score for whether the assistant escalates when the caller's
          refund is denied.
        type: llm_judge
        eval_type: continuous_qualitative
        prompt: Score the assistant's escalation behaviour between 0.0 and 1.0.
        agents:
          - 1259
        add_to_new_agents: false
        simulation_enabled: true
        observability_enabled: true
    AiTestMetric:
      type: object
      properties:
        id:
          type: integer
        slug:
          type:
            - string
            - 'null'
          description: Stable identifier of a built-in metric.
        project:
          type:
            - integer
            - 'null'
        agent:
          type:
            - integer
            - 'null'
        agents:
          type: array
          items:
            type: integer
          description: Test agent IDs the metric is attached to.
        agent_names:
          type: array
          items:
            type: string
        name:
          type: string
        description:
          type: string
        function_name:
          type:
            - string
            - 'null'
          description: Built-in evaluation function used by custom_code metrics.
        type:
          type: string
          description: 'How the metric is evaluated: custom_code or llm_judge.'
        eval_type:
          type: string
          description: >-
            What the metric scores: numeric, continuous_qualitative, or
            binary_workflow_adherence.
        enum_values:
          type: array
          items:
            type: string
          description: Allowed values for qualitative enum metrics.
        audio_enabled:
          type: boolean
        observability_enabled:
          type: boolean
        simulation_enabled:
          type: boolean
        sampling_enabled:
          type: boolean
        sample_rate:
          type:
            - number
            - 'null'
        prompt:
          type: string
          description: Judge prompt used by llm_judge metrics.
        display_order:
          type: integer
        evaluation_trigger:
          type: string
        trigger_type:
          type: string
        evaluation_trigger_prompt:
          type: string
        evaluation_trigger_custom_code:
          type: string
        priority_assignment_prompt:
          type: string
        configuration:
          type:
            - object
            - 'null'
          additionalProperties: true
        overall_score:
          type:
            - number
            - string
        total_score:
          type:
            - number
            - string
        kb_file_ids:
          type: array
          items:
            type: integer
        knowledge_base_files:
          type: array
          items:
            type: string
        metric_cost:
          type: number
        alert_type:
          type: string
        significant_change_alert_status:
          type: string
        significant_change_alert_direction:
          type: string
        window_size:
          type: integer
          description: Sliding window size the alert status is computed over.
        std_multiplier:
          type: number
          description: Standard-deviation multiplier for significant-change alerts.
        ewma_alpha:
          type: number
          description: Smoothing factor for the alert trend.
        add_to_new_agents:
          type:
            - boolean
            - 'null'
          description: >-
            Whether the metric is attached to newly created test agents by
            default.
        alert_filters:
          type:
            - object
            - 'null'
          additionalProperties: true
        uses_llm_judge:
          type: boolean
        user_defined:
          type: boolean
      required:
        - id
        - name
        - type
        - eval_type
      example:
        id: 266881
        slug: ai_interrupting_user
        project: 16003
        agent: null
        agents: []
        agent_names: []
        name: AI interrupting user
        description: >-
          Tells if the AI (main agent) interrupted user (testing agent) during
          the interaction.
        function_name: get_main_agent_interruption
        type: custom_code
        eval_type: numeric
        enum_values: []
        audio_enabled: false
        observability_enabled: true
        simulation_enabled: true
        sampling_enabled: false
        sample_rate: null
        prompt: ''
        display_order: 1
        evaluation_trigger: always
        trigger_type: llm_judge
        evaluation_trigger_prompt: ''
        evaluation_trigger_custom_code: ''
        priority_assignment_prompt: ''
        configuration: {}
        overall_score: 0
        total_score: 0
        kb_file_ids: []
        knowledge_base_files: []
        metric_cost: 0
        alert_type: disabled
        significant_change_alert_status: disabled
        significant_change_alert_direction: ''
        window_size: 50
        std_multiplier: 2
        ewma_alpha: 0.1
        add_to_new_agents: true
        alert_filters: {}
        uses_llm_judge: false
        user_defined: false
    AiTestsErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              code:
                type: string
                description: Telnyx error code.
              title:
                type: string
              detail:
                type: string
              source:
                type: object
                properties:
                  pointer:
                    type: string
            required:
              - code
              - title
      required:
        - errors
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````