KosmoKrator

automation

Apify Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Apify KosmoKrator integration.

10 functions 9 read 1 write API token auth

Lua Namespace

Agents call this integration through app.integrations.apify.*. Use lua_read_doc("integrations.apify") inside KosmoKrator to discover the same reference at runtime.

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

Apify — Lua API Reference

run_actor

Run an Apify actor with input configuration. Returns the run details including run ID and status.

Parameters

NameTypeRequiredDescription
actorIdstringyesActor ID (e.g. "apify/web-scraper") or numeric ID
inputobjectyesInput configuration for the actor (structure depends on the actor)
buildstringnoActor build tag ("latest", "beta", etc.)
waitForFinishintegernoMax seconds to wait for the run to finish (0–300, default: 0)
timeoutintegernoTimeout for the actor run in seconds
memoryintegernoMemory in MB (128, 256, 512, 1024, 2048, 4096, 8192)

Examples

-- Run a web scraper actor
local result = app.integrations.apify.run_actor({
  actorId = "apify/web-scraper",
  input = {
    startUrls = {
      { url = "https://example.com" }
    },
    linkSelector = "a[href]",
    globPatterns = { "https://example.com/*" },
    pageFunction = "async function pageFunction(context) { return { url: context.request.url, title: (await context.page.title()) }; }"
  },
  waitForFinish = 120
})

print("Run ID: " .. result.id)
print("Status: " .. result.status)
print("Dataset ID: " .. result.defaultDatasetId)
-- Run and check status later
local run = app.integrations.apify.run_actor({
  actorId = "apify/cheerio-scraper",
  input = {
    startUrls = { { url = "https://news.ycombinator.com" } },
    globs = { "https://news.ycombinator.com/*" }
  }
})

-- Poll for completion
local status = app.integrations.apify.get_run({ runId = run.id })
while status.status == "RUNNING" do
  os.execute("sleep 5")
  status = app.integrations.apify.get_run({ runId = run.id })
end

print("Run finished with status: " .. status.status)

get_run

Get details and status of an actor run.

Parameters

NameTypeRequiredDescription
runIdstringyesThe actor run ID

Run Statuses

StatusDescription
READYRun is queued but not started
RUNNINGRun is currently executing
SUCCEEDEDRun completed successfully
FAILEDRun ended with an error
ABORTEDRun was manually aborted
TIMING-OUTRun is about to time out
TIMED-OUTRun exceeded its timeout

Example

local run = app.integrations.apify.get_run({ runId = "abc123XYZ" })
print("Status: " .. run.status)
print("Dataset: " .. (run.defaultDatasetId or "none"))
print("Duration: " .. (run.durationMillis or 0) .. "ms")

list_actors

List actors available to the authenticated user.

Parameters

NameTypeRequiredDescription
offsetintegernoNumber of actors to skip (default: 0)
limitintegernoMaximum actors to return (default: 20, max: 1000)

Example

local result = app.integrations.apify.list_actors({ limit = 10 })

for _, actor in ipairs(result.actors) do
  print(actor.fullName .. ": " .. (actor.description or "no description"))
end

get_actor

Get details of a specific actor, including its input schema.

Parameters

NameTypeRequiredDescription
actorIdstringyesActor ID (e.g. "apify/web-scraper")

Example

local actor = app.integrations.apify.get_actor({ actorId = "apify/web-scraper" })
print("Name: " .. actor.fullName)
print("Description: " .. (actor.description or ""))

-- Check input schema to understand required parameters
if actor.inputSchema then
  for key, schema in pairs(actor.inputSchema.properties or {}) do
    print("  Input: " .. key .. " (" .. (schema.type or "?") .. ")")
  end
end

list_datasets

List datasets accessible to the authenticated user.

Parameters

NameTypeRequiredDescription
offsetintegernoNumber of datasets to skip (default: 0)
limitintegernoMaximum datasets to return (default: 20, max: 1000)

Example

local result = app.integrations.apify.list_datasets({ limit = 10 })

for _, ds in ipairs(result.datasets) do
  print(ds.id .. " (" .. (ds.name or "unnamed") .. "): " .. ds.itemCount .. " items")
end

get_dataset

Get details of a specific dataset.

Parameters

NameTypeRequiredDescription
datasetIdstringyesThe dataset ID

Example

local ds = app.integrations.apify.get_dataset({ datasetId = "abc123XYZ" })
print("Items: " .. ds.itemCount)
print("Name: " .. (ds.name or "unnamed"))

get_dataset_items

Retrieve items from a dataset.

Parameters

