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

# Create dataset

Creates a new dataset, either populated with existing logs or empty for manual population. You can specify filters and sampling rate to select which logs to include, or create an empty dataset to add logs manually later.

## Authentication

All endpoints require API key authentication:

```bash theme={"system"}
Authorization: Bearer YOUR_API_KEY
```

## Parameters

<ParamField body="name" type="string" required>
  The name of the dataset.
</ParamField>

<ParamField body="description" type="string">
  A description of the dataset.
</ParamField>

<ParamField body="sampling" type="integer" default="100">
  Percentage of logs to include (0-100).
</ParamField>

<ParamField body="start_time" type="string">
  ISO 8601 timestamp for log filtering. Required when `is_empty` is false or not provided. Ignored when `is_empty` is true.
</ParamField>

<ParamField body="end_time" type="string">
  ISO 8601 timestamp for log filtering. Required when `is_empty` is false or not provided. Ignored when `is_empty` is true.
</ParamField>

<ParamField body="is_empty" type="boolean" default="false">
  Create empty dataset. When `true`, `start_time` and `end_time` are ignored.
</ParamField>

<ParamField body="initial_log_filters" type="object">
  Filters to apply to select logs for the dataset.

  <Accordion title="Example">
    ```json theme={"system"}
    {
      "id": {
        "operator": "in",
        "value": ["log_id_1", "log_id_2"]
      }
    }
    ```
  </Accordion>
</ParamField>

## Request Examples

<CodeGroup>
  ```python Python - Populated Dataset theme={"system"}
  import requests
  import json

  url = "https://api.keywordsai.co/api/datasets/"

  payload = json.dumps({
    "name": "Support Conversations - July",
    "description": "Sampled support chats for July",
    "sampling": 40,
    "start_time": "2025-07-01T00:00:00Z",
    "end_time": "2025-07-31T23:59:59Z",
    "initial_log_filters": {
      "status_code": {
        "operator": "eq",
        "value": 200
      }
    }
  })
  headers = {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```

  ```python Python - Empty Dataset theme={"system"}
  import requests
  import json

  url = "https://api.keywordsai.co/api/datasets/"

  payload = json.dumps({
    "name": "Custom Workflow Logs",
    "description": "Manually curated logs for workflow analysis",
    "is_empty": true
  })
  headers = {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```
</CodeGroup>

## Response

<ResponseExample>
  ```json 201 Created - Populated Dataset theme={"system"}
  {
    "id": "6d0b2c7e-3a6a-4c09-9c7e-1f2d9e2d3f0a",
    "name": "Support Conversations - July",
    "description": "Sampled support chats for July",
    "type": "sampling",
    "status": "ready",
    "log_count": 250,
    "created_at": "2025-07-26T00:00:00Z"
  }
  ```

  ```json 201 Created - Empty Dataset theme={"system"}
  {
    "id": "6d0b2c7e-3a6a-4c09-9c7e-1f2d9e2d3f0a",
    "name": "Custom Workflow Logs",
    "description": "Manually curated logs for workflow analysis",
    "type": "sampling",
    "status": "ready",
    "log_count": 0,
    "created_at": "2025-12-09T10:00:00Z"
  }
  ```
</ResponseExample>
