KosmoKrator

analytics

PostHog CLI for AI Agents

Use the PostHog CLI from KosmoKrator to call PostHog tools headlessly, return JSON, inspect schemas, and automate workflows from coding agents, scripts, and CI.

15 functions 11 read 4 write API token auth

PostHog CLI Setup

PostHog can be configured headlessly with `kosmokrator integrations:configure posthog`.

# Install KosmoKrator first if it is not available on PATH.
curl -fsSL https://raw.githubusercontent.com/OpenCompanyApp/kosmokrator/main/install.sh | bash

# Configure and verify this integration.
kosmokrator integrations:configure posthog --set api_token="$POSTHOG_API_TOKEN" --enable --read allow --write ask --json
kosmokrator integrations:doctor posthog --json
kosmokrator integrations:status --json

Credentials

Authentication type: API token api_token. Configure credentials once, then use the same stored profile from scripts, coding CLIs, Lua code mode, and the MCP gateway.

KeyEnv varTypeRequiredLabel
api_token POSTHOG_API_TOKEN Secret secret yes API Token
url POSTHOG_URL URL url no PostHog URL

Call PostHog Headlessly

Use the generic call form when another coding CLI or script needs a stable universal interface.

kosmo integrations:call posthog.posthog_capture_event '{
  "event": "example_event",
  "distinct_id": "example_distinct_id",
  "properties": "example_properties",
  "timestamp": "example_timestamp"
}' --json

Use the provider shortcut form for shorter human-facing commands.

kosmo integrations:posthog posthog_capture_event '{
  "event": "example_event",
  "distinct_id": "example_distinct_id",
  "properties": "example_properties",
  "timestamp": "example_timestamp"
}' --json

Agent Discovery Commands

These commands return structured output for coding agents that need to inspect capabilities before choosing a function.

kosmo integrations:docs posthog --json
kosmo integrations:docs posthog.posthog_capture_event --json
kosmo integrations:schema posthog.posthog_capture_event --json
kosmo integrations:search "PostHog" --json
kosmo integrations:list --json

All CLI Functions

Every function below can be called headlessly. The generic form is stable across all integrations; the provider shortcut is shorter but specific to PostHog.

posthog.posthog_capture_event

Write write

Send (capture) a custom event to PostHog for a specific user. The event will appear in the PostHog events stream and can be used in insights and funnels.

Parameters
event, distinct_id, properties, timestamp

Generic CLI call

kosmo integrations:call posthog.posthog_capture_event '{"event":"example_event","distinct_id":"example_distinct_id","properties":"example_properties","timestamp":"example_timestamp"}' --json

Provider shortcut

kosmo integrations:posthog posthog_capture_event '{"event":"example_event","distinct_id":"example_distinct_id","properties":"example_properties","timestamp":"example_timestamp"}' --json

posthog.posthog_list_events

Read read

List events from PostHog with optional filtering by event name, user, date range, and pagination.

Parameters
limit, offset, event, distinct_id, person_id, after, before

Generic CLI call

kosmo integrations:call posthog.posthog_list_events '{"limit":1,"offset":1,"event":"example_event","distinct_id":"example_distinct_id","person_id":"example_person_id","after":"example_after","before":"example_before"}' --json

Provider shortcut

kosmo integrations:posthog posthog_list_events '{"limit":1,"offset":1,"event":"example_event","distinct_id":"example_distinct_id","person_id":"example_person_id","after":"example_after","before":"example_before"}' --json

posthog.posthog_get_event

Read read

Get details of a specific PostHog event by its unique ID, including all event properties and metadata.

Parameters
event_id

Generic CLI call

kosmo integrations:call posthog.posthog_get_event '{"event_id":"example_event_id"}' --json

Provider shortcut

kosmo integrations:posthog posthog_get_event '{"event_id":"example_event_id"}' --json

posthog.posthog_list_persons

Read read

List persons (users) from PostHog. Optionally search by name, email, or distinct ID to find specific users.

