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

# Moderation API

> आपका AI product generate करने से पहले prompts और images को screen करें, और 17 content categories के लिए score के साथ allow, flag या deny verdict प्राप्त करें।

<CardGroup cols={2}>
  <Card title="Screen a Prompt" icon="shield-check" href="/api-reference/moderation/screen">
    टेक्स्ट, image या दोनों भेजें और verdict प्राप्त करें।
  </Card>

  <Card title="Get Moderation Usage" icon="chart-column" href="/api-reference/moderation/get-usage">
    अपने billable screens और अपना अगला charge देखें।
  </Card>
</CardGroup>

## अवलोकन

Moderation API आपके AI product द्वारा user input से generate करने से पहले उसे screen करता है। आप prompt का text, image या दोनों भेजते हैं, और Dodo Payments प्रत्येक content category के score के साथ `allow`, `flag` या `deny` का verdict लौटाता है।

इसे किसी भी ऐसे image, video या text generation model के सामने उपयोग करें जो आपके users से input लेता है। Moderation API हर business के लिए default रूप से चालू है और आपकी मौजूदा Dodo Payments API key के साथ चलता है, इसलिए sign up करने की आवश्यकता नहीं है। Dodo Payments इसे किसी individual business के लिए बंद कर सकता है; इसके बाद calls `403` को `MODERATION_DISABLED` के साथ लौटाती हैं।

## हमने Moderation API क्यों बनाया

AI generation product अपने users द्वारा लिखी गई किसी भी चीज़ से नया content बनाता है। आप हर prompt की manually समीक्षा नहीं कर सकते, और एक harmful output आपके business को जोखिम में डाल सकता है।

आपके Merchant of Record के रूप में, Dodo Payments platform के माध्यम से बेची जाने वाली चीज़ों के लिए कानूनी और reputational रूप से ज़िम्मेदार है। [Merchant Acceptance Policy](/miscellaneous/merchant-acceptance) AI content generation tools की समीक्षा करती है और impersonation, deepfakes या explicit content, जिसमें AI-generated content भी शामिल है, की अनुमति नहीं देती। ऐसा account जो harmful content, अत्यधिक chargebacks या payment partners से flags generate करता है, review के अधीन या suspended किया जा सकता है।

हमने Moderation API बनाया है ताकि आपका model इसे create करने से पहले आप इस content को रोक सकें:

* **Generate करने से पहले screen करें।** Block किया गया prompt कभी आपके model तक नहीं पहुँचता, इसलिए कोई harmful output मौजूद नहीं होता और आप उस पर compute खर्च नहीं करते।
* **Generation के लिए महत्वपूर्ण categories को cover करें।** Screen 17 categories के scores देता है, जिनमें real-person likeness, non-consensual intimate imagery, minor-coded language और sexual content के साथ real person का combination शामिल है, जो sexual deepfake को चिह्नित करता है।
* **किसी अन्य vendor के बिना integrate करें।** API आपकी Dodo Payments API key के साथ चलता है और इसकी fee आपके balance से debit होती है। कोई अलग contract, invoice या account नहीं है।
* **User content को private रखें।** Dodo Payments आपके द्वारा screen किए गए text और images को store या log नहीं करता।

<Note>
  Moderation API आपके अपने enforcement के लिए एक tool है। यह Merchant Acceptance Policy का replacement नहीं है और आपका product जो generate करता है उसके लिए आप ज़िम्मेदार रहते हैं।
</Note>

## यह कैसे काम करता है

User द्वारा prompt submit करने के बाद और आपका model चलने से पहले, अपने backend से Moderation API call करें:

```mermaid theme={null}
flowchart LR
  A[User submits a prompt] --> B[Your backend calls POST /moderation/screen]
  B -->|allow| C[Generate]
  B -->|flag| D[Apply your own policy]
  B -->|deny| E[Block the request]
  B -->|error, no verdict| E
```

हर call एक **screen** है। एक ही call में भेजा गया text और image एक screen के रूप में count होता है।

### Verdicts

`decision` field verdict रखता है:

