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

# Create test

> Create a test.



## OpenAPI

````yaml post /projects/{projectId}/tests
openapi: 3.0.3
info:
  contact:
    email: support@openlayer.com
    name: Openlayer
    url: https://openlayer.com/
  description: API for interacting with the Openlayer server.
  title: Openlayer API
  version: '1.0'
  x-logo:
    url: https://logo.clearbit.com/openlayer.com
servers:
  - url: https://api.openlayer.com/v1
    description: Our prod backend
security:
  - bearerAuth: []
paths:
  /projects/{projectId}/tests:
    post:
      tags:
        - Projects
      summary: Create a test in a project.
      description: Create a test.
      operationId: createTest
      parameters:
        - $ref: '#/components/parameters/projectId'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TestBase'
      responses:
        '201':
          description: Status OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestBase'
        default:
          $ref: '#/components/responses/UnexpectedError'
      x-codeSamples:
        - lang: python
          source: |
            import os
            from openlayer import Openlayer

            client = Openlayer()
            test = client.projects.tests.create(
                project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
                name="No duplicate rows",
                description="This test checks for duplicate rows in the dataset.",
                type="integrity",
                subtype="duplicateRowCount",
                thresholds=[
                  {
                    "insightName": "duplicateRowCount",
                    "measurement": "duplicateRowCount", # Using the absolute row count
                    "operator": "<=",
                    "value": 0 # Integer
                  }
                ],
                uses_production_data=True, # For monitoring mode
                evaluation_window=3600, # 1 hour
                delay_window=0,
                uses_training_dataset=False,
                uses_validation_dataset=False,

            )
        - lang: typescript
          source: |
            import Openlayer from 'openlayer';

            const openlayer = new Openlayer();
            const project = await openlayer.projects.tests.create({
              projectId: "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
              name: "No duplicate rows",
              description: "This test checks for duplicate rows in the dataset.",
              type: "integrity",
              subtype: "duplicateRowCount",
              thresholds: [
                {
                  insightName: "duplicateRowCount",
                  measurement: "duplicateRowCount",  // Using the absolute row count
                  operator: "<=",
                  value: 0  // Integer
                }
              ],
              usesProductionData: true, // For monitoring mode
              evaluationWindow: 3600, // 1 hour
              delayWindow: 0,
              usesTrainingDataset: false,
              usesValidationDataset: false,
            });
        - lang: go
          source: |
            package main

            import (
              "context"

              "github.com/openlayer-ai/openlayer-go"
              "github.com/openlayer-ai/openlayer-go/option"
            )

            client := openlayer.NewClient()
            project, err := client.Projects.Tests.New(
              context.TODO(),
              "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
              openlayer.ProjectTestNewParams{
                Name: openlayer.F("No duplicate rows"),
                Description: openlayer.F("This test checks for duplicate rows in the dataset."),
                Type: openlayer.F(openlayer.ProjectTestNewParamsTypeIntegrity),
                Subtype: openlayer.F(openlayer.ProjectTestNewParamsSubtypeDuplicateRowCount),
                Thresholds: []openlayer.ProjectTestNewParamsThreshold{
                  {
                    InsightName: openlayer.F("duplicateRowCount"),
                    Measurement: openlayer.F("duplicateRowCount"),
                    Operator: openlayer.F(openlayer.ProjectTestNewParamsOperatorLessThanOrEqual),
                    Value: openlayer.F(0),
                  }
                },
                UsesProductionData: true,
                EvaluationWindow: 3600,
                DelayWindow: 0,
                UsesTrainingDataset: false,
                UsesValidationDataset: false,
              })
            if err != nil {
              panic(err.Error())
            }
        - lang: curl
          source: |
            curl --request POST \
              --url https://api.openlayer.com/v1/projects/{projectId}/tests \
              --header 'Authorization: Bearer <token>' \
              --header 'Content-Type: application/json' \
              --data '{
                "name": "No duplicate rows",
                "description": "This test checks for duplicate rows in the dataset.",
                "type": "integrity",
                "subtype": "duplicateRowCount",
                "thresholds": [
                  {
                    "insightName": "duplicateRowCount",
                    "measurement": "duplicateRowCount",
                    "operator": "<=",
                    "value": 0
                  }
                ],
                "usesProductionData": true,
                "evaluationWindow": 3600,
                "delayWindow": 0,
                "usesTrainingDataset": false,
                "usesValidationDataset": false,
              }'