Parameters
limit, offset, search

Generic CLI call

kosmo integrations:call posthog.posthog_list_persons '{"limit":1,"offset":1,"search":"example_search"}' --json

Provider shortcut

kosmo integrations:posthog posthog_list_persons '{"limit":1,"offset":1,"search":"example_search"}' --json

posthog.posthog_get_person

Read read

Get details of a specific PostHog person (user) by their unique ID, including properties and event history metadata.

Parameters
person_id

Generic CLI call

kosmo integrations:call posthog.posthog_get_person '{"person_id":"example_person_id"}' --json

Provider shortcut

kosmo integrations:posthog posthog_get_person '{"person_id":"example_person_id"}' --json

posthog.posthog_list_feature_flags

Read read

List all feature flags in the PostHog project, including their status, rollout percentages, and filter conditions.

Parameters
limit, offset

Generic CLI call

kosmo integrations:call posthog.posthog_list_feature_flags '{"limit":1,"offset":1}' --json

Provider shortcut

kosmo integrations:posthog posthog_list_feature_flags '{"limit":1,"offset":1}' --json

posthog.posthog_get_feature_flag

Read read

Get details of a specific PostHog feature flag by its ID, including rollout configuration and filter conditions.

Parameters
flag_id

Generic CLI call

kosmo integrations:call posthog.posthog_get_feature_flag '{"flag_id":1}' --json

Provider shortcut

kosmo integrations:posthog posthog_get_feature_flag '{"flag_id":1}' --json

posthog.posthog_create_feature_flag

Write write

Create a new feature flag in PostHog with a name, key, and optional rollout configuration.

Parameters
name, key, active, filters, rollout_percentage

Generic CLI call

kosmo integrations:call posthog.posthog_create_feature_flag '{"name":"example_name","key":"example_key","active":true,"filters":"example_filters","rollout_percentage":1}' --json

Provider shortcut

kosmo integrations:posthog posthog_create_feature_flag '{"name":"example_name","key":"example_key","active":true,"filters":"example_filters","rollout_percentage":1}' --json

posthog.posthog_update_feature_flag

Write write

Update an existing PostHog feature flag — change its active state, filters, or rollout percentage.

Parameters
flag_id, active, filters, rollout_percentage

Generic CLI call

kosmo integrations:call posthog.posthog_update_feature_flag '{"flag_id":1,"active":true,"filters":"example_filters","rollout_percentage":1}' --json

Provider shortcut

kosmo integrations:posthog posthog_update_feature_flag '{"flag_id":1,"active":true,"filters":"example_filters","rollout_percentage":1}' --json

posthog.posthog_delete_feature_flag

Write write

Delete a feature flag from PostHog. This action is permanent and cannot be undone.

Parameters
flag_id

Generic CLI call

kosmo integrations:call posthog.posthog_delete_feature_flag '{"flag_id":1}' --json

Provider shortcut

kosmo integrations:posthog posthog_delete_feature_flag '{"flag_id":1}' --json

posthog.posthog_list_insights

Read read

List saved insights in the PostHog project. Optionally filter by insight type (e.g., TRENDS, FUNNELS, RETENTION, PATHS).

Parameters
limit, offset, type

Generic CLI call

kosmo integrations:call posthog.posthog_list_insights '{"limit":1,"offset":1,"type":"example_type"}' --json

Provider shortcut

kosmo integrations:posthog posthog_list_insights '{"limit":1,"offset":1,"type":"example_type"}' --json

posthog.posthog_get_insight

Read read

Get details of a specific PostHog insight by its ID, including its query configuration and cached results.

Parameters
insight_id

Generic CLI call

kosmo integrations:call posthog.posthog_get_insight '{"insight_id":1}' --json

Provider shortcut

kosmo integrations:posthog posthog_get_insight '{"insight_id":1}' --json

posthog.posthog_list_dashboards

Read read

List dashboards in the PostHog project. Dashboards contain collections of insights organized for monitoring.

