The Moderations API allows you to classify text and image inputs to determine if they contain potentially harmful content across multiple categories including harassment, hate speech, self-harm, sexual content, and violence.
response = client.moderations.create( input: "This is a sample text to check for harmful content.")if response.results.first.flagged puts "Content flagged for: #{response.results.first.categories.inspect}"end
response = client.moderations.create( input: [ "First text to moderate", "Second text to moderate", "Third text to moderate" ])response.results.each_with_index do |result, index| puts "Input #{index + 1}: flagged=#{result.flagged}"end