components:
  parameters:
    projectId:
      name: projectId
      in: path
      description: The project id.
      required: true
      schema:
        type: string
        format: uuid
  schemas:
    TestBase:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
          description: The test id.
          example: 3fa85f64-5717-4562-b3fc-2c963f66afa6
        number:
          type: integer
          readOnly: true
          description: The test number.
          example: 1
        name:
          type: string
          maxLength: 100
          description: The test name.
          example: No duplicate rows
        dateCreated:
          type: string
          format: date-time
          readOnly: true
          description: The creation date.
          example: '2024-03-22T11:31:01.185Z'
        dateUpdated:
          type: string
          format: date-time
          readOnly: true
          description: The last updated date.
          example: '2024-03-22T11:31:01.185Z'
        description:
          type: object
          nullable: true
          description: The test description.
          example: This test checks for duplicate rows in the dataset.
        evaluationWindow:
          type: number
          nullable: true
          maximum: 2592000
          description: >-
            The evaluation window in seconds. Only applies to tests that use
            production data.
          example: 3600
        delayWindow:
          type: number
          nullable: true
          minimum: 0
          maximum: 2592000
          description: >-
            The delay window in seconds. Only applies to tests that use
            production data.
          example: 0
        type:
          type: string
          description: The test type.
          example: integrity
          enum:
            - integrity
            - consistency
            - performance
        subtype:
          type: string
          description: The test subtype.
          example: duplicateRowCount
          enum:
            - anomalousColumnCount
            - characterLength
            - classImbalanceRatio
            - expectColumnAToBeInColumnB
            - columnAverage
            - columnDrift
            - columnStatistic
            - columnValuesMatch
            - conflictingLabelRowCount
            - containsPii
            - containsValidUrl
            - correlatedFeatureCount
            - customMetricThreshold
            - duplicateRowCount
            - emptyFeature
            - emptyFeatureCount
            - driftedFeatureCount
            - featureMissingValues
            - featureValueValidation
            - greatExpectations
            - groupByColumnStatsCheck
            - illFormedRowCount
            - isCode
            - isJson
            - llmRubricThresholdV2
            - labelDrift
            - metricThreshold
            - newCategoryCount
            - newLabelCount
            - nullRowCount
            - rowCount
            - ppScoreValueValidation
            - quasiConstantFeature
            - quasiConstantFeatureCount
            - sqlQuery
            - dtypeValidation
            - sentenceLength
            - sizeRatio
            - specialCharactersRatio
            - stringValidation
            - trainValLeakageRowCount
        creatorId:
          type: string
          format: uuid
          readOnly: true
          nullable: true
          description: The test creator id.
          example: 589ece63-49a2-41b4-98e1-10547761d4b0
        originProjectVersionId:
          type: string
          format: uuid
          readOnly: true
          nullable: true
          description: The project version (commit) id where the test was created.
          example: 3fa85f64-5717-4562-b3fc-2c963f66afa6
        thresholds:
          type: array
          required:
            - measurement
            - insightName
            - operator
            - value
          items:
            type: object
            properties:
              measurement:
                type: string
                description: The measurement to be evaluated.
                example: duplicateRowCount
              insightName:
                type: string
                description: The insight name to be evaluated.
                example: duplicateRowCount
                enum:
                  - characterLength
                  - classImbalance
                  - expectColumnAToBeInColumnB
                  - columnAverage
                  - columnDrift
                  - columnValuesMatch
                  - confidenceDistribution
                  - conflictingLabelRowCount
                  - containsPii
                  - containsValidUrl
                  - correlatedFeatures
                  - customMetric
                  - duplicateRowCount
                  - emptyFeatures
                  - featureDrift
                  - featureProfile
                  - greatExpectations
                  - groupByColumnStatsCheck
                  - illFormedRowCount
                  - isCode
                  - isJson
                  - llmRubricV2
                  - labelDrift
                  - metrics
                  - newCategories
                  - newLabels
                  - nullRowCount
                  - ppScore
                  - quasiConstantFeatures
                  - sentenceLength
                  - sizeRatio
                  - specialCharacters
                  - stringValidation
                  - trainValLeakageRowCount
              insightParameters:
                type: array
                nullable: true
                description: >-
                  The insight parameters. Required only for some test subtypes.
                  For example, for tests that require a column name, the insight
                  parameters will be [{'name': 'column_name', 'value': 'Age'}]
                items:
                  type: object
                  required:
                    - name
                    - value
                  properties:
                    name:
                      type: string
                      description: The name of the insight filter.
                      example: column_name
                    value:
                      example: Age
              thresholdMode:
                type: string
                enum:
                  - automatic
                  - manual
                description: >-
                  Whether to use automatic anomaly detection or manual
                  thresholds
                default: manual
              operator:
                type: string
                description: The operator to be used for the evaluation.
                example: <=
                enum:
                  - is
                  - '>'
                  - '>='
                  - <
                  - <=
                  - '!='
              value:
                description: The value to be compared.
                example: 0
                oneOf:
                  - type: number
                  - type: boolean
                  - type: string
                  - type: array
                    items:
                      type: string
        archived:
          type: boolean
          description: Whether the test is archived.
          example: false
        dateArchived:
          type: string
          format: date-time
          nullable: true
          readOnly: true
          description: The date the test was archived.
          example: '2024-03-22T11:31:01.185Z'
        suggested:
          type: boolean
          readOnly: true
          description: Whether the test is suggested or user-created.
          example: false
        commentCount:
          type: integer
          minimum: 0
          readOnly: true
          description: The number of comments on the test.
          example: 0
        usesMlModel:
          type: boolean
          description: Whether the test uses an ML model.
          example: false
        usesValidationDataset:
          type: boolean
          description: Whether the test uses a validation dataset.
          example: true
        usesTrainingDataset:
          type: boolean
          description: Whether the test uses a training dataset.
          example: false
        usesReferenceDataset:
          type: boolean
          description: Whether the test uses a reference dataset (monitoring mode only).
          example: false
        usesProductionData:
          type: boolean
          description: Whether the test uses production data (monitoring mode only).
          example: false
        includeHistoricalData:
          type: boolean
          nullable: true
          default: false
          description: >-
            Whether to include historical data in the test result. Only applies
            to tests that use production data.
        defaultToAllPipelines:
          type: boolean
          nullable: true
          default: true
          description: >-
            Whether to apply the test to all pipelines (data sources) or to a
            specific set of pipelines. Only applies to tests that use production
            data.
        includePipelines:
          type: array
          nullable: true
          items:
            type: string
            format: uuid
          description: >-
            Array of pipelines (data sources) to which the test should be
            applied. Only applies to tests that use production data.
        excludePipelines:
          type: array
          nullable: true
          items:
            type: string
            format: uuid
          description: >-
            Array of pipelines (data sources) to which the test should not be
            applied. Only applies to tests that use production data.
      required:
        - id
        - number
        - name
        - dateCreated
        - dateUpdated
        - description
        - type
        - subtype
        - creatorId
        - originProjectVersionId
        - thresholds
        - dateArchived
        - suggested
        - commentCount
  responses:
    UnexpectedError:
      description: Unexpected error.
      content:
        application/json:
          schema:
            type: object
            required:
              - code
              - error
            properties:
              code:
                type: integer
                format: int32
              error:
                type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        Bearer authentication header of the form `Bearer <token>`, where
        `<token>` is your workspace API key. See [Find your API
        key](https://www.openlayer.com/docs/workspace-and-projects/find-your-api-key)
        for more information.

````