# KVS Cleanup - Find & Delete Large Records (`olgaz/kvs-cleanup`) Actor

Scans all key-value stores in your account, ranks records by size, and optionally deletes selected ones.

- **URL**: https://apify.com/olgaz/kvs-cleanup.md
- **Developed by:** [Olga Zagrubska](https://apify.com/olgaz) (community)
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## KVS Cleanup - Find & Delete Large Key-Value Stores

Scans all key-value stores in your Apify account, ranks them by size, and optionally deletes the largest stores or individual records.

### What it does

1. Lists all key-value stores in your account
2. Calculates the total size of each store by summing all record sizes
3. Outputs the largest stores and largest individual records to a dataset
4. Optionally deletes entire stores or individual records above a size threshold

### Why use it

Key-value stores can accumulate over time from Actor runs, especially ones that save screenshots, HTML snapshots, or large JSON files. This Actor helps you find what's taking up space and clean it up.

### Input

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `topN` | number | 50 | How many of the largest stores and records to show |
| `deleteStoresAboveMB` | number | 0 | Delete entire stores larger than this (MB). 0 = don't delete |
| `deleteRecordsAboveMB` | number | 0 | Delete individual records larger than this (MB). 0 = don't delete |
| `dryRun` | boolean | true | Preview what would be deleted without actually deleting |

### Usage examples

#### Just scan (no deletion)

Leave all defaults. The Actor scans every store and outputs the top 50 largest stores and records.

```json
{
    "topN": 50
}
```

#### Preview what you'd delete

See which stores are over 100 MB without deleting anything:

```json
{
    "deleteStoresAboveMB": 100,
    "dryRun": true
}
```

#### Delete large stores

Delete all stores over 100 MB:

```json
{
    "deleteStoresAboveMB": 100,
    "dryRun": false
}
```

#### Delete large individual records

Delete individual records over 10 MB (keeps the stores, just removes big records):

```json
{
    "deleteRecordsAboveMB": 10,
    "dryRun": false
}
```

### Output

The dataset contains two types of rows:

**Store rows** (`type: "store"`):
| Field | Description |
|-------|-------------|
| `storeName` | Name of the store (or "(unnamed)") |
| `storeId` | Store ID |
| `totalSizeMB` | Total size of all records in the store |
| `recordCount` | Number of records |
| `createdAt` | When the store was created |
| `modifiedAt` | When the store was last modified |

**Record rows** (`type: "record"`):
| Field | Description |
|-------|-------------|
| `storeName` | Name of the parent store |
| `storeId` | Parent store ID |
| `key` | Record key |
| `sizeMB` | Size of the record |

A summary is also saved to the key-value store under the `OUTPUT` key with totals and the top stores and records.

# Actor input Schema

## `topN` (type: `integer`):

How many of the largest stores and records to output.

## `deleteStoresAboveMB` (type: `number`):

Delete whole KVS stores larger than this total size. 0 = don't delete stores.

## `deleteRecordsAboveMB` (type: `number`):

Delete individual KVS records larger than this. 0 = don't delete records.

## `dryRun` (type: `boolean`):

When true, shows what would be deleted without actually deleting. Set to false to delete for real.

## Actor input object example

```json
{
  "topN": 50,
  "deleteStoresAboveMB": 0,
  "deleteRecordsAboveMB": 0,
  "dryRun": true
}
```

# Actor output Schema

## `dataset` (type: `string`):

Dataset containing the largest stores and records ranked by size

## `files` (type: `string`):

Key-value store containing the summary output

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("olgaz/kvs-cleanup").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("olgaz/kvs-cleanup").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call olgaz/kvs-cleanup --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,olgaz/kvs-cleanup"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/d8OPizdEzfPQbqYAT/builds/8vM9CaEiDNjfGYDtz/openapi.json
