Policies

Overview

Moderation configurations (also called policies) define how content is moderated within your application. Each configuration specifies which moderation engines are active, what rules apply to detected content categories, and what actions to take when rules are triggered. Configurations are identified by a unique key and can be scoped to specific teams for multi-tenancy support.

You can combine multiple moderation engines in a single configuration -- for example, AI text analysis for detecting harassment, blocklists for filtering profanity, and image moderation for detecting nudity. Each engine has its own set of rules that map detected labels or patterns to actions such as flagging, removing, or shadow-blocking content.

Upsert Config

Creates or updates a moderation configuration. If a configuration with the specified key already exists, it will be replaced. A configuration can include any combination of moderation engines: AI text analysis, AI image moderation, blocklist filtering, toxicity detection, platform circumvention detection, velocity filters, and video call rules.

$client->moderation()->upsertConfig(new UpsertConfigRequest(
    key: 'my_config',
    aiTextConfig: new AITextConfig(
        rules: [
            new AITextRule(label: 'SPAM', action: 'flag'),
            new AITextRule(label: 'HARASSMENT', severityRules: [
                new SeverityRule(severity: 'low', action: 'flag'),
                new SeverityRule(severity: 'high', action: 'remove'),
            ]),
        ],
    ),
    blockListConfig: new BlockListConfig(
        rules: [new BlockListRule(name: 'profanity_en', action: 'remove')],
    ),
    aiImageConfig: new AIImageConfig(
        rules: [new AIImageRule(label: 'Non-Explicit Nudity', action: 'flag')],
    ),
));

Request Parameters

keyrequiredtypedescription
keytruestringUnique identifier for the config. Used when sending content for moderation check.
teamfalsestringTeam identifier for multi-tenancy. Scopes the config to a specific team.
asyncfalsebooleanWhen true, moderation checks using this config run asynchronously.
ai_text_configfalseobjectConfiguration for AI text analysis. Define rules mapping harm labels to actions.
ai_image_configfalseobjectConfiguration for AI image moderation (e.g., nudity, violence detection).
ai_video_configfalseobjectConfiguration for AI video moderation.
block_list_configfalseobjectConfiguration for blocklist-based filtering. Define which blocklists to use and their actions.
automod_toxicity_configfalseobjectConfiguration for Stream's built-in toxicity detection engine.
automod_platform_circumvention_configfalseobjectConfiguration for platform circumvention detection (phone numbers, external links, etc.).
velocity_filter_configfalseobjectConfiguration for velocity-based filtering (rate limiting repeated content).
llm_configfalseobjectConfiguration for LLM-based moderation.

Config Key Conventions

The config key follows a hierarchical naming convention that determines its scope:

  • Chat channel: chat:messaging:channel_id -- applies to a specific channel
  • Chat channel type: chat:messaging -- applies to all channels of a given type
  • All chat channels: chat -- applies to all chat channels
  • Activity Feeds: feeds:default -- applies to activity feeds

When content is submitted for moderation, the system looks for the most specific config key first, then falls back to broader scopes.

Get Config

Retrieve a specific moderation configuration by its key. Returns the full configuration object including all engine settings and rules.

$client->moderation()->getConfig('my_config');

Request Parameters

keyrequiredtypedescription
keytruestringThe unique identifier of the config to retrieve.
teamfalsestringTeam identifier for multi-tenancy.

Response

keytypedescription
configobjectThe full moderation configuration object.

Delete Config

Delete a moderation configuration. Once deleted, any content moderation checks referencing this config key will no longer apply.

$client->moderation()->deleteConfig('my_config');

Request Parameters

keyrequiredtypedescription
keytruestringThe unique identifier of the config to delete.
teamfalsestringTeam identifier for multi-tenancy.

Query Configs

Search and filter moderation configurations with support for sorting and pagination. Use this endpoint to list all configurations or find specific ones matching filter criteria.

$client->moderation()->queryModerationConfigs(new QueryModerationConfigsRequest(
    filter: (object)[],
    sort: [new SortParam(field: 'created_at', direction: -1)],
    limit: 10,
));

Request Parameters

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

Response

keytypedescription
configsarrayList of moderation config objects.
nextstringNext cursor for pagination.

Config Structure Reference

Each moderation configuration can include one or more engine-specific sub-configurations. The following table summarizes the available config types and where to find detailed documentation for each engine.

Config FieldDescriptionEngine Documentation
ai_text_configAI-powered text analysis for detecting harm categoriesAI Text
ai_image_configAI-powered image moderation for nudity, violence, and moreImage Moderation
block_list_configBlocklist and regex-based filtering for known bad words or patternsBlocklists and Regex Filters
automod_toxicity_configStream's built-in toxicity scoring engine--
automod_platform_circumvention_configDetection of phone numbers, emails, and external links--
velocity_filter_configRate limiting for repeated or high-volume content--
ai_video_configAI-powered video call moderation--
llm_configLLM-based moderation for custom policies--

Rule Actions

Each rule within a config maps a detected label or pattern to an action. The following actions are available:

ActionDescription
flagFlag the content for human review. The content remains visible but appears in the moderation review queue.
removeRemove the content immediately. The content is deleted and a review queue item is created.
shadow_blockShadow-block the content. The content appears visible to the author but is hidden from other users.
bounceBounce the content back to the sender. The content is rejected before it is published, and the user is notified.

Severity Levels

For AI text analysis rules, you can define severity-based rules instead of a single action. This allows different actions depending on how severe the detected violation is. The available severity levels are:

SeverityDescription
lowMinor or borderline violations. Typically used for flagging or monitoring.
mediumModerate violations that may warrant content removal or closer review.
highSerious violations that typically result in content removal.
criticalThe most severe violations requiring immediate action.

When using severity rules, each severity level can be mapped to a different action. For example, you might flag low-severity harassment but automatically remove high-severity harassment, as shown in the Upsert Config example above.