| Verdict | अर्थ                                                                                           | क्या करें                                                                                            |
| ------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| `allow` | Content पास हो गया।                                                                            | Generate करें।                                                                                       |
| `flag`  | Content ऐसी category threshold को पार कर गया जिस पर judgement आवश्यक है। यह soft deny नहीं है। | अपनी policy लागू करें। आप इसे block कर सकते हैं, review के लिए भेज सकते हैं या generate कर सकते हैं। |
| `deny`  | Content generate नहीं किया जाना चाहिए।                                                         | Request को block करें और user को error दिखाएँ।                                                       |

<Warning>
  जब आपको कोई verdict न मिले तो generate न करें। `503` का अर्थ है कि Dodo Payments verdict तैयार नहीं कर सका, और timeout या network error के कारण भी आपके पास verdict नहीं रहेगा। इन सभी को block मानें और user से दोबारा प्रयास करने को कहें।
</Warning>

## Prompt को screen करना

Prompt को screen करने के लिए `POST` request को `/moderation/screen` पर भेजें, जिसमें कम से कम `text` या `image` में से एक हो। Request तीन fields स्वीकार करती है:

| Field        | Type   | Description                                                                                                                                                                  |
| ------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `text`       | string | Screen किया जाने वाला text, अधिकतम 8,000 characters।                                                                                                                         |
| `image`      | string | Screen की जाने वाली image, base64 के रूप में, `data:image/...;base64,` prefix के साथ या उसके बिना।                                                                           |
| `request_id` | string | Optional। इस screen के लिए आपका identifier, जैसे generation ID; अधिकतम 128 characters और इसमें कोई control characters नहीं होने चाहिए। Response इसे बिना बदलाव के लौटाता है। |

TypeScript और Python SDKs endpoint को `client.moderation.screen()` के रूप में expose करते हैं। यह example `deny`, `flag` और किसी भी error पर generation को block करता है:

<Note>
  Examples live mode को call करते हैं, क्योंकि केवल live mode moderation model चलाता है। Test mode [mock verdicts](#testing-your-integration) लौटाता है और content को कभी screen नहीं करता। Live mode screens का bill बनता है।
</Note>

<CodeGroup>
  ```typescript Node.js expandable theme={null}
  import DodoPayments from 'dodopayments';

  const client = new DodoPayments({
    bearerToken: process.env.DODO_PAYMENTS_API_KEY,
    environment: 'live_mode',
  });

  async function generateImage(prompt: string, generationId: string) {
    let verdict;
    try {
      verdict = await client.moderation.screen({
        text: prompt,
        request_id: generationId,
      });
    } catch (err) {
      // No verdict: do not generate.
      throw new Error('Moderation is unavailable. Try again in a moment.');
    }

    if (verdict.decision !== 'allow') {
      throw new Error('This prompt cannot be generated. Revise it and try again.');
    }

    return myModel.generate(prompt);
  }
  ```

  ```python Python expandable theme={null}
  import os
  from dodopayments import DodoPayments, APIError

  client = DodoPayments(
      bearer_token=os.environ["DODO_PAYMENTS_API_KEY"],
      environment="live_mode",
  )

  def generate_image(prompt: str, generation_id: str):
      try:
          verdict = client.moderation.screen(text=prompt, request_id=generation_id)
      except APIError:
          # No verdict: do not generate.
          raise RuntimeError("Moderation is unavailable. Try again in a moment.")

      if verdict.decision != "allow":
          raise ValueError("This prompt cannot be generated. Revise it and try again.")

      return my_model.generate(prompt)
  ```

  ```bash cURL theme={null}
  curl -X POST https://live.dodopayments.com/moderation/screen \
    -H "Authorization: Bearer $DODO_PAYMENTS_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "text": "a watercolor painting of a lighthouse at sunset",
      "request_id": "gen_7Hc2k9"
    }'
  ```
</CodeGroup>

Example `flag` को `deny` की तरह treat करता है। यदि आपका product कुछ flagged content की अनुमति देता है, तो category के अनुसार निर्णय लेने के लिए `triggered` देखें।

<Tip>
  अपने user द्वारा लिखे गए text को screen करें, न कि उस prompt template को जिसे आप उसके चारों ओर wrap करते हैं। आपका अपना template हर call में समान होता है और screen में कुछ नहीं जोड़ता।
</Tip>

### Images को screen करना

Uploaded reference image को screen करने या generated image दिखाने से पहले उसे screen करने के लिए image भेजें। Image को इन requirements को पूरा करना होगा:

* Format JPEG, PNG, WebP, GIF या BMP हो।
* Base64 string अधिकतम 6,991,530 characters की हो और decoded image अधिकतम 5 MiB की हो।
* Image single still frame हो। Animated GIF और WebP images reject कर दी जाती हैं।
* सबसे लंबी edge कम से कम 32 pixels की हो।

जो image इनमें से किसी check में विफल होती है, वह `400` को `MODERATION_INVALID_IMAGE` के साथ लौटाती है, या बहुत बड़ी होने पर `413` को `MODERATION_INPUT_TOO_LARGE` के साथ लौटाती है।

Image को screen करने के लिए file पढ़ें, उसे base64 के रूप में encode करें और `image` में भेजें। Image और उसके prompt को साथ screen करने के लिए उसी call में `text` और `image` दोनों भेजें। यह एक screen के रूप में count होता है। यह example पिछले example से `client` का उपयोग करता है:

<CodeGroup>
  ```typescript Node.js expandable theme={null}
  import { readFile } from 'node:fs/promises';

  async function screenImage(path: string, prompt: string, generationId: string) {
    const image = (await readFile(path)).toString('base64');

    const verdict = await client.moderation.screen({
      image, // or `data:image/png;base64,${image}`
      text: prompt, // optional: screen the prompt with the image
      request_id: generationId,
    });

    return verdict.decision === 'allow';
  }
  ```

  ```python Python expandable theme={null}
  import base64

  def screen_image(path: str, prompt: str, generation_id: str) -> bool:
      with open(path, "rb") as f:
          image = base64.b64encode(f.read()).decode("ascii")

      verdict = client.moderation.screen(
          image=image,  # or f"data:image/png;base64,{image}"
          text=prompt,  # optional: screen the prompt with the image
          request_id=generation_id,
      )
      return verdict.decision == "allow"
  ```

  ```bash cURL expandable theme={null}
  # Builds the JSON body with jq, so a large image does not hit the shell argument limit.
  base64 < reference.png | tr -d '\n' \
    | jq -Rs '{image: ., text: "turn this photo into a watercolor painting", request_id: "gen_7Hc2k9"}' \
    | curl -X POST https://live.dodopayments.com/moderation/screen \
        -H "Authorization: Bearer $DODO_PAYMENTS_API_KEY" \
        -H "Content-Type: application/json" \
        --data @-
  ```
</CodeGroup>

Image screen से errors को text screen की तरह handle करें: यदि call throw होती है, तो generate न करें।

## Response को पढ़ना

Response verdict और उसके पीछे का evidence लौटाता है:

| Field                | Description                                                                                                                                          |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `decision`           | Verdict: `allow`, `flag` या `deny`।                                                                                                                  |
| `triggered`          | वे categories जिनका score category की threshold को पार कर गया। सामान्य check से मिले `flag` पर यह empty हो सकता है।                                  |
| `compound_triggered` | `true` जब real-person likeness और sexual content ने मिलकर अपनी combined threshold पार कर ली हो, जो sexual deepfake का pattern है।                    |
| `categories`         | प्रत्येक category में content के आने की probability, 0 से 1 तक।                                                                                      |
| `provenance`         | प्रत्येक score को कैसे measure किया गया: उस एक category की जाँच द्वारा `targeted` या सभी categories को cover करने वाली general check द्वारा `broad`। |
| `notes`              | Decision के human-readable reasons। Wording बदल सकती है, इसलिए इसे parse न करें।                                                                     |
| `normalized_applied` | `true` जब text को obfuscation हटाकर भी screen किया गया हो, जैसे invisible या look-alike characters।                                                  |
| `passes`             | इस screen के लिए model द्वारा उत्तर दिए गए yes/no questions की संख्या।                                                                               |
| `latency_ms`         | Screen में लगा समय, milliseconds में।                                                                                                                |
| `request_id`         | आपके द्वारा भेजा गया `request_id` या `null`।                                                                                                         |

अपना logic `decision` और `triggered` पर आधारित करें। प्रत्येक category की अपनी threshold होती है, इसलिए आपके code में single score cut-off verdict से मेल नहीं खाता।

### Categories

हर response content को 17 categories के विरुद्ध score करता है:

| Category                          | Covers                                                                               |
| --------------------------------- | ------------------------------------------------------------------------------------ |
| `violent_crimes`                  | Violent crimes।                                                                      |
| `sex_related_crimes`              | Sex-related crimes।                                                                  |
| `child_sexual_exploitation`       | Child sexual exploitation।                                                           |
| `suicide_and_self_harm`           | Suicide और self-harm।                                                                |
| `indiscriminate_weapons`          | Chemical, biological, radiological, nuclear या explosive weapons।                    |
| `intellectual_property`           | Copyright या trademark infringement।                                                 |
| `defamation`                      | ऐसा false depiction जिससे real person की reputation को नुकसान पहुँचने की संभावना हो। |
| `non_violent_crimes`              | Non-violent crimes।                                                                  |
| `hate`                            | Protected characteristic के कारण लोगों को demean करना।                               |
| `privacy`                         | किसी व्यक्ति के बारे में sensitive private information।                              |
| `specialized_advice`              | Unqualified financial, medical, legal या electoral advice।                           |
| `sexual_content`                  | Sexually explicit या pornographic content।                                           |
| `non_consensual_intimate_imagery` | Real person को undress, nudify या sexualize करना।                                    |
| `minor_coded_language`            | ऐसा age-coded language जिससे subject के minor होने का संकेत मिले।                    |
| `real_person_likeness`            | किसी real, identifiable, named person की likeness।                                   |
| `living_artist_style`             | किसी specific living artist की signature style की imitation।                         |
| `prompt_injection`                | System के instructions को override या manipulate करने का प्रयास।                     |

## Errors को handle करना

Errors standard Dodo Payments error body को `code` और `message` के साथ लौटाती हैं। कोई भी error verdict नहीं है, इसलिए इनमें से कोई भी generation की अनुमति नहीं देता:

| Status | `code`                       | Cause                                                                | What to do                                                              |
| ------ | ---------------------------- | -------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| `400`  | `INVALID_REQUEST_PARAMETERS` | Request malformed है या इसमें न तो `text` है और न `image`।           | Request ठीक करें।                                                       |
| `400`  | `MODERATION_INVALID_IMAGE`   | Image decode नहीं की जा सकती, animated है या बहुत छोटी है।           | Supported still image भेजें।                                            |
| `403`  | `MODERATION_DISABLED`        | Dodo Payments ने आपके business के लिए Moderation API बंद कर दी है।   | कारण जानने के लिए support से contact करें।                              |
| `413`  | `MODERATION_INPUT_TOO_LARGE` | `text` 8,000 characters से अधिक है या `image` size limit से अधिक है। | Text छोटा करें या image का आकार घटाएँ।                                  |
| `429`  | `MODERATION_OVERLOADED`      | Moderation capacity पर है। यह throughput limit है, verdict नहीं।     | `Retry-After` header में दिए seconds तक प्रतीक्षा करें, फिर retry करें। |
| `503`  | `MODERATION_UNAVAILABLE`     | कोई verdict उपलब्ध नहीं है।                                          | Generate न करें। बाद में retry करें।                                    |

SDKs default रूप से `429` या `503` को दो बार retry करते हैं और attempts के बीच `Retry-After` तक प्रतीक्षा करते हैं। Retries समाप्त होने पर SDK error raise करता है और आपके code को request block करनी होगी।

## अपना Integration test करना

Test mode mock verdicts लौटाता है और moderation model को कभी call नहीं करता, इसलिए आप बिना cost के अपना routing test कर सकते हैं। Test mode API key के साथ requests को `https://test.dodopayments.com` पर भेजें।

Default mock verdict `allow` है। दूसरा outcome पाने के लिए इन strings में से किसी एक को `text` में कहीं भी रखें:

| String in `text`       | Response                                                 |
| ---------------------- | -------------------------------------------------------- |
| `dodo_mock_flag`       | `200` जिसमें `decision` को `flag` पर set किया गया है     |
| `dodo_mock_deny`       | `200` जिसमें `decision` को `deny` पर set किया गया है     |
| `dodo_mock_overloaded` | `429` `MODERATION_OVERLOADED` जिसमें `Retry-After: 1` है |
| `dodo_mock_not_ready`  | `503` `MODERATION_UNAVAILABLE`                           |

Mock verdict में एक note होता है जो बताता है कि वह mock है, और उसके सभी category scores `0` होते हैं। Test mode वही request validation लागू करता है जो live mode करता है। Images के लिए यह base64 encoding और format जाँचता है, लेकिन frame count या dimensions नहीं।

Live होने से पहले पुष्टि करें कि आपका integration प्रत्येक case को handle करता है:

<Steps>
  <Step title="Deny Blocks Generation">
    `dodo_mock_deny` भेजें और पुष्टि करें कि आपका model call नहीं होता।
  </Step>

  <Step title="Flag Follows Your Policy">
    `dodo_mock_flag` भेजें और पुष्टि करें कि आपका product वही करता है जो आपकी policy कहती है।
  </Step>

  <Step title="Overload Retries">
    `dodo_mock_overloaded` भेजें और पुष्टि करें कि आपका code `Retry-After` की प्रतीक्षा करता है और verdict के बिना generate नहीं करता।
  </Step>

  <Step title="An Outage Blocks Generation">
    `dodo_mock_not_ready` भेजें और पुष्टि करें कि आपका model call नहीं होता।
  </Step>

  <Step title="Every Generation Path Screens">
    जाँचें कि आपके model तक पहुँचने वाला हर code path पहले Moderation API को call करता है।
  </Step>
</Steps>

## Pricing और Billing

Moderation API की cost **1,000 billable screens के लिए \$0.30 USD** है। कोई free tier या minimum नहीं है।

Billable screen वह live mode screen है जो verdict लौटाती है। ये screens free हैं और count नहीं की जातीं:

* Test mode में screens।
* वे screens जो error लौटाती हैं, जिनमें `429` और `503` शामिल हैं।

Dodo Payments पूरी 1,000 screens की blocks में bill करता है। प्रत्येक पूरा block एक घंटे के भीतर charge किया जाता है, और जो screens block पूरा नहीं करतीं वे पूरा होने तक unbilled रहती हैं। Fee आपके USD balance से debit होती है और event type `moderation_fees` के साथ आपके [balance ledger](/api-reference/balance-ledger/list-ledger-entries) में दिखाई देती है। Payouts में यह **Moderation Fees** के अंतर्गत दिखाई देती है।

### Usage को track करना

अपना usage देखने के लिए `GET /moderation/usage` call करें। Response लौटाता है:

| Field                   | Description                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `unbilled_screens`      | वे billable screens जिनके लिए Dodo Payments ने अभी charge नहीं किया है।                                           |
| `screens_to_next_block` | अगले 1,000 के block को पूरा करने के लिए अभी आवश्यक billable screens।                                              |
| `daily`                 | पिछले 30 दिनों के लिए UTC day के अनुसार आपके billable screens। जिन दिनों कोई screen नहीं है, वे omitted रहते हैं। |

<CodeGroup>
  ```bash cURL theme={null}
  curl https://live.dodopayments.com/moderation/usage \
    -H "Authorization: Bearer $DODO_PAYMENTS_API_KEY"
  ```

  ```typescript Node.js theme={null}
  const usage = await client.moderation.retrieveUsage();
  console.log(usage.unbilled_screens, usage.screens_to_next_block);
  ```

  ```python Python theme={null}
  usage = client.moderation.retrieve_usage()
  print(usage.unbilled_screens, usage.screens_to_next_block)
  ```
</CodeGroup>

Test mode कोई screens record नहीं करता, इसलिए usage endpoint कोई test mode activity नहीं लौटाता।

## Access और Privacy

Screening के लिए write access वाली API key आवश्यक है। कोई भी API key, जिसमें read-only key भी शामिल है, usage पढ़ सकती है। Key बनाने और उसका access level set करने के तरीके के लिए [Authentication](/api-reference/introduction#authentication) देखें।

Dodo Payments आपके द्वारा screen किए गए text या images को store नहीं करता और उन्हें logs में नहीं लिखता। प्रत्येक live mode screen के लिए यह billing और usage reporting के लिए time, verdict और आपका `request_id` रखता है।

<CardGroup cols={2}>
  <Card title="Usage-Based Billing" icon="arrow-trend-up" href="/features/usage-based-billing/introduction">
    प्रत्येक generation के लिए अपने customers से charge करें।
  </Card>

  <Card title="Credit-Based Billing" icon="coins" href="/features/credit-based-billing">
    Generation credits बेचें और प्रति use उन्हें deduct करें।
  </Card>
</CardGroup>