Parameters
limit, offset

Generic CLI call

kosmo integrations:call posthog.posthog_list_dashboards '{"limit":1,"offset":1}' --json

Provider shortcut

kosmo integrations:posthog posthog_list_dashboards '{"limit":1,"offset":1}' --json

posthog.posthog_get_dashboard

Read read

Get details of a specific PostHog dashboard by its ID, including its layout and contained insights.

Parameters
dashboard_id

Generic CLI call

kosmo integrations:call posthog.posthog_get_dashboard '{"dashboard_id":1}' --json

Provider shortcut

kosmo integrations:posthog posthog_get_dashboard '{"dashboard_id":1}' --json

posthog.posthog_list_cohorts

Read read

List cohorts in the PostHog project. Cohorts are dynamic groups of users defined by behavioral or property conditions.

Parameters
limit, offset

Generic CLI call

kosmo integrations:call posthog.posthog_list_cohorts '{"limit":1,"offset":1}' --json

Provider shortcut

kosmo integrations:posthog posthog_list_cohorts '{"limit":1,"offset":1}' --json

Function Schemas

Use these parameter tables when building CLI payloads without calling integrations:schema first.

posthog.posthog_capture_event

Send (capture) a custom event to PostHog for a specific user. The event will appear in the PostHog events stream and can be used in insights and funnels.

Operation
Write write
Schema command
kosmo integrations:schema posthog.posthog_capture_event --json
ParameterTypeRequiredDescription
event string yes The name of the event to capture (e.g., "signup", "purchase", "button_clicked").
distinct_id string yes A unique identifier for the user performing the event (e.g., user ID, email, or anonymous ID).
properties object no Optional key-value properties to attach to the event.
timestamp string no Optional ISO 8601 timestamp for the event. Defaults to the current server time.

posthog.posthog_list_events

List events from PostHog with optional filtering by event name, user, date range, and pagination.

Operation
Read read
Schema command
kosmo integrations:schema posthog.posthog_list_events --json
ParameterTypeRequiredDescription
limit integer no Maximum number of events to return (default: 100).
offset integer no Number of events to skip for pagination (default: 0).
event string no Filter by event name (e.g., "$pageview", "signup").
distinct_id string no Filter by distinct user ID.
person_id string no Filter by internal person UUID.
after string no Only return events after this timestamp (ISO 8601, e.g., "2025-01-01T00:00:00Z").
before string no Only return events before this timestamp (ISO 8601, e.g., "2025-12-31T23:59:59Z").

posthog.posthog_get_event

Get details of a specific PostHog event by its unique ID, including all event properties and metadata.

Operation
Read read
Schema command
kosmo integrations:schema posthog.posthog_get_event --json
ParameterTypeRequiredDescription
event_id string yes The unique identifier of the event to retrieve.

posthog.posthog_list_persons

List persons (users) from PostHog. Optionally search by name, email, or distinct ID to find specific users.

Operation
Read read
Schema command
kosmo integrations:schema posthog.posthog_list_persons --json
ParameterTypeRequiredDescription
limit integer no Maximum number of persons to return (default: 100).
offset integer no Number of persons to skip for pagination (default: 0).
search string no Search query to filter persons by name, email, or distinct ID.

posthog.posthog_get_person

Get details of a specific PostHog person (user) by their unique ID, including properties and event history metadata.

Operation
Read read
Schema command
kosmo integrations:schema posthog.posthog_get_person --json
ParameterTypeRequiredDescription
person_id string yes The unique identifier (UUID) of the person to retrieve.

posthog.posthog_list_feature_flags

List all feature flags in the PostHog project, including their status, rollout percentages, and filter conditions.

Operation
Read read
Schema command
kosmo integrations:schema posthog.posthog_list_feature_flags --json
ParameterTypeRequiredDescription
limit integer no Maximum number of feature flags to return (default: 100).
offset integer no Number of feature flags to skip for pagination (default: 0).

