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

# Create test

> Create a test in a project.



## 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
      description: Create a test in a project.
      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: |
            from openlayer import Openlayer

            client = Openlayer()

            test = client.projects.tests.create(
                "3fa85f64-5717-4562-b3fc-2c963f66afa6",
                name="No duplicate rows",
                description="Fails if the data contains duplicate rows.",
                type="integrity",
                subtype="duplicateRowCount",
                thresholds=[
                    {
                        "insight_name": "duplicateRowCount",
                        "measurement": "duplicateRowCount",
                        "operator": "<=",
                        "value": 0,
                    }
                ],
                uses_production_data=True,
                evaluation_window=3600,
            )
            print(test.id)
        - lang: typescript
          source: >
            import Openlayer from 'openlayer';


            const client = new Openlayer();


            const test = await
            client.projects.tests.create('3fa85f64-5717-4562-b3fc-2c963f66afa6',
            {
              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,
                },
              ],
            });


            console.log(test.id);
        - lang: go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/openlayer-ai/openlayer-go\"\n\t\"github.com/openlayer-ai/openlayer-go/shared\"\n)\n\nclient := openlayer.NewClient()\ntest, err := client.Projects.Tests.New(\n\tcontext.TODO(),\n\t\"3fa85f64-5717-4562-b3fc-2c963f66afa6\",\n\topenlayer.ProjectTestNewParams{\n\t\tName:        openlayer.F(\"No duplicate rows\"),\n\t\tDescription: openlayer.F[any](\"This test checks for duplicate rows in the dataset.\"),\n\t\tType:        openlayer.F(openlayer.ProjectTestNewParamsTypeIntegrity),\n\t\tSubtype:     openlayer.F(openlayer.ProjectTestNewParamsSubtypeDuplicateRowCount),\n\t\tThresholds: openlayer.F([]openlayer.ProjectTestNewParamsThreshold{{\n\t\t\tInsightName: openlayer.F(openlayer.ProjectTestNewParamsThresholdsInsightNameDuplicateRowCount),\n\t\t\tMeasurement: openlayer.F(\"duplicateRowCount\"),\n\t\t\tOperator:    openlayer.F(openlayer.ProjectTestNewParamsThresholdsOperatorLessOrEquals),\n\t\t\tValue:       openlayer.F[openlayer.ProjectTestNewParamsThresholdsValueUnion](shared.UnionFloat(0)),\n\t\t}}),\n\t\tUsesProductionData: openlayer.F(true),\n\t},\n)\nif err != nil {\n\tpanic(err.Error())\n}\nfmt.Printf(\"%+v\\n\", test.ID)\n"
        - lang: java
          source: |
            import com.openlayer.api.client.OpenlayerClient;
            import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;
            import com.openlayer.api.core.JsonMissing;
            import com.openlayer.api.core.JsonValue;
            import com.openlayer.api.models.projects.tests.TestCreateParams;
            import com.openlayer.api.models.projects.tests.TestCreateResponse;

            OpenlayerClient client = OpenlayerOkHttpClient.fromEnv();

            TestCreateParams params = TestCreateParams.builder()
                .projectId("3fa85f64-5717-4562-b3fc-2c963f66afa6")
                .name("No duplicate rows")
                .description(JsonValue.from("This test checks for duplicate rows in the dataset."))
                .type(TestCreateParams.Type.INTEGRITY)
                .subtype(TestCreateParams.Subtype.DUPLICATE_ROW_COUNT)
                .addThreshold(TestCreateParams.Threshold.builder()
                    .insightName(TestCreateParams.Threshold.InsightName.DUPLICATE_ROW_COUNT)
                    .measurement("duplicateRowCount")
                    .operator(TestCreateParams.Threshold.Operator.LESS_OR_EQUALS)
                    .value(0.0)
                    .build())
                // Server-assigned fields the Java SDK marks as required: leave them out of the request.
                .id(JsonMissing.of())
                .number(JsonMissing.of())
                .creatorId(JsonMissing.of())
                .originProjectVersionId(JsonMissing.of())
                .dateCreated(JsonMissing.of())
                .dateUpdated(JsonMissing.of())
                .dateArchived(JsonMissing.of())
                .suggested(JsonMissing.of())
                .commentCount(JsonMissing.of())
                .build();
            TestCreateResponse test = client.projects().tests().create(params);
        - lang: ruby
          source: |
            require "openlayer"

            openlayer = Openlayer::Client.new(api_key: ENV["OPENLAYER_API_KEY"])

            test = openlayer.projects.tests.create(
              "3fa85f64-5717-4562-b3fc-2c963f66afa6",
              name: "No duplicate rows",
              description: "This test checks for duplicate rows in the dataset.",
              type: :integrity,
              subtype: :duplicateRowCount,
              thresholds: [
                {
                  insight_name: :duplicateRowCount,
                  measurement: "duplicateRowCount",
                  operator: :<=,
                  value: 0.0
                }
              ]
            )

            puts(test)
        - 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:
          oneOf:
            - type: object
            - type: string
              nullable: true
          description: The test description.
          example: This test checks for duplicate rows in the dataset.
          x-stainless-override-schema:
            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.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.