KosmoKrator

analytics

Segment CLI for AI Agents

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

Segment CLI Setup

Segment can be configured headlessly with `kosmokrator integrations:configure segment`.

Install, configure, and verify
# 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 segment --set write_key="$SEGMENT_WRITE_KEY" --enable --read allow --write ask --json
kosmokrator integrations:doctor segment --json
kosmokrator integrations:status --json

Credentials

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

KeyEnv varTypeRequiredLabel
write_key SEGMENT_WRITE_KEY Secret secret yes Write Key
api_token SEGMENT_API_TOKEN Secret secret no API Token
url SEGMENT_URL URL url no API Base URL

Command Patterns

The generic command is stable across every integration. The provider shortcut is shorter for humans.

Generic CLI call
kosmo integrations:call segment.segment_identify '{"userId":"example_userId","traits":"example_traits"}' --json
Provider shortcut
kosmo integrations:segment segment_identify '{"userId":"example_userId","traits":"example_traits"}' --json

Discovery

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

Discovery commands
kosmo integrations:docs segment --json
kosmo integrations:docs segment.segment_identify --json
kosmo integrations:schema segment.segment_identify --json
kosmo integrations:search "Segment" --json
kosmo integrations:list --json

Automation Contexts

The same configured command surface works in these environments. The command does not change unless the host wrapper, credentials, or permissions change.

CLI Functions

Every function below can be called headlessly. Commands are highlighted, copyable, and scroll horizontally when payloads are long.

segment.segment_identify

Identify a user in Segment with their traits. Links metadata about a user (name, email, plan, etc.) to a known userId so all their events can be attributed correctly.

Write write
Parameters
userId, traits
Generic call
kosmo integrations:call segment.segment_identify '{"userId":"example_userId","traits":"example_traits"}' --json
Shortcut
kosmo integrations:segment segment_identify '{"userId":"example_userId","traits":"example_traits"}' --json

segment.segment_track

Track a custom event for a user in Segment. Records actions your users perform along with optional properties describing the action.

Write write
Parameters
event, userId, properties
Generic call
kosmo integrations:call segment.segment_track '{"event":"example_event","userId":"example_userId","properties":"example_properties"}' --json
Shortcut
kosmo integrations:segment segment_track '{"event":"example_event","userId":"example_userId","properties":"example_properties"}' --json

segment.segment_page

Record a page view in Segment. Tracks when a user views a page, along with optional properties about the page.

Write write
Parameters
name, userId, properties
Generic call
kosmo integrations:call segment.segment_page '{"name":"example_name","userId":"example_userId","properties":"example_properties"}' --json
Shortcut
kosmo integrations:segment segment_page '{"name":"example_name","userId":"example_userId","properties":"example_properties"}' --json

segment.segment_group

Associate a user with a group (organization, company, account) in Segment. Lets you record group membership along with optional group traits.

Write write
Parameters
groupId, userId, traits
Generic call
kosmo integrations:call segment.segment_group '{"groupId":"example_groupId","userId":"example_userId","traits":"example_traits"}' --json
Shortcut
kosmo integrations:segment segment_group '{"groupId":"example_groupId","userId":"example_userId","traits":"example_traits"}' --json

segment.segment_get_workspace

Get details of a Segment workspace by its slug. Requires an API token to be configured.

Read read
Parameters
slug
Generic call
kosmo integrations:call segment.segment_get_workspace '{"slug":"example_slug"}' --json
Shortcut
kosmo integrations:segment segment_get_workspace '{"slug":"example_slug"}' --json

segment.segment_list_sources

List all sources in a Segment workspace. Requires an API token to be configured.

Read read
Parameters
slug
Generic call
kosmo integrations:call segment.segment_list_sources '{"slug":"example_slug"}' --json
Shortcut
kosmo integrations:segment segment_list_sources '{"slug":"example_slug"}' --json

segment.segment_get_source

Get details of a specific Segment source by ID. Requires an API token to be configured.

Read read
Parameters
slug, id
Generic call
kosmo integrations:call segment.segment_get_source '{"slug":"example_slug","id":"example_id"}' --json
Shortcut
kosmo integrations:segment segment_get_source '{"slug":"example_slug","id":"example_id"}' --json

segment.segment_get_current_user

Get the currently authenticated Segment user. Useful for verifying API token credentials are correct.

Read read
Parameters
none
Generic call
kosmo integrations:call segment.segment_get_current_user '{}' --json
Shortcut
kosmo integrations:segment segment_get_current_user '{}' --json

Function Schemas

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

segment.segment_identify 2 parameters
Schema command
kosmo integrations:schema segment.segment_identify --json
ParameterTypeRequiredDescription
userId string yes The unique identifier for the user in your database.
traits object no Key-value pairs of user traits (e.g., name, email, plan, role, company).
segment.segment_track 3 parameters
Schema command
kosmo integrations:schema segment.segment_track --json
ParameterTypeRequiredDescription
event string yes The name of the event being tracked (e.g., "Order Completed", "Button Clicked").
userId string yes The unique identifier for the user in your database.
properties object no Key-value pairs of event properties (e.g., revenue, category, productId).
segment.segment_page 3 parameters
Schema command
kosmo integrations:schema segment.segment_page --json
ParameterTypeRequiredDescription
name string yes The name of the page viewed (e.g., "Homepage", "Product Listing").
userId string yes The unique identifier for the user in your database.
properties object no Key-value pairs of page properties (e.g., url, referrer, title, path).
segment.segment_group 3 parameters
Schema command
kosmo integrations:schema segment.segment_group --json
ParameterTypeRequiredDescription
groupId string yes The unique identifier for the group (e.g., company ID, organization ID).
userId string yes The unique identifier for the user in your database.
traits object no Key-value pairs of group traits (e.g., name, plan, industry, employee_count).
segment.segment_get_workspace 1 parameters
Schema command
kosmo integrations:schema segment.segment_get_workspace --json
ParameterTypeRequiredDescription
slug string yes The workspace slug (e.g., "my-workspace").
segment.segment_list_sources 1 parameters
Schema command
kosmo integrations:schema segment.segment_list_sources --json
ParameterTypeRequiredDescription
slug string yes The workspace slug (e.g., "my-workspace").
segment.segment_get_source 2 parameters
Schema command
kosmo integrations:schema segment.segment_get_source --json
ParameterTypeRequiredDescription
slug string yes The workspace slug (e.g., "my-workspace").
id string yes The source ID (e.g., "abc123").
segment.segment_get_current_user 0 parameters
Schema command
kosmo integrations:schema segment.segment_get_current_user --json
ParameterTypeRequiredDescription
No parameters.

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.