NameTypeRequiredDescription
datasetIdstringyesThe dataset ID
formatstringnoResponse format: "json" (default), "csv", "xml", "html", "xlsx", "rss", "jsonl"
limitintegernoMax items to return (default: 100)
offsetintegernoNumber of items to skip (default: 0)

Example

-- Get first 50 items from a dataset
local result = app.integrations.apify.get_dataset_items({
  datasetId = "abc123XYZ",
  limit = 50
})

for _, item in ipairs(result.items) do
  print(item.url .. ": " .. (item.title or ""))
end
-- Export as CSV
local result = app.integrations.apify.get_dataset_items({
  datasetId = "abc123XYZ",
  format = "csv"
})
-- result.data contains the raw CSV string

list_key_value_stores

List key-value stores accessible to the authenticated user.

Parameters

NameTypeRequiredDescription
offsetintegernoNumber of stores to skip (default: 0)
limitintegernoMaximum stores to return (default: 20, max: 1000)

Example

local result = app.integrations.apify.list_key_value_stores({ limit = 10 })

for _, store in ipairs(result.stores) do
  print(store.id .. " (" .. (store.name or "unnamed") .. ")")
end

get_record

Get a record from a key-value store by its key.

Parameters

NameTypeRequiredDescription
storeIdstringyesThe key-value store ID
keystringyesRecord key (e.g. "OUTPUT", "SCREENSHOT")

Common Record Keys

KeyDescription
OUTPUTActor’s main output result
SCREENSHOTPage screenshot (PNG/JPEG)
PAGE_CONTENTRaw page HTML content

Example

-- Get actor output
local record = app.integrations.apify.get_record({
  storeId = "store123ABC",
  key = "OUTPUT"
})

if record.type == "json" then
  for k, v in pairs(record.data) do
    print(k .. ": " .. tostring(v))
  end
end

get_current_user

Get the authenticated user’s profile.

Parameters

None.

Example

local user = app.integrations.apify.get_current_user({})
print("User: " .. user.username)
print("Plan: " .. (user.plan or "free"))
print("Monthly usage: $" .. (user.monthlyUsageUsd or 0))

Multi-Account Usage

If you have multiple Apify accounts configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.apify.run_actor({...})

-- Explicit default (portable across setups)
app.integrations.apify.default.run_actor({...})

-- Named accounts
app.integrations.apify.production.run_actor({...})
app.integrations.apify.staging.run_actor({...})

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# Apify — Lua API Reference

## run_actor

Run an Apify actor with input configuration. Returns the run details including run ID and status.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `actorId` | string | yes | Actor ID (e.g. `"apify/web-scraper"`) or numeric ID |
| `input` | object | yes | Input configuration for the actor (structure depends on the actor) |
| `build` | string | no | Actor build tag (`"latest"`, `"beta"`, etc.) |
| `waitForFinish` | integer | no | Max seconds to wait for the run to finish (0–300, default: 0) |
| `timeout` | integer | no | Timeout for the actor run in seconds |
| `memory` | integer | no | Memory in MB (128, 256, 512, 1024, 2048, 4096, 8192) |

### Examples

```lua
-- Run a web scraper actor
local result = app.integrations.apify.run_actor({
  actorId = "apify/web-scraper",
  input = {
    startUrls = {
      { url = "https://example.com" }
    },
    linkSelector = "a[href]",
    globPatterns = { "https://example.com/*" },
    pageFunction = "async function pageFunction(context) { return { url: context.request.url, title: (await context.page.title()) }; }"
  },
  waitForFinish = 120
})

print("Run ID: " .. result.id)
print("Status: " .. result.status)
print("Dataset ID: " .. result.defaultDatasetId)
```

```lua
-- Run and check status later
local run = app.integrations.apify.run_actor({
  actorId = "apify/cheerio-scraper",
  input = {
    startUrls = { { url = "https://news.ycombinator.com" } },
    globs = { "https://news.ycombinator.com/*" }
  }
})

-- Poll for completion
local status = app.integrations.apify.get_run({ runId = run.id })
while status.status == "RUNNING" do
  os.execute("sleep 5")
  status = app.integrations.apify.get_run({ runId = run.id })
end

print("Run finished with status: " .. status.status)
```

---

## get_run

Get details and status of an actor run.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `runId` | string | yes | The actor run ID |

### Run Statuses

| Status | Description |
|--------|-------------|
| `READY` | Run is queued but not started |
| `RUNNING` | Run is currently executing |
| `SUCCEEDED` | Run completed successfully |
| `FAILED` | Run ended with an error |
| `ABORTED` | Run was manually aborted |
| `TIMING-OUT` | Run is about to time out |
| `TIMED-OUT` | Run exceeded its timeout |

### Example

