{
  "openapi": "3.0.1",
  "info": {
    "title": "Dataset Sampler: random, stratified & seeded rows",
    "description": "Takes a sample of an Apify dataset or a CSV / JSON / NDJSON file: random N rows or percent, every k-th row, first or last N, or a fixed number per group of a column. Same seed gives the same sample. Handles huge inputs row by row. Empty input = free demo.",
    "version": "0.1",
    "x-build-id": "i5jFapQi81ZnN9xz2"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/ucchiii~dataset-sampler/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-ucchiii-dataset-sampler",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/acts/ucchiii~dataset-sampler/runs": {
      "post": {
        "operationId": "runs-sync-ucchiii-dataset-sampler",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor and returns information about the initiated run in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/runsResponseSchema"
                }
              }
            }
          }
        }
      }
    },
    "/acts/ucchiii~dataset-sampler/run-sync": {
      "post": {
        "operationId": "run-sync-ucchiii-dataset-sampler",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "inputSchema": {
        "type": "object",
        "properties": {
          "datasetIds": {
            "title": "Apify datasets",
            "type": "array",
            "description": "Datasets to sample from (the 'defaultDatasetId' of a finished run). You can paste a dataset URL from Apify Console too. Several datasets and files are read in the order given and sampled together as one table. Up to 20 in total. Leave this and 'File URLs' empty to run a free demo on a built-in sample (not charged)."
          },
          "fileUrls": {
            "title": "File URLs",
            "type": "array",
            "description": "Public http(s) links to CSV, TSV, JSON or NDJSON files (up to 100 MB each; a JSON array up to 50 MB, use NDJSON for bigger files). The encoding (UTF-8, Shift JIS, Windows-1252) and the delimiter are detected. Links to internal networks are blocked.",
            "items": {
              "type": "string"
            }
          },
          "method": {
            "title": "Method",
            "enum": [
              "random_n",
              "random_percent",
              "systematic",
              "first",
              "last",
              "stratified"
            ],
            "type": "string",
            "description": "How to pick the rows. Random N uses reservoir sampling and reads the input once. Random percentage and stratified percent read the input twice (first to count the rows, reading is free) so the number of rows is exact. First N stops reading after N rows. Default: Random N rows.",
            "default": "random_n"
          },
          "sampleSize": {
            "title": "Sample size (N)",
            "minimum": 1,
            "maximum": 1000000,
            "type": "integer",
            "description": "Number of rows for the methods Random N, First N and Last N. If the input has fewer rows, all of them are returned. Default: 100.",
            "default": 100
          },
          "samplePercent": {
            "title": "Sample percentage",
            "minimum": 0.0001,
            "maximum": 100,
            "type": "number",
            "description": "For the method Random percentage: the share of the rows to return, for example 5 for 5%. The result has the rounded number of rows (at least 1), not 'about' that many. Default: 10.",
            "default": 10
          },
          "step": {
            "title": "Every k-th row",
            "minimum": 1,
            "maximum": 1000000,
            "type": "integer",
            "description": "For the method Every k-th row: return one row out of every k, for example 100 returns rows 1, 101, 201 ... (rows counted after dedupe). Default: 10.",
            "default": 10
          },
          "startAt": {
            "title": "Start at row",
            "minimum": 1,
            "type": "integer",
            "description": "For the method Every k-th row: the row number (starting at 1) of the first row returned. Ignored when 'Random start' is on. Default: 1.",
            "default": 1
          },
          "randomStart": {
            "title": "Random start",
            "type": "boolean",
            "description": "For the method Every k-th row: begin at a random row among the first k, chosen from the seed. This avoids always picking the same position in a repeating pattern. Default: off.",
            "default": false
          },
          "stratifyBy": {
            "title": "Stratify by column",
            "type": "string",
            "description": "For the method Stratified: the column whose values form the groups, for example country or category. Nested fields use dots (owner.type). Rows with an empty value form their own group named '(empty)'. Required for stratified sampling."
          },
          "perGroupSize": {
            "title": "Rows per group",
            "minimum": 0,
            "maximum": 1000000,
            "type": "integer",
            "description": "For the method Stratified: number of random rows from every group. A smaller group is returned completely. Set this or 'Percent per group', not both. 0 = not used. Default: 0.",
            "default": 0
          },
          "perGroupPercent": {
            "title": "Percent per group",
            "minimum": 0,
            "maximum": 100,
            "type": "number",
            "description": "For the method Stratified: share of every group to return, for example 10 for 10% of each group (at least 1 row per group, so rare groups stay in the sample). Set this or 'Rows per group', not both. 0 = not used. Default: 0.",
            "default": 0
          },
          "seed": {
            "title": "Seed",
            "type": "string",
            "description": "Any text or number. The same seed on the same input (same rows in the same order) and the same settings gives exactly the same sample, so you can repeat a split or an audit. Empty = a new random seed each run; it is written to the run summary (record STATS) so you can reproduce the run later."
          },
          "dedupeFields": {
            "title": "Dedupe columns",
            "type": "array",
            "description": "Column names. Before sampling, a row whose values in these columns equal those of an earlier row is dropped, so every combination can be drawn only once (the first row of each stays). Two empty values are equal. Only a short fingerprint of each key is kept in memory. Empty list = no dedupe.",
            "items": {
              "type": "string"
            }
          },
          "addSampleIndex": {
            "title": "Add the row position",
            "type": "boolean",
            "description": "Add a field '_sampleIndex' to every output row: its position in the input (1 = first row read, counted across all sources before dedupe). Useful to find the row in the source again. Default: off.",
            "default": false
          },
          "addStratum": {
            "title": "Add the group",
            "type": "boolean",
            "description": "Add a field '_stratum' to every output row: the group value the row was sampled from. Only for the method Stratified. Default: off.",
            "default": false
          }
        }
      },
      "runsResponseSchema": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "actId": {
                "type": "string"
              },
              "userId": {
                "type": "string"
              },
              "startedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "finishedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "status": {
                "type": "string",
                "example": "READY"
              },
              "meta": {
                "type": "object",
                "properties": {
                  "origin": {
                    "type": "string",
                    "example": "API"
                  },
                  "userAgent": {
                    "type": "string"
                  }
                }
              },
              "stats": {
                "type": "object",
                "properties": {
                  "inputBodyLen": {
                    "type": "integer",
                    "example": 2000
                  },
                  "rebootCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "restartCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "resurrectCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "computeUnits": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "options": {
                "type": "object",
                "properties": {
                  "build": {
                    "type": "string",
                    "example": "latest"
                  },
                  "timeoutSecs": {
                    "type": "integer",
                    "example": 300
                  },
                  "memoryMbytes": {
                    "type": "integer",
                    "example": 1024
                  },
                  "diskMbytes": {
                    "type": "integer",
                    "example": 2048
                  }
                }
              },
              "buildId": {
                "type": "string"
              },
              "defaultKeyValueStoreId": {
                "type": "string"
              },
              "defaultDatasetId": {
                "type": "string"
              },
              "defaultRequestQueueId": {
                "type": "string"
              },
              "buildNumber": {
                "type": "string",
                "example": "1.0.0"
              },
              "containerUrl": {
                "type": "string"
              },
              "usage": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "integer",
                    "example": 1
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "usageTotalUsd": {
                "type": "number",
                "example": 0.00005
              },
              "usageUsd": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "number",
                    "example": 0.00005
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}