> ## Documentation Index
> Fetch the complete documentation index at: https://ayrshare.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# コンテンツモデレーション

> コンテンツを検査して有害または不適切でないことを確認します

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

<PlansAvailable plans={["premium"]} maxPackRequired={false} />

コンテンツモデレーション API は、開発者が潜在的に有害または不適切なテキストコンテンツを特定するのを支援するために設計されています。
このエンドポイントはテキスト入力を分析し、さまざまな種類の懸念すべきコンテンツに基づいて分類します。

## 主な機能

<ul className="custom-bullets">
  <li>有害なコンテンツの自動検出。</li>
  <li>問題のあるテキストの複数のカテゴリ。</li>
  <li>コンテンツフィルタリングのための容易な統合。</li>
</ul>

## 動作の仕組み

モデレーションエンドポイントにテキストを送信すると、OpenAI モデルを使用してコンテンツを分析します。次に API は、テキストが定義された問題のあるカテゴリのいずれかに該当するかを示す結果を返します。

## 有害コンテンツのカテゴリ

API は以下のカテゴリにテキストを分類します:

| カテゴリ                   | 説明                                                                                                                |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------- |
| hate                   | 人種、性別、民族、宗教、国籍、性的指向、障害状況、カーストに基づく憎悪を表現、扇動、または促進するコンテンツ。保護されていないグループ(例: チェスプレイヤー)を対象とした憎悪コンテンツは harassment に該当します。 |
| hate/threatening       | 対象グループ(人種、性別、民族、宗教、国籍、性的指向、障害状況、カーストに基づく)に対する暴力または重大な危害を含む憎悪コンテンツ。                                                |
| harassment             | 任意の対象へのハラスメント言語を表現、扇動、または促進するコンテンツ。                                                                               |
| harassment/threatening | 任意の対象への暴力または重大な危害を含むハラスメントコンテンツ。                                                                                  |
| self-harm              | 自殺、切傷、摂食障害など、自傷行為を促進、奨励、または描写するコンテンツ。                                                                             |
| self-harm/intent       | 発言者が自傷行為(自殺、切傷、摂食障害など)に及んでいる、または及ぶつもりであることを表明するコンテンツ。                                                             |
| self-harm/instructions | 自殺、切傷、摂食障害などの自傷行為を実行するよう奨励するコンテンツ、またはそのような行為の実行方法に関する指示や助言を提供するコンテンツ。                                             |
| sexual                 | 性的活動の描写など性的興奮を引き起こすことを目的とするコンテンツ、または性的サービスを促進するコンテンツ(性教育やウェルネスを除く)。                                               |
| sexual/minors          | 18 歳未満の人物を含む性的コンテンツ。                                                                                              |
| violence               | 死、暴力、または身体的な傷害を描写するコンテンツ。                                                                                         |
| violence/graphic       | 死、暴力、または身体的な傷害を生々しく詳細に描写するコンテンツ。                                                                                  |

## 使用方法とベストプラクティス

1. **最適なテキスト長**: 最良の結果を得るには、長いテキストを小さなチャンクに分割することを推奨します。それぞれ 2,000 文字未満のセグメントを目指してください。
2. **統合**: この API を使用して、アプリケーション、フォーラム、ユーザー生成コンテンツプラットフォームにおける潜在的に問題のあるコンテンツを自動的にフラグ付けします。
3. **結果に対するアクション**: API の出力に基づいて、コンテンツフィルタリング、ユーザーへの警告、追加レビュープロセスなどの適切なアクションを実装できます。

## ヘッダーパラメータ

<HeaderAPI noProfileKey={true} />

## ボディパラメータ

<ParamField body="text" type="string">
  モデレーション用に分析するテキストです。
</ParamField>

<ParamField body="imageUrl" type="string">
  画像の URL です。`https://` で始まる必要があります。
</ParamField>

