Getting Started

Stream's Moderation API lets you integrate content moderation into any application. This guide walks you through installation, configuration, and your first moderation check.

Installation

composer require getstream/getstream-php

Initialize the Client

use GetStream\ClientBuilder;

$client = ClientBuilder::apiKey('YOUR_API_KEY')
    ->apiSecret('YOUR_API_SECRET')
    ->buildModerationClient();

Create a Moderation Policy

Before checking content, create a moderation configuration that defines which rules to apply:

$client->upsertConfig(new UpsertConfigRequest(
    key: 'my_config',
    aiTextConfig: new AiTextConfig(
        rules: [
            new AiTextRule(label: 'SPAM', action: 'flag'),
            new AiTextRule(label: 'HARASSMENT', action: 'remove'),
        ],
    ),
    blockListConfig: new BlockListConfig(
        rules: [
            new BlockListRule(name: 'profanity_en', action: 'remove'),
        ],
    ),
));

For Stream Chat, use config key chat:messaging. For Stream Feeds, use feeds. See Configuration for details.

Check Content

$response = $client->check(new CheckRequest(
    entityType: 'stream:chat:v1:message',
    entityID: 'message-123',
    entityCreatorID: 'user-456',
    moderationPayload: new ModerationPayload(
        texts: ['Hello, this is a test message'],
    ),
    configKey: 'my_config',
));

echo $response->getData()->getRecommendedAction(); // "keep", "flag", or "remove"

Handle the Response

The response includes:

  • getRecommendedAction() -- "keep", "flag", or "remove"
  • getStatus() -- "complete" or "partial" (if async checks are still running)
  • getItem() -- the review queue item (if content was flagged or removed)
$action = $response->getData()->getRecommendedAction();

if ($action === 'keep') {
    // Content is safe, no action needed
} elseif ($action === 'flag') {
    // Content is suspicious, send to review queue
    echo 'Flagged for review: ' . print_r($response->getData()->getItem(), true);
} elseif ($action === 'remove') {
    // Content violates policies, remove it
    echo 'Content removed: ' . print_r($response->getData()->getItem(), true);
}

Next Steps