```lua
local run = app.integrations.apify.get_run({ runId = "abc123XYZ" })
print("Status: " .. run.status)
print("Dataset: " .. (run.defaultDatasetId or "none"))
print("Duration: " .. (run.durationMillis or 0) .. "ms")
```

---

## list_actors

List actors available to the authenticated user.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `offset` | integer | no | Number of actors to skip (default: 0) |
| `limit` | integer | no | Maximum actors to return (default: 20, max: 1000) |

### Example

```lua
local result = app.integrations.apify.list_actors({ limit = 10 })

for _, actor in ipairs(result.actors) do
  print(actor.fullName .. ": " .. (actor.description or "no description"))
end
```

---

## get_actor

Get details of a specific actor, including its input schema.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `actorId` | string | yes | Actor ID (e.g. `"apify/web-scraper"`) |

### Example

```lua
local actor = app.integrations.apify.get_actor({ actorId = "apify/web-scraper" })
print("Name: " .. actor.fullName)
print("Description: " .. (actor.description or ""))

-- Check input schema to understand required parameters
if actor.inputSchema then
  for key, schema in pairs(actor.inputSchema.properties or {}) do
    print("  Input: " .. key .. " (" .. (schema.type or "?") .. ")")
  end
end
```

---

## list_datasets

List datasets accessible to the authenticated user.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `offset` | integer | no | Number of datasets to skip (default: 0) |
| `limit` | integer | no | Maximum datasets to return (default: 20, max: 1000) |

### Example

```lua
local result = app.integrations.apify.list_datasets({ limit = 10 })

for _, ds in ipairs(result.datasets) do
  print(ds.id .. " (" .. (ds.name or "unnamed") .. "): " .. ds.itemCount .. " items")
end
```

---

## get_dataset

Get details of a specific dataset.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `datasetId` | string | yes | The dataset ID |

### Example

```lua
local ds = app.integrations.apify.get_dataset({ datasetId = "abc123XYZ" })
print("Items: " .. ds.itemCount)
print("Name: " .. (ds.name or "unnamed"))
```

---

## get_dataset_items

Retrieve items from a dataset.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `datasetId` | string | yes | The dataset ID |
| `format` | string | no | Response format: `"json"` (default), `"csv"`, `"xml"`, `"html"`, `"xlsx"`, `"rss"`, `"jsonl"` |
| `limit` | integer | no | Max items to return (default: 100) |
| `offset` | integer | no | Number of items to skip (default: 0) |

### Example

```lua
-- Get first 50 items from a dataset
local result = app.integrations.apify.get_dataset_items({
  datasetId = "abc123XYZ",
  limit = 50
})

for _, item in ipairs(result.items) do
  print(item.url .. ": " .. (item.title or ""))
end
```

```lua
-- Export as CSV
local result = app.integrations.apify.get_dataset_items({
  datasetId = "abc123XYZ",
  format = "csv"
})
-- result.data contains the raw CSV string
```

---

## list_key_value_stores

List key-value stores accessible to the authenticated user.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `offset` | integer | no | Number of stores to skip (default: 0) |
| `limit` | integer | no | Maximum stores to return (default: 20, max: 1000) |

### Example

```lua
local result = app.integrations.apify.list_key_value_stores({ limit = 10 })

for _, store in ipairs(result.stores) do
  print(store.id .. " (" .. (store.name or "unnamed") .. ")")
end
```

---

## get_record

Get a record from a key-value store by its key.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `storeId` | string | yes | The key-value store ID |
| `key` | string | yes | Record key (e.g. `"OUTPUT"`, `"SCREENSHOT"`) |

### Common Record Keys

| Key | Description |
|-----|-------------|
| `OUTPUT` | Actor's main output result |
| `SCREENSHOT` | Page screenshot (PNG/JPEG) |
| `PAGE_CONTENT` | Raw page HTML content |

### Example

```lua
-- Get actor output
local record = app.integrations.apify.get_record({
  storeId = "store123ABC",
  key = "OUTPUT"
})

if record.type == "json" then
  for k, v in pairs(record.data) do
    print(k .. ": " .. tostring(v))
  end
end
```

---

## get_current_user

Get the authenticated user's profile.

### Parameters

None.

### Example

```lua
local user = app.integrations.apify.get_current_user({})
print("User: " .. user.username)
print("Plan: " .. (user.plan or "free"))
print("Monthly usage: $" .. (user.monthlyUsageUsd or 0))
```

---

## Multi-Account Usage

If you have multiple Apify accounts configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.apify.run_actor({...})

-- Explicit default (portable across setups)
app.integrations.apify.default.run_actor({...})