<RequestExample>
  ```bash cURL theme={"system"}
  curl --location 'https://api.ayrshare.com/api/validate/moderation' \
  --header 'Authorization: Bearer API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
      "text": "Let'\''s kill '\''em all"
  }'
  ```

  ```javascript JavaScript theme={"system"}
  const url = "https://api.ayrshare.com/api/validate/moderation";
  const apiKey = "API_KEY"; // Replace with your actual API key

  const data = {
    text: "Let's kill 'em all",
  };

  fetch(url, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(data),
  })
    .then((response) => response.json())
    .then((result) => console.log(result))
    .catch((error) => console.error("Error:", error));
  ```

  ```python Python theme={"system"}
  import requests

  url = 'https://api.ayrshare.com/api/validate/moderation'
  api_key = 'API_KEY'  # Replace with your actual API key

  headers = {
      'Authorization': f'Bearer {api_key}',
      'Content-Type': 'application/json'
  }

  data = {
      'text': "Let's kill 'em all"
  }

  response = requests.post(url, json=data, headers=headers)

  if response.status_code == 200:
      result = response.json()
      print(result)
  else:
      print(f"Error: {response.status_code}")
      print(response.text)
  ```

  ```php PHP theme={"system"}
  <?php

  $url = 'https://api.ayrshare.com/api/validate/moderation';
  $apiKey = 'API_KEY';  // Replace with your actual API key

  $data = [
      'text' => "Let's kill 'em all"
  ];

  $headers = [
      'Authorization: Bearer ' . $apiKey,
      'Content-Type: application/json'
  ];

  $ch = curl_init($url);

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

  $response = curl_exec($ch);

  if (curl_errno($ch)) {
      echo 'Error: ' . curl_error($ch);
  } else {
      $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      if ($httpCode == 200) {
          $result = json_decode($response, true);
          print_r($result);
      } else {
          echo "Error: HTTP Code " . $httpCode . "\n";
          echo $response;
      }
  }
  ```

  ```go Go theme={"system"}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"fmt"
  	"io/ioutil"
  	"net/http"
  )

  func main() {
  	url := "https://api.ayrshare.com/api/validate/moderation"
  	apiKey := "API_KEY" // Replace with your actual API key

  	// Create the request body
  	requestBody, err := json.Marshal(map[string]string{
  		"text": "Let's kill 'em all",
  	})
  	if err != nil {
  		fmt.Println("Error creating request body:", err)
  		return
  	}

  	// Create a new request
  	req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
  	if err != nil {
  		fmt.Println("Error creating request:", err)
  		return
  	}

  	// Set headers
  	req.Header.Set("Authorization", "Bearer "+apiKey)
  	req.Header.Set("Content-Type", "application/json")

  	// Send the request
  	client := &http.Client{}
  	resp, err := client.Do(req)
  	if err != nil {
  		fmt.Println("Error sending request:", err)
  		return
  	}
  	defer resp.Body.Close()

  	// Read the response
  	body, err := ioutil.ReadAll(resp.Body)
  	if err != nil {
  		fmt.Println("Error reading response:", err)
  		return
  	}

  	// Check the status code
  	if resp.StatusCode == http.StatusOK {
  		fmt.Println("Response:")
  		fmt.Println(string(body))
  	} else {
  		fmt.Printf("Error: Status Code %d\n", resp.StatusCode)
  		fmt.Println(string(body))
  	}
  }
  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.Text;
  using System.Threading.Tasks;
  using System.Text.Json;

  class Program
  {
      static async Task Main(string[] args)
      {
          string url = "https://api.ayrshare.com/api/validate/moderation";
          string apiKey = "API_KEY";  // Replace with your actual API key

          var data = new
          {
              text = "Let's kill 'em all"
          };

          using (var client = new HttpClient())
          {
              client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");

              var content = new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, "application/json");

              try
              {
                  HttpResponseMessage response = await client.PostAsync(url, content);

                  if (response.IsSuccessStatusCode)
                  {
                      string result = await response.Content.ReadAsStringAsync();
                      Console.WriteLine("Response:");
                      Console.WriteLine(result);
                  }
                  else
                  {
                      Console.WriteLine($"Error: {response.StatusCode}");
                      Console.WriteLine(await response.Content.ReadAsStringAsync());
                  }
              }
              catch (HttpRequestException e)
              {
                  Console.WriteLine($"Request error: {e.Message}");
                  Console.WriteLine($"InnerException: {e.InnerException?.Message}"); // Include inner exception details for more information
              }
          }
      }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200: Response theme={"system"}
  {
    "status": "success",
    "text": "Let's kill 'em all",
    "moderation": [
      {
        "flagged": true,
        "categories": {
          "sexual": false,
          "hate": false,
          "harassment": false,
          "self-harm": false,
          "sexual/minors": false,
          "hate/threatening": false,
          "violence/graphic": false,
          "self-harm/intent": false,
          "self-harm/instructions": false,
          "harassment/threatening": false,
          "violence": true
        },
        "categoryScores": {
          "sexual": 0.00002128273445123341,
          "hate": 0.027735227718949318,
          "harassment": 0.08523011207580566,
          "self-harm": 0.0000021838018255948555,
          "sexual/minors": 1.924875903114298e-7,
          "hate/threatening": 0.0063302298076450825,
          "violence/graphic": 0.00024857991957105696,
          "self-harm/intent": 7.833968993509188e-7,
          "self-harm/instructions": 8.686130570367823e-8,
          "harassment/threatening": 0.07459623366594315,
          "violence": 0.9833663702011108
        }
      }
    ]
  }
  ```

  ```json 400: Bad Request theme={"system"}
  {
    "action": "generate",
    "status": "error",
    "code": 331,
    "message": "There was an issue with the AI processing. Please try again and if the issue persists, contact us."
  }
  ```
</ResponseExample>