posthog.posthog_get_feature_flag

Get details of a specific PostHog feature flag by its ID, including rollout configuration and filter conditions.

Operation
Read read
Schema command
kosmo integrations:schema posthog.posthog_get_feature_flag --json
ParameterTypeRequiredDescription
flag_id integer yes The unique identifier of the feature flag to retrieve.

posthog.posthog_create_feature_flag

Create a new feature flag in PostHog with a name, key, and optional rollout configuration.

Operation
Write write
Schema command
kosmo integrations:schema posthog.posthog_create_feature_flag --json
ParameterTypeRequiredDescription
name string yes Human-readable name for the feature flag (e.g., "New checkout flow").
key string yes Unique key used to reference the flag in code (e.g., "new-checkout"). Must be lowercase with hyphens.
active boolean no Whether the flag should be active immediately (default: true).
filters object no Optional filter conditions for targeting specific users or groups.
rollout_percentage integer no Percentage of users to roll out to (0–100). Omit for 100%.

posthog.posthog_update_feature_flag

Update an existing PostHog feature flag — change its active state, filters, or rollout percentage.

Operation
Write write
Schema command
kosmo integrations:schema posthog.posthog_update_feature_flag --json
ParameterTypeRequiredDescription
flag_id integer yes The unique identifier of the feature flag to update.
active boolean no Set the flag active (true) or inactive (false).
filters object no New filter conditions for targeting specific users or groups.
rollout_percentage integer no New rollout percentage (0–100).

posthog.posthog_delete_feature_flag

Delete a feature flag from PostHog. This action is permanent and cannot be undone.

Operation
Write write
Schema command
kosmo integrations:schema posthog.posthog_delete_feature_flag --json
ParameterTypeRequiredDescription
flag_id integer yes The unique identifier of the feature flag to delete.

posthog.posthog_list_insights

List saved insights in the PostHog project. Optionally filter by insight type (e.g., TRENDS, FUNNELS, RETENTION, PATHS).

Operation
Read read
Schema command
kosmo integrations:schema posthog.posthog_list_insights --json
ParameterTypeRequiredDescription
limit integer no Maximum number of insights to return (default: 100).
offset integer no Number of insights to skip for pagination (default: 0).
type string no Filter by insight type: TRENDS, FUNNELS, RETENTION, PATHS, LIFECYCLE, or STICKINESS.

posthog.posthog_get_insight

Get details of a specific PostHog insight by its ID, including its query configuration and cached results.

Operation
Read read
Schema command
kosmo integrations:schema posthog.posthog_get_insight --json
ParameterTypeRequiredDescription
insight_id integer yes The unique identifier of the insight to retrieve.

posthog.posthog_list_dashboards

List dashboards in the PostHog project. Dashboards contain collections of insights organized for monitoring.

Operation
Read read
Schema command
kosmo integrations:schema posthog.posthog_list_dashboards --json
ParameterTypeRequiredDescription
limit integer no Maximum number of dashboards to return (default: 100).
offset integer no Number of dashboards to skip for pagination (default: 0).

posthog.posthog_get_dashboard

Get details of a specific PostHog dashboard by its ID, including its layout and contained insights.

Operation
Read read
Schema command
kosmo integrations:schema posthog.posthog_get_dashboard --json
ParameterTypeRequiredDescription
dashboard_id integer yes The unique identifier of the dashboard to retrieve.

posthog.posthog_list_cohorts

List cohorts in the PostHog project. Cohorts are dynamic groups of users defined by behavioral or property conditions.

Operation
Read read
Schema command
kosmo integrations:schema posthog.posthog_list_cohorts --json
ParameterTypeRequiredDescription
limit integer no Maximum number of cohorts to return (default: 100).
offset integer no Number of cohorts to skip for pagination (default: 0).

Permissions

Headless calls still follow the integration read/write permission policy. Configure read/write defaults with integrations:configure. Add --force only for trusted automation that should bypass that policy.