analytics
Amplitude Analytics Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the Amplitude Analytics KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.amplitude.*.
Use lua_read_doc("integrations.amplitude") inside KosmoKrator to discover the same reference at runtime.
Call Lua from the Headless CLI
Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic
Amplitude Analytics workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.amplitude.list_events({user_id = "example_user_id", device_id = "example_device_id", start = "example_start", end = "example_end", limit = 1}))' --json kosmo integrations:lua --eval 'print(docs.read("amplitude"))' --json
kosmo integrations:lua --eval 'print(docs.read("amplitude.list_events"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local amplitude = app.integrations.amplitude
local result = amplitude.list_events({user_id = "example_user_id", device_id = "example_device_id", start = "example_start", end = "example_end", limit = 1})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.amplitude, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.amplitude.default.* or app.integrations.amplitude.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need Amplitude Analytics, use the narrower mcp:lua command.
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json Agent-Facing Lua Docs
This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.
Amplitude Analytics — Lua API Reference
list_events
List events from Amplitude, optionally filtered by user, device, or time range.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
user_id | string | no | Filter by Amplitude user ID |
device_id | string | no | Filter by device ID |
start | string | no | Start timestamp (ISO 8601 or milliseconds epoch) |
end | string | no | End timestamp (ISO 8601 or milliseconds epoch) |
limit | integer | no | Maximum number of events to return (default: 1000) |
Examples
-- Get recent events for a user
local result = app.integrations.amplitude.list_events({
user_id = "user_123",
limit = 50
})
for _, event in ipairs(result.events or {}) do
print(event.event_type .. " at " .. event.server_received_time)
end
-- Get events in a time range
local result = app.integrations.amplitude.list_events({
start = "2025-01-01T00:00:00Z",
end = "2025-01-31T23:59:59Z",
limit = 100
})
get_event
Retrieve a single event by its ID.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
id | string | yes | The Amplitude event ID |
Example
local result = app.integrations.amplitude.get_event({
id = "12345"
})
print("Event: " .. result.event_type)
print("User: " .. result.user_id)
list_funnels
List funnels configured in the Amplitude project.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
project_id | integer | no | Filter by Amplitude project ID |
limit | integer | no | Maximum number of funnels to return (default: 100) |
Example
local result = app.integrations.amplitude.list_funnels({
limit = 20
})
for _, funnel in ipairs(result.funnels or result.data or {}) do
print("Funnel: " .. (funnel.name or funnel.id) .. " — conversion: " .. tostring(funnel.conversion_rate or "N/A"))
end
get_funnel
Retrieve a single funnel by its ID with conversion metrics and step details.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
id | string | yes | The Amplitude funnel ID |
Example
local result = app.integrations.amplitude.get_funnel({
id = "42"
})
print("Funnel: " .. result.name)
for _, step in ipairs(result.steps or {}) do
print(" Step: " .. step.event_type .. " — " .. tostring(step.count) .. " users")
end
list_cohorts
List behavioral cohorts in the Amplitude project.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
project_id | integer | no | Filter by Amplitude project ID |
limit | integer | no | Maximum number of cohorts to return (default: 100) |
Example
local result = app.integrations.amplitude.list_cohorts({
limit = 20
})
for _, cohort in ipairs(result.cohorts or result.data or {}) do
print("Cohort: " .. (cohort.name or cohort.id) .. " — size: " .. tostring(cohort.size or "N/A"))
end
get_cohort
Retrieve a single cohort by its ID with membership and behavioral criteria.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
id | string | yes | The Amplitude cohort ID |
Example
local result = app.integrations.amplitude.get_cohort({
id = "7"
})
print("Cohort: " .. result.name)
print("Members: " .. tostring(result.size or result.count or "N/A"))
get_current_user
Get the currently authenticated Amplitude user (caller identity).
Parameters
None.
Example
local result = app.integrations.amplitude.get_current_user({})
print("Logged in as: " .. (result.name or result.email or "unknown"))
print("Role: " .. (result.role or "N/A"))
Multi-Account Usage
If you have multiple Amplitude accounts configured, use account-specific namespaces:
-- Default account (always works)
app.integrations.amplitude.list_events({user_id = "user_123"})
-- Explicit default (portable across setups)
app.integrations.amplitude.default.list_events({user_id = "user_123"})
-- Named accounts
app.integrations.amplitude.production.list_events({user_id = "user_123"})
app.integrations.amplitude.staging.list_events({user_id = "user_123"})
All functions are identical across accounts — only the credentials differ.
Raw agent markdown
# Amplitude Analytics — Lua API Reference
## list_events
List events from Amplitude, optionally filtered by user, device, or time range.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `user_id` | string | no | Filter by Amplitude user ID |
| `device_id` | string | no | Filter by device ID |
| `start` | string | no | Start timestamp (ISO 8601 or milliseconds epoch) |
| `end` | string | no | End timestamp (ISO 8601 or milliseconds epoch) |
| `limit` | integer | no | Maximum number of events to return (default: 1000) |
### Examples
```lua
-- Get recent events for a user
local result = app.integrations.amplitude.list_events({
user_id = "user_123",
limit = 50
})
for _, event in ipairs(result.events or {}) do
print(event.event_type .. " at " .. event.server_received_time)
end
```
```lua
-- Get events in a time range
local result = app.integrations.amplitude.list_events({
start = "2025-01-01T00:00:00Z",
end = "2025-01-31T23:59:59Z",
limit = 100
})
```
---
## get_event
Retrieve a single event by its ID.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The Amplitude event ID |
### Example
```lua
local result = app.integrations.amplitude.get_event({
id = "12345"
})
print("Event: " .. result.event_type)
print("User: " .. result.user_id)
```
---
## list_funnels
List funnels configured in the Amplitude project.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `project_id` | integer | no | Filter by Amplitude project ID |
| `limit` | integer | no | Maximum number of funnels to return (default: 100) |
### Example
```lua
local result = app.integrations.amplitude.list_funnels({
limit = 20
})
for _, funnel in ipairs(result.funnels or result.data or {}) do
print("Funnel: " .. (funnel.name or funnel.id) .. " — conversion: " .. tostring(funnel.conversion_rate or "N/A"))
end
```
---
## get_funnel
Retrieve a single funnel by its ID with conversion metrics and step details.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The Amplitude funnel ID |
### Example
```lua
local result = app.integrations.amplitude.get_funnel({
id = "42"
})
print("Funnel: " .. result.name)
for _, step in ipairs(result.steps or {}) do
print(" Step: " .. step.event_type .. " — " .. tostring(step.count) .. " users")
end
```
---
## list_cohorts
List behavioral cohorts in the Amplitude project.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `project_id` | integer | no | Filter by Amplitude project ID |
| `limit` | integer | no | Maximum number of cohorts to return (default: 100) |
### Example
```lua
local result = app.integrations.amplitude.list_cohorts({
limit = 20
})
for _, cohort in ipairs(result.cohorts or result.data or {}) do
print("Cohort: " .. (cohort.name or cohort.id) .. " — size: " .. tostring(cohort.size or "N/A"))
end
```
---
## get_cohort
Retrieve a single cohort by its ID with membership and behavioral criteria.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The Amplitude cohort ID |
### Example
```lua
local result = app.integrations.amplitude.get_cohort({
id = "7"
})
print("Cohort: " .. result.name)
print("Members: " .. tostring(result.size or result.count or "N/A"))
```
---
## get_current_user
Get the currently authenticated Amplitude user (caller identity).
### Parameters
None.
### Example
```lua
local result = app.integrations.amplitude.get_current_user({})
print("Logged in as: " .. (result.name or result.email or "unknown"))
print("Role: " .. (result.role or "N/A"))
```
---
## Multi-Account Usage
If you have multiple Amplitude accounts configured, use account-specific namespaces:
```lua
-- Default account (always works)
app.integrations.amplitude.list_events({user_id = "user_123"})
-- Explicit default (portable across setups)
app.integrations.amplitude.default.list_events({user_id = "user_123"})
-- Named accounts
app.integrations.amplitude.production.list_events({user_id = "user_123"})
app.integrations.amplitude.staging.list_events({user_id = "user_123"})
```
All functions are identical across accounts — only the credentials differ. local result = app.integrations.amplitude.list_events({user_id = "example_user_id", device_id = "example_device_id", start = "example_start", end = "example_end", limit = 1})
print(result) Functions
list_events Read
List events from Amplitude Analytics. Optionally filter by user ID, device ID, or time range. Returns the most recent events matching the criteria.
- Lua path
app.integrations.amplitude.list_events- Full name
amplitude.amplitude_list_events
| Parameter | Type | Required | Description |
|---|---|---|---|
user_id | string | no | Filter events by Amplitude user ID. |
device_id | string | no | Filter events by device ID. |
start | string | no | Start timestamp (ISO 8601 e.g. "2025-01-01T00:00:00Z" or milliseconds epoch). |
end | string | no | End timestamp (ISO 8601 e.g. "2025-01-31T23:59:59Z" or milliseconds epoch). |
limit | integer | no | Maximum number of events to return (default: 1000). |
get_event Read
Retrieve a single Amplitude event by its ID. Returns full event details including all event properties and metadata.
- Lua path
app.integrations.amplitude.get_event- Full name
amplitude.amplitude_get_event
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | yes | The Amplitude event ID. |
list_funnels Read
List funnels configured in Amplitude. Optionally filter by project ID. Returns funnel names, IDs, and summary conversion metrics.
- Lua path
app.integrations.amplitude.list_funnels- Full name
amplitude.amplitude_list_funnels
| Parameter | Type | Required | Description |
|---|---|---|---|
project_id | integer | no | Filter by Amplitude project ID. |
limit | integer | no | Maximum number of funnels to return (default: 100). |
get_funnel Read
Retrieve a single Amplitude funnel by its ID. Returns the full funnel definition including steps, conversion rates, and drop-off metrics.
- Lua path
app.integrations.amplitude.get_funnel- Full name
amplitude.amplitude_get_funnel
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | yes | The Amplitude funnel ID. |
list_cohorts Read
List behavioral cohorts in Amplitude. Optionally filter by project ID. Returns cohort names, IDs, and membership counts.
- Lua path
app.integrations.amplitude.list_cohorts- Full name
amplitude.amplitude_list_cohorts
| Parameter | Type | Required | Description |
|---|---|---|---|
project_id | integer | no | Filter by Amplitude project ID. |
limit | integer | no | Maximum number of cohorts to return (default: 100). |
get_cohort Read
Retrieve a single Amplitude cohort by its ID. Returns the full cohort definition including behavioral criteria and membership size.
- Lua path
app.integrations.amplitude.get_cohort- Full name
amplitude.amplitude_get_cohort
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | yes | The Amplitude cohort ID. |
get_current_user Read
Get the currently authenticated Amplitude user. Returns account details for the API key owner — useful for verifying credentials and checking permissions.
- Lua path
app.integrations.amplitude.get_current_user- Full name
amplitude.amplitude_get_current_user
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||