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

Add to your build.gradle:

dependencies {
    implementation 'io.getstream:stream-sdk-java:7.+'
}

Or Maven pom.xml:

<dependency>
    <groupId>io.getstream</groupId>
    <artifactId>stream-sdk-java</artifactId>
    <version>7.0.0</version>
</dependency>

Initialize the Client

import io.getstream.services.framework.StreamSDKClient;

var client = StreamSDKClient.builder()
    .apiKey("YOUR_API_KEY")
    .apiSecret("YOUR_API_SECRET")
    .build();

Create a Moderation Policy

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

client.moderation()
    .upsertConfig(UpsertConfigRequest.builder()
        .key("my_config")
        .aiTextConfig(AiTextConfig.builder()
            .rules(List.of(
                AiTextRule.builder().label("SPAM").action("flag").build(),
                AiTextRule.builder().label("HARASSMENT").action("remove").build()
            ))
            .build())
        .blockListConfig(BlockListConfig.builder()
            .rules(List.of(
                BlockListRule.builder().name("profanity_en").action("remove").build()
            ))
            .build())
        .build())
    .execute();

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

Check Content

var response = client.moderation()
    .check(CheckRequest.builder()
        .entityType("stream:chat:v1:message")
        .entityID("message-123")
        .entityCreatorID("user-456")
        .moderationPayload(ModerationPayload.builder()
            .texts(List.of("Hello, this is a test message"))
            .build())
        .configKey("my_config")
        .build())
    .execute();

System.out.println(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)
String action = response.getData().getRecommendedAction();

switch (action) {
    case "keep":
        // Content is safe, no action needed
        break;
    case "flag":
        // Content is suspicious, send to review queue
        System.out.println("Flagged for review: " + response.getData().getItem());
        break;
    case "remove":
        // Content violates policies, remove it
        System.out.println("Content removed: " + response.getData().getItem());
        break;
}

Next Steps