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

# Create Test Cases

> Create one or more test cases

Create one or more test cases for a prompt. Test cases can be used to validate prompt performance and ensure consistent output across different scenarios.

## Create a Test Case

<CodeGroup>
  ```typescript theme={null}
  const API_KEY = process.env.TELA_API_KEY;

  // Single test case
  const testCase = {
    title: "Customer Support Query Test",
    promptId: "prompt_uuid",
    messages: [
      {
        role: "system",
        content: "You are a helpful customer support assistant."
      },
      {
        role: "user",
        content: "My order hasn't arrived yet."
      }
    ],
    variables: {
      "customer_name": "John Doe",
      "order_id": "ORD-12345"
    },
    variablesRichContent: {},
    expectedOutput: "I'll help you track down your order, John. Let me look up order ORD-12345 for you.",
    metadata: {
      source: "craft"
    }
  };

  const response = await fetch('https://api.tela.ai/test-case', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(testCase)
  });

  const data = await response.json();
  console.log(data);
  ```

  ```python theme={null}
  import requests

  API_KEY = os.getenv('TELA_API_KEY')

  # Single test case
  test_case = {
    "title": "Customer Support Query Test",
    "promptId": "prompt_uuid",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful customer support assistant."
      },
      {
        "role": "user",
        "content": "My order hasn't arrived yet."
      }
    ],
    "variables": {
      "customer_name": "John Doe",
      "order_id": "ORD-12345"
    },
    "variablesRichContent": {},
    "expectedOutput": "I'll help you track down your order, John. Let me look up order ORD-12345 for you.",
    "metadata": {
      "source": "craft"
    }
  }

  response = requests.post(
      'https://api.tela.ai/test-case',
      headers={
          'Authorization': f'Bearer {API_KEY}',
          'Content-Type': 'application/json'
      },
      json=test_case
  )

  print(response.json())
  ```

  ```javascript theme={null}
  const API_KEY = process.env.TELA_API_KEY;

  // Single test case
  const testCase = {
    title: "Customer Support Query Test",
    promptId: "prompt_uuid",
    messages: [
      {
        role: "system",
        content: "You are a helpful customer support assistant."
      },
      {
        role: "user",
        content: "My order hasn't arrived yet."
      }
    ],
    variables: {
      "customer_name": "John Doe",
      "order_id": "ORD-12345"
    },
    variablesRichContent: {},
    expectedOutput: "I'll help you track down your order, John. Let me look up order ORD-12345 for you.",
    metadata: {
      source: "craft"
    }
  };

  fetch('https://api.tela.ai/test-case', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(testCase)
  })
  .then(response => response.json())
  .then(data => {
    console.log(data);
  })
  .catch(error => {
    console.error('Error:', error);
  });
  ```
</CodeGroup>

## Create Multiple Test Cases

<CodeGroup>
  ```typescript theme={null}
  const API_KEY = process.env.TELA_API_KEY;

  // Multiple test cases
  const testCases = [
    {
      title: "Customer Support Query - Order Status",
      promptId: "prompt_uuid",
      messages: [
        {
          role: "system",
          content: "You are a helpful customer support assistant."
        },
        {
          role: "user",
          content: "My order hasn't arrived yet."
        }
      ],
      variables: {
        "customer_name": "John Doe",
        "order_id": "ORD-12345"
      },
      variablesRichContent: {},
      expectedOutput: "I'll help you track down your order, John. Let me look up order ORD-12345 for you.",
      metadata: {
        source: "craft"
      }
    },
    {
      title: "Customer Support Query - Return Policy",
      promptId: "prompt_uuid",
      messages: [
        {
          role: "system",
          content: "You are a helpful customer support assistant."
        },
        {
          role: "user",
          content: "What's your return policy?"
        }
      ],
      variables: {
        "customer_name": "Jane Smith"
      },
      variablesRichContent: {},
      expectedOutput: "Our return policy allows returns within 30 days of purchase with a receipt.",
      metadata: {
        source: "craft"
      }
    }
  ];

  const response = await fetch('https://api.tela.ai/test-case', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(testCases)
  });

  const data = await response.json();
  console.log(data);
  ```

  ```python theme={null}
  import requests

  API_KEY = os.getenv('TELA_API_KEY')

  # Multiple test cases
  test_cases = [
    {
      "title": "Customer Support Query - Order Status",
      "promptId": "prompt_uuid",
      "messages": [
        {
          "role": "system",
          "content": "You are a helpful customer support assistant."
        },
        {
          "role": "user",
          "content": "My order hasn't arrived yet."
        }
      ],
      "variables": {
        "customer_name": "John Doe",
        "order_id": "ORD-12345"
      },
      "variablesRichContent": {},
      "expectedOutput": "I'll help you track down your order, John. Let me look up order ORD-12345 for you.",
      "metadata": {
        "source": "craft"
      }
    },
    {
      "title": "Customer Support Query - Return Policy",
      "promptId": "prompt_uuid",
      "messages": [
        {
          "role": "system",
          "content": "You are a helpful customer support assistant."
        },
        {
          "role": "user",
          "content": "What's your return policy?"
        }
      ],
      "variables": {
        "customer_name": "Jane Smith"
      },
      "variablesRichContent": {},
      "expectedOutput": "Our return policy allows returns within 30 days of purchase with a receipt.",
      "metadata": {
        "source": "craft"
      }
    }
  ]

  response = requests.post(
      'https://api.tela.ai/test-case',
      headers={
          'Authorization': f'Bearer {API_KEY}',
          'Content-Type': 'application/json'
      },
      json=test_cases
  )

  print(response.json())
  ```

  ```javascript theme={null}
  const API_KEY = process.env.TELA_API_KEY;

  // Multiple test cases
  const testCases = [
    {
      title: "Customer Support Query - Order Status",
      promptId: "prompt_uuid",
      messages: [
        {
          role: "system",
          content: "You are a helpful customer support assistant."
        },
        {
          role: "user",
          content: "My order hasn't arrived yet."
        }
      ],
      variables: {
        "customer_name": "John Doe",
        "order_id": "ORD-12345"
      },
      variablesRichContent: {},
      expectedOutput: "I'll help you track down your order, John. Let me look up order ORD-12345 for you.",
      metadata: {
        source: "craft"
      }
    },
    {
      title: "Customer Support Query - Return Policy",
      promptId: "prompt_uuid",
      messages: [
        {
          role: "system",
          content: "You are a helpful customer support assistant."
        },
        {
          role: "user",
          content: "What's your return policy?"
        }
      ],
      variables: {
        "customer_name": "Jane Smith"
      },
      variablesRichContent: {},
      expectedOutput: "Our return policy allows returns within 30 days of purchase with a receipt.",
      metadata: {
        source: "craft"
      }
    }
  ];

  fetch('https://api.tela.ai/test-case', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(testCases)
  })
  .then(response => response.json())
  .then(data => {
    console.log(data);
  })
  .catch(error => {
    console.error('Error:', error);
  });
  ```
