go get github.com/GetStream/getstream-go/v4Getting 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.
Moderation lives in the Stream Dashboard, where you can create and tune policies, manage AI rules and blocklists, and review flagged content across your app. You can also manage moderation from the terminal with the Stream CLI — useful for scripting policy setup, or for letting an AI agent configure policies and blocklists for you.
Installation
Initialize the Client
package main
import (
"context"
getstream "github.com/GetStream/getstream-go/v4"
)
func main() {
client, err := getstream.NewClient("YOUR_API_KEY", "YOUR_API_SECRET")
if err != nil {
panic(err)
}
ctx := context.Background()
}Create a Moderation Policy
Before checking content, create a moderation configuration that defines which rules to apply:
_, err := client.Moderation().UpsertConfig(ctx, &getstream.UpsertConfigRequest{
Key: "my_config",
AiTextConfig: &getstream.AiTextConfig{
Rules: []getstream.AiTextRule{
{Label: "SPAM", Action: "flag"},
{Label: "HARASSMENT", Action: "remove"},
},
},
BlockListConfig: &getstream.BlockListConfig{
Rules: []getstream.BlockListRule{
{Name: "profanity_en", Action: "remove"},
},
},
})For Stream Chat, use config key
chat:messaging. For Stream Feeds, usefeeds. See Configuration for details.
Check Content
response, err := client.Moderation().Check(ctx, &getstream.CheckRequest{
EntityType: "stream:chat:v1:message",
EntityID: "message-123",
EntityCreatorID: "user-456",
ModerationPayload: &getstream.ModerationPayload{
Texts: []string{"Hello, this is a test message"},
},
ConfigKey: getstream.PtrTo("my_config"),
})
fmt.Println(response.Data.RecommendedAction) // "keep", "flag", or "remove"Handle the Response
The response includes:
RecommendedAction--"keep","flag", or"remove"Status--"complete"or"partial"(if async checks are still running)Item-- the review queue item (if content was flagged or removed)
switch response.Data.RecommendedAction {
case "keep":
// Content is safe, no action needed
case "flag":
// Content is suspicious, send to review queue
fmt.Println("Flagged for review:", response.Data.Item)
case "remove":
// Content violates policies, remove it
fmt.Println("Content removed:", response.Data.Item)
}Next Steps
- Configuration -- Advanced policy setup
- Stream Chat Integration -- Chat moderation
- Stream Feeds Integration -- Feeds moderation
- Review Queue -- Query and act on flagged content
- Client Configuration — HTTP defaults, timeouts, and connection pooling