KosmoKrator

analytics

Amplitude Analytics Lua API for KosmoKrator Agents

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

7 functions 7 read 0 write API key auth

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.

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

NameTypeRequiredDescription
user_idstringnoFilter by Amplitude user ID
device_idstringnoFilter by device ID
startstringnoStart timestamp (ISO 8601 or milliseconds epoch)
endstringnoEnd timestamp (ISO 8601 or milliseconds epoch)
limitintegernoMaximum 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

NameTypeRequiredDescription
idstringyesThe 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

NameTypeRequiredDescription
project_idintegernoFilter by Amplitude project ID
limitintegernoMaximum 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

NameTypeRequiredDescription
idstringyesThe 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

NameTypeRequiredDescription
project_idintegernoFilter by Amplitude project ID
limitintegernoMaximum 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

NameTypeRequiredDescription
idstringyesThe 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.

Metadata-Derived Lua Example

local result = app.integrations.amplitude.amplitude_list_events({
  user_id = "example_user_id",
  device_id = "example_device_id",
  start = "example_start",
  end = "example_end",
  limit = 1
})
print(result)

Functions

amplitude_list_events

List events from Amplitude Analytics. Optionally filter by user ID, device ID, or time range. Returns the most recent events matching the criteria.

Operation
Read read
Full name
amplitude.amplitude_list_events
ParameterTypeRequiredDescription
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).

amplitude_get_event

Retrieve a single Amplitude event by its ID. Returns full event details including all event properties and metadata.

Operation
Read read
Full name
amplitude.amplitude_get_event
ParameterTypeRequiredDescription
id string yes The Amplitude event ID.

amplitude_list_funnels

List funnels configured in Amplitude. Optionally filter by project ID. Returns funnel names, IDs, and summary conversion metrics.

Operation
Read read
Full name
amplitude.amplitude_list_funnels
ParameterTypeRequiredDescription
project_id integer no Filter by Amplitude project ID.
limit integer no Maximum number of funnels to return (default: 100).

amplitude_get_funnel

Retrieve a single Amplitude funnel by its ID. Returns the full funnel definition including steps, conversion rates, and drop-off metrics.

Operation
Read read
Full name
amplitude.amplitude_get_funnel
ParameterTypeRequiredDescription
id string yes The Amplitude funnel ID.

amplitude_list_cohorts

List behavioral cohorts in Amplitude. Optionally filter by project ID. Returns cohort names, IDs, and membership counts.

Operation
Read read
Full name
amplitude.amplitude_list_cohorts
ParameterTypeRequiredDescription
project_id integer no Filter by Amplitude project ID.
limit integer no Maximum number of cohorts to return (default: 100).

amplitude_get_cohort

Retrieve a single Amplitude cohort by its ID. Returns the full cohort definition including behavioral criteria and membership size.

Operation
Read read
Full name
amplitude.amplitude_get_cohort
ParameterTypeRequiredDescription
id string yes The Amplitude cohort ID.

amplitude_get_current_user

Get the currently authenticated Amplitude user. Returns account details for the API key owner — useful for verifying credentials and checking permissions.

Operation
Read read
Full name
amplitude.amplitude_get_current_user
ParameterTypeRequiredDescription
No parameters.