</CodeGroup>

### Request Body

The request body can be either a single test case object or an array of test case objects.

#### Test Case Object

| Field                  | Type   | Required | Description                                        |
| ---------------------- | ------ | -------- | -------------------------------------------------- |
| `promptId`             | string | Yes      | UUID of the prompt to create test cases for        |
| `title`                | string | No       | Title of the test case                             |
| `messages`             | array  | Yes      | Array of message objects with role and content     |
| `variables`            | object | No       | Key-value pairs of variables used in the test case |
| `variablesRichContent` | object | Yes      | Key-value pairs of rich content variables          |
| `files`                | array  | No       | Array of file objects to attach to the test case   |
| `expectedOutput`       | string | No       | Expected output for evaluation purposes            |
| `promptApplicationId`  | string | No       | UUID of the prompt application if applicable       |
| `metadata`             | object | No       | Metadata about the test case including source      |

#### Message Object

| Field     | Type   | Required | Description                                                               |
| --------- | ------ | -------- | ------------------------------------------------------------------------- |
| `role`    | string | Yes      | Role of the message sender (user, system, assistant, function, developer) |
| `content` | string | Yes      | Content of the message                                                    |

#### File Object

| Field          | Type   | Required | Description                            |
| -------------- | ------ | -------- | -------------------------------------- |
| `index`        | number | Yes      | Index of the file in the array         |
| `name`         | string | Yes      | Name of the file                       |
| `mimeType`     | string | Yes      | MIME type of the file                  |
| `vaultUrl`     | string | Yes      | URL to the file in the vault           |
| `variableName` | string | Yes      | Variable name associated with the file |
| `url`          | string | Yes      | Public URL to the file                 |

### Response

The response will contain the created test case(s) with all fields including the generated IDs and timestamps.


## OpenAPI

````yaml POST /test-case
openapi: 3.0.1
info:
  title: Tela API
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.tela.com
security: []
paths:
  /test-case:
    post:
      description: Create one or more test cases
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/TestCaseCreateRequest'
                - type: array
                  items:
                    $ref: '#/components/schemas/TestCaseCreateRequest'
      responses:
        '200':
          description: Test case(s) created successfully
components:
  schemas:
    TestCaseCreateRequest:
      type: object
      properties:
        title:
          type: string
          description: Title of the test case
        variablesRichContent:
          type: object
          description: Key-value pairs of rich content variables
          additionalProperties:
            type: string
        promptId:
          type: string
          format: uuid
          description: UUID of the prompt to create test cases for
        expectedOutput:
          type: string
          nullable: true
          description: Expected output for evaluation purposes
        promptApplicationId:
          type: string
          format: uuid
          nullable: true
          description: UUID of the prompt application if applicable
        messages:
          type: array
          description: Array of message objects with role and content
          items:
            type: object
            properties:
              role:
                type: string
                enum:
                  - user
                  - system
                  - assistant
                  - function
                  - developer
                description: The role of the message sender
              content:
                description: The content of the message
                oneOf:
                  - type: string
                  - type: object
                    additionalProperties: true
            required:
              - role
              - content
        variables:
          type: object
          nullable: true
          description: Key-value pairs of variables used in the test case
          additionalProperties:
            type: string
        files:
          type: array
          nullable: true
          description: Array of file objects to attach to the test case
          items:
            type: object
            properties:
              index:
                type: number
              name:
                type: string
              mimeType:
                type: string
              vaultUrl:
                type: string
              variableName:
                type: string
              url:
                type: string
            required:
              - index
              - name
              - mimeType
              - vaultUrl
              - variableName
              - url
        metadata:
          type: object
          description: Metadata about the test case
          properties:
            source:
              type: string
              enum:
                - workstation
                - craft
                - test-case
      required:
        - variablesRichContent
        - promptId
        - messages

````