-- Named accounts
app.integrations.apify.production.run_actor({...})
app.integrations.apify.staging.run_actor({...})
```

All functions are identical across accounts — only the credentials differ.

Metadata-Derived Lua Example

local result = app.integrations.apify.apify_run_actor({
  actorId = "example_actorId",
  input = "example_input",
  build = "example_build",
  waitForFinish = 1,
  timeout = 1,
  memory = 1
})
print(result)

Functions

apify_run_actor

Run an Apify actor. Provide the actor ID and input configuration to start a new run. Returns the run details including run ID and status. Use apify_get_run to check progress.

Operation
Write write
Full name
apify.apify_run_actor
ParameterTypeRequiredDescription
actorId string yes The actor ID (e.g., "apify/web-scraper", "apify/cheerio-scraper") or numeric ID.
input object yes The input configuration for the actor run. Structure depends on the specific actor.
build string no Actor build to use (e.g., "latest", "beta"). Defaults to the latest build.
waitForFinish integer no Maximum seconds to wait for the run to finish (0–300). Defaults to 0 (return immediately).
timeout integer no Timeout for the actor run in seconds. Overrides the actor's default timeout.
memory integer no Memory allocation in megabytes (128, 256, 512, 1024, 2048, 4096, 8192). Overrides the actor's default.

apify_get_run

Get details and status of an Apify actor run. Returns the run status (READY, RUNNING, SUCCEEDED, FAILED, ABORTED, TIMING-OUT, TIMED-OUT), output dataset ID, and other metadata.

Operation
Read read
Full name
apify.apify_get_run
ParameterTypeRequiredDescription
runId string yes The actor run ID.

apify_list_actors

List Apify actors available to the authenticated user. Returns actor names, IDs, descriptions, and versions. Supports pagination with offset and limit.

Operation
Read read
Full name
apify.apify_list_actors
ParameterTypeRequiredDescription
offset integer no Number of actors to skip (default: 0).
limit integer no Maximum number of actors to return (default: 20, max: 1000).

apify_get_actor

Get details of a specific Apify actor, including its description, input schema, default run options, and available versions. Use this to understand what input an actor requires before running it.

Operation
Read read
Full name
apify.apify_get_actor
ParameterTypeRequiredDescription
actorId string yes The actor ID (e.g., "apify/web-scraper") or numeric ID.

apify_list_datasets

List Apify datasets accessible to the authenticated user. Returns dataset IDs, names, item counts, and sizes. Supports pagination.

Operation
Read read
Full name
apify.apify_list_datasets
ParameterTypeRequiredDescription
offset integer no Number of datasets to skip (default: 0).
limit integer no Maximum number of datasets to return (default: 20, max: 1000).

apify_get_dataset

Get details of a specific Apify dataset, including its item count, size, name, and associated actor run. Use apify_get_dataset_items to retrieve the actual data.

Operation
Read read
Full name
apify.apify_get_dataset
ParameterTypeRequiredDescription
datasetId string yes The dataset ID.

apify_get_dataset_items

Retrieve items from an Apify dataset. Supports JSON, CSV, and other formats. Use this to get the results from completed actor runs. Datasets are referenced by ID from run results.

Operation
Read read
Full name
apify.apify_get_dataset_items
ParameterTypeRequiredDescription
datasetId string yes The dataset ID (e.g., from a run's defaultDatasetId).
format string no Response format: "json" (default), "csv", "xml", "html", "xlsx", "rss", or "jsonl".
limit integer no Maximum number of items to return (default: 100).
offset integer no Number of items to skip (default: 0).

apify_list_key_value_stores

List Apify key-value stores accessible to the authenticated user. Key-value stores hold actor outputs like screenshots, PDFs, or JSON results. Supports pagination.

Operation
Read read
Full name
apify.apify_list_key_value_stores
ParameterTypeRequiredDescription
offset integer no Number of stores to skip (default: 0).
limit integer no Maximum number of stores to return (default: 20, max: 1000).

apify_get_record

Get a record from an Apify key-value store by its key. Common keys include "OUTPUT" for actor results, "SCREENSHOT" for page screenshots, or custom keys set by actor runs.

Operation
Read read
Full name
apify.apify_get_record
ParameterTypeRequiredDescription
storeId string yes The key-value store ID (e.g., from a run's defaultKeyValueStoreId).
key string yes The record key (e.g., "OUTPUT", "SCREENSHOT", or a custom key).

apify_get_current_user

Get the profile of the currently authenticated Apify user. Returns user ID, username, email, plan details, and monthly usage information.

Operation
Read read
Full name
apify.apify_get_current_user
ParameterTypeRequiredDescription
No parameters.