Skip to main content

Multimodal Moderation – Text + Images

In this lesson, you'll learn how to use OpenAI’s omni-moderation-latest model to classify both text and images for policy violations in a single moderation request.

Prerequisites

Install the OpenAI SDK:

pip install openai

The Code

from openai import OpenAI
client = OpenAI()

response = client.moderations.create(
model="omni-moderation-latest",
input=[
{"type": "text", "text": "...text to classify goes here..."},
{
"type": "image_url",
"image_url": {
"url": "https://www.ripcurl.co.id/cdn/shop/files/0DKWSW_0090_1_10055f65-ff05-45df-8de7-ee84821dd87c_1800x1800.jpg",
}
},
],
)

print(response.results)

Explanation

  • model="omni-moderation-latest": Supports both text and image moderation.
  • Input list can contain mixed media types: text and image_url.
  • response.results: Lists results per input (e.g., which categories were flagged).

Use Case

Ideal for:

  • Moderating posts that include both captions and images
  • Ensuring content safety in multimodal platforms (e.g., social media, forums)
  • Flagging inappropriate visual or textual content before display