Logs & Analytics

Stream provides APIs to query moderation logs, export them for compliance, retrieve analytics, and track usage statistics. These endpoints help you audit moderation activity, monitor moderator performance, and generate reports.

Query Moderation Logs

POST /api/v2/moderation/logs

Query moderation action logs with filtering, sorting, and pagination. Logs record every moderation action taken -- who did what, when, and on which content.

$response = $client->moderation()->queryModerationLogs(new QueryModerationLogsRequest(
    filter: (object)['entity_type' => 'stream:chat:v1:message'],
    sort: [new SortParam(field: 'created_at', direction: -1)],
    limit: 50,
));

Request Parameters

KeyRequiredTypeDescription
filterfalseobjectFilter conditions for logs.
sortfalsearraySort parameters (e.g., by created_at).
limitfalsenumberMaximum number of logs to return.
nextfalsestringCursor for pagination.

Response

KeyTypeDescription
logsarrayList of moderation log entries. Each entry includes action type, actor, target, timestamp, and details.
nextstringNext cursor for pagination.

Export Moderation Logs

POST /api/v2/moderation/logs/export

Export moderation logs for external analysis or compliance purposes. The export can be filtered by time range, entity type, or any other supported filter condition.

$response = $client->moderation()->exportModerationLogs(new ExportModerationLogsRequest(
    filter: (object)['created_at' => (object)['$gte' => '2024-01-01T00:00:00Z']],
));

Request Parameters

KeyRequiredTypeDescription
filterfalseobjectFilter conditions for which logs to export.

Response

KeyTypeDescription
export_urlstringURL to download the exported logs file.
statusstringStatus of the export operation.

Get Moderation Analytics

POST /api/v2/moderation/analytics

Retrieve moderation analytics for a specified time range. This is a server-side only endpoint that returns aggregate statistics about moderation activity.

$response = $client->moderation()->getModerationAnalytics(new GetModerationAnalyticsRequest(
    from: '2024-01-01T00:00:00Z',
    to: '2024-01-31T23:59:59Z',
));

Request Parameters

KeyRequiredTypeDescription
fromfalsestringStart of time range (ISO 8601 datetime).
tofalsestringEnd of time range (ISO 8601 datetime).

Response

KeyTypeDescription
analyticsobjectAggregate moderation analytics data for the specified time range.

Query Usage Stats

POST /api/v2/moderation/usage_stats

Query moderation usage statistics -- number of checks, flags, actions, and other operational metrics over a given time period.

$response = $client->moderation()->queryUsageStats(new QueryUsageStatsRequest(
    from: '2024-01-01T00:00:00Z',
    to: '2024-01-31T23:59:59Z',
));

Request Parameters

KeyRequiredTypeDescription
fromfalsestringStart of time range (ISO 8601 datetime).
tofalsestringEnd of time range (ISO 8601 datetime).

Response

KeyTypeDescription
statsobjectUsage statistics including counts for checks, flags, and actions within the time range.

Get User Moderation Report

GET /api/v2/moderation/user_report

Retrieve a comprehensive moderation report for a specific user, including moderation history, flags received, and actions taken against their content.

$response = $client->moderation()->getUserModerationReport(new GetUserModerationReportRequest(
    userId: 'user_123',
));

Request Parameters

KeyRequiredTypeDescription
user_idtruestringThe ID of the user to get the report for.

Response

KeyTypeDescription
reportobjectComprehensive moderation report for the user, including history, flags, and actions.

Get Flag Count

POST /api/v2/moderation/flag_count

Get the number of moderation flags created against a specific user's content. Useful for building moderation dashboards and identifying repeat offenders.

$response = $client->moderation()->getFlagCount(new GetFlagCountRequest(
    userId: 'user_123',
));

Request Parameters

KeyRequiredTypeDescription
user_idtruestringUser ID to get flag count for.
entity_typefalsestringOptionally filter by entity type.

Response

KeyTypeDescription
countnumberTotal number of flags for the specified user.