# API V2: नाम, ईमेल और यूज़रनेम के बैच अनुरोध

> एक बैच में GenderAPI.io V2 के अधिकतम 50 अनुमान भेजें। हर आइटम के विकल्प, सुरक्षित रखे गए ID, आंशिक विफलताएँ, रिस्पॉन्स का सारांश और क्रेडिट का हिसाब समझें।

Canonical HTML: https://www.genderapi.io/hi/docs/v2/batch

Last reviewed: 2026-09-29

## नामों, ईमेल और यूज़रनेम के बैच अनुरोध

| पैरामीटर | प्रकार | ज़रूरी | डिफ़ॉल्ट | विवरण |
| --- | --- | --- | --- | --- |
| `items` | `array<object>` | हाँ | `—` | अनुमान के 1 से 50 आइटम; IP ट्रायल में अधिकतम 10। परिणाम इनपुट का क्रम बनाए रखते हैं। |
| `items[].type` | `string` | हाँ | `—` | इनपुट की श्रेणी: name, email या username। |
| `items[].value` | `string` | हाँ | `—` | ज़रूरी। 1–254 अक्षर; खाली नहीं और कंट्रोल कैरेक्टर के बिना। ईमेल मान मान्य ईमेल सिंटैक्स में होने चाहिए। |
| `items[].country` | `string` | नहीं | `—` | वैकल्पिक, बड़े अक्षरों में ISO 3166-1 alpha-2 कोड, जैसे TR या US। देश के हिसाब से खोज में वैश्विक डेटासेट का भी इस्तेमाल हो सकता है। |
| `items[].forceToGenderize` | `boolean` | नहीं | `false` | पहले डेटासेट आज़माएँ, फिर परिणाम न मिलने पर निकनेम समझने वाला AI। name, email और username के लिए समर्थित। |
| `items[].options` | `object` | नहीं | `—` | हर इनपुट के AI विकल्पों का कंटेनर। |
| `items[].options.ai_mode` | `string` | नहीं | `off` | मान्य मान: off, fallback, always। forceToGenderize: true के साथ यह फ़ील्ड छोड़ दें या fallback इस्तेमाल करें। |
| `items[].id` | `string` | नहीं | `—` | POST JSON में वैकल्पिक, 1–64 अक्षरों का पहचानकर्ता। हर बैच परिणाम के साथ लौटाया जाता है; एक बैच में यूनिक होना चाहिए। एकल अनुमान में स्वीकार होता है, लेकिन लौटाया नहीं जाता। GET क्वेरी में समर्थित नहीं। |

POST /gender/batch में items ऐरे होता है: API कुंजी के साथ 1–50 आइटम, IP ट्रायल में अधिकतम 10। आप सिर्फ़ नाम, सिर्फ़ ईमेल, सिर्फ़ यूज़रनेम या तीनों को मिलाकर भेज सकते हैं। हर आइटम का अपना country, forceToGenderize और options होता है। ID वैकल्पिक हैं और यूनिक होने चाहिए।

परिणाम इनपुट का क्रम बनाए रखते हैं और उनमें index, आपका वैकल्पिक id, charged_credits और data या error में से ठीक एक होता है। HTTP 200 में भी आइटम स्तर की विफलताएँ हो सकती हैं, इसलिए हर आइटम जाँचें। meta.summary में total, succeeded, identified, unknown और failed होते हैं। अज्ञात अनुमान सफल आइटम है और उस पर शुल्क लगता है।

अनुरोध के सत्यापन या योजना में विफलता होने पर बैच क्रेडिट कटने से पहले ही अस्वीकार हो जाता है। अगर चलाए गए सभी आइटम विफल हों, तो API data ऐरे और उसी के पुराने नाम results के साथ non-2xx Problem रिस्पॉन्स लौटाता है। रिफ़ंड की पुष्टि के बाद विफल आइटम पर कोई शुल्क नहीं लगता। बिलिंग की पुष्टि न हो, तो आइटम के शुल्क को अंतिम न मानें।

ये उदाहरण अपने सर्वर पर चलाएँ। प्रोसेस एनवायरनमेंट में GENDERAPI_API_KEY को अपनी मौजूदा API कुंजी पर सेट करें। पक्का करें कि meta.access.mode का मान api_key है: पहचानी न गई कुंजी IP ट्रायल पर जा सकती है।

अनुमान का हर अनुरोध, दोबारा प्रयास सहित, शुल्क वाली नई प्रक्रिया है। ये उदाहरण अपने-आप दोबारा प्रयास नहीं करते। दूसरा अनुरोध भेजने से पहले बिलिंग स्टेटस देखें।

HTTP 4xx और 5xx वाले JSON रिस्पॉन्स में त्रुटि की बॉडी बनी रहती है और प्रोग्राम शून्य से अलग एग्ज़िट स्टेटस लौटाता है। दोबारा प्रयास से पहले code, action और meta.usage.billing_status देखें। HTTP 200 वाले बैच रिस्पॉन्स में हर आइटम का data या error भी जाँचें।

**cURL**

POSIX शेल में cURL 7.76+। अपने टर्मिनल में चलाएँ।

```bash
curl --silent --show-error --fail-with-body --max-time 30 \
  --request POST 'https://api.genderapi.io/api/v2/gender/batch' \
  --header "Authorization: Bearer ${GENDERAPI_API_KEY:?Set GENDERAPI_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{
  "items": [
    {
      "id": "contact-1",
      "type": "name",
      "value": "Arjun",
      "country": "IN"
    },
    {
      "id": "contact-2",
      "type": "email",
      "value": "alice.smith@example.com",
      "options": {
        "ai_mode": "fallback"
      }
    },
    {
      "id": "contact-3",
      "type": "username",
      "value": "prenses",
      "country": "TR",
      "forceToGenderize": true
    }
  ]
}'
```

**JavaScript / Node.js**

Node.js 22+; बिल्ट-इन fetch। example.mjs के रूप में सेव करें और node example.mjs चलाएँ।

```javascript
// Server-side Node.js. Save as example.mjs.
const apiKey = process.env.GENDERAPI_API_KEY;
if (!apiKey) throw new Error("Set GENDERAPI_API_KEY");
const body = {
  "items": [
    {
      "id": "contact-1",
      "type": "name",
      "value": "Arjun",
      "country": "IN"
    },
    {
      "id": "contact-2",
      "type": "email",
      "value": "alice.smith@example.com",
      "options": {
        "ai_mode": "fallback"
      }
    },
    {
      "id": "contact-3",
      "type": "username",
      "value": "prenses",
      "country": "TR",
      "forceToGenderize": true
    }
  ]
};

const response = await fetch("https://api.genderapi.io/api/v2/gender/batch", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
  signal: AbortSignal.timeout(30_000),
  redirect: "error",
});
const raw = await response.text();
if (!(response.headers.get("content-type") ?? "").includes("json")) {
  throw new Error(`HTTP ${response.status}: expected JSON; request ID ${response.headers.get("x-request-id")}`);
}
const result = JSON.parse(raw); // Also accepts application/problem+json.
if (!response.ok) {
  console.error(`HTTP ${response.status}`, result);
  process.exitCode = 1; // A retry is a new operation; inspect billing first.
} else {
  console.log(JSON.stringify(result, null, 2));
  // For batches, inspect every item: HTTP 200 may contain item errors.
}
```

**Python**

Python 3.10+; स्टैंडर्ड लाइब्रेरी। example.py के रूप में सेव करें और python3 example.py चलाएँ।

```python
import json
import os
import sys
import urllib.error
import urllib.request

api_key = os.environ.get("GENDERAPI_API_KEY")
if not api_key:
    raise RuntimeError("Set GENDERAPI_API_KEY")
body = json.loads("{\"items\":[{\"id\":\"contact-1\",\"type\":\"name\",\"value\":\"Arjun\",\"country\":\"IN\"},{\"id\":\"contact-2\",\"type\":\"email\",\"value\":\"alice.smith@example.com\",\"options\":{\"ai_mode\":\"fallback\"}},{\"id\":\"contact-3\",\"type\":\"username\",\"value\":\"prenses\",\"country\":\"TR\",\"forceToGenderize\":true}]}")

class NoRedirect(urllib.request.HTTPRedirectHandler):
    def redirect_request(self, req, fp, code, msg, headers, newurl):
        return None

request = urllib.request.Request(
    "https://api.genderapi.io/api/v2/gender/batch",
    method="POST",
    data=json.dumps(body).encode("utf-8"),
    headers={
        "Authorization": "Bearer " + api_key,
        "Content-Type": "application/json",
    },
)
opener = urllib.request.build_opener(NoRedirect())
try:
    response = opener.open(request, timeout=30)
except urllib.error.HTTPError as error:
    response = error  # Keep the Problem Details body on non-2xx responses.
with response:
    status = response.status
    raw = response.read().decode("utf-8")
    if "json" not in response.headers.get("Content-Type", ""):
        raise RuntimeError(f"HTTP {status}: expected a JSON response")
    result = json.loads(raw)
print(json.dumps(result, indent=2), file=sys.stderr if status >= 300 else sys.stdout)
if not 200 <= status < 300:
    sys.exit(1)  # Inspect code, action and billing before retrying.
# For batches, inspect every item even when HTTP status is 200.
```

**PHP**

cURL एक्सटेंशन के साथ PHP 8+। example.php के रूप में सेव करें और php example.php चलाएँ।

```php
<?php
$apiKey = getenv('GENDERAPI_API_KEY');
if (!$apiKey) {
    throw new RuntimeException('Set GENDERAPI_API_KEY');
}
$body = json_decode('{"items":[{"id":"contact-1","type":"name","value":"Arjun","country":"IN"},{"id":"contact-2","type":"email","value":"alice.smith@example.com","options":{"ai_mode":"fallback"}},{"id":"contact-3","type":"username","value":"prenses","country":"TR","forceToGenderize":true}]}', true, 512, JSON_THROW_ON_ERROR);

$ch = curl_init('https://api.genderapi.io/api/v2/gender/batch');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => false,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode($body, JSON_THROW_ON_ERROR),
]);
$raw = curl_exec($ch);
if ($raw === false) {
    throw new RuntimeException(curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE) ?: '';
curl_close($ch);
if (strpos($contentType, 'json') === false) {
    throw new RuntimeException("HTTP $status: expected a JSON response");
}
$result = json_decode($raw, true, 512, JSON_THROW_ON_ERROR);
$output = json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . PHP_EOL;
if ($status < 200 || $status >= 300) {
    fwrite(STDERR, $output); // Preserve the Problem Details body.
    exit(1);
}
echo $output;
// For batches, inspect every item; HTTP 200 can contain item errors.
```

**Java**

Java 17+; स्टैंडर्ड HTTP क्लाइंट। GenderApiExample.java के रूप में सेव करें और java GenderApiExample.java चलाएँ।

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;

public class GenderApiExample {
    private static String requiredEnv(String name) {
        String value = System.getenv(name);
        if (value == null || value.isBlank()) throw new IllegalStateException("Set " + name);
        return value;
    }

    public static void main(String[] args) throws Exception {
        String apiKey = requiredEnv("GENDERAPI_API_KEY");
        String body = "{\"items\":[{\"id\":\"contact-1\",\"type\":\"name\",\"value\":\"Arjun\",\"country\":\"IN\"},{\"id\":\"contact-2\",\"type\":\"email\",\"value\":\"alice.smith@example.com\",\"options\":{\"ai_mode\":\"fallback\"}},{\"id\":\"contact-3\",\"type\":\"username\",\"value\":\"prenses\",\"country\":\"TR\",\"forceToGenderize\":true}]}";
        HttpClient client = HttpClient.newBuilder()
            .connectTimeout(Duration.ofSeconds(10))
            .followRedirects(HttpClient.Redirect.NEVER)
            .build();
        HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.genderapi.io/api/v2/gender/batch"))
            .timeout(Duration.ofSeconds(30))
            .header("Authorization", "Bearer " + apiKey)
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8))
            .build();
        HttpResponse<String> response = client.send(request,
            HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
        if (!response.headers().firstValue("content-type").orElse("").contains("json")) {
            throw new IllegalStateException("HTTP " + response.statusCode() + ": expected JSON");
        }
        // JSON text; parse with your application's JSON library when integrating.
        if (response.statusCode() < 200 || response.statusCode() >= 300) {
            System.err.println(response.body()); // Includes Problem Details.
            System.exit(1);
        }
        System.out.println(response.body());
        // For batches, inspect each item's data or error, including on HTTP 200.
    }
}
```

**C# / .NET**

.NET 8+ कंसोल ऐप्लिकेशन। कंसोल प्रोजेक्ट में Program.cs के रूप में इस्तेमाल करें, फिर dotnet run चलाएँ।

```csharp
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

string RequiredEnv(string name) =>
    !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(name))
        ? Environment.GetEnvironmentVariable(name)!
        : throw new InvalidOperationException($"Set {name}");

var apiKey = RequiredEnv("GENDERAPI_API_KEY");
using var handler = new HttpClientHandler { AllowAutoRedirect = false };
using var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(30) };
using var request = new HttpRequestMessage(HttpMethod.Post, "https://api.genderapi.io/api/v2/gender/batch");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
request.Content = new StringContent("{\"items\":[{\"id\":\"contact-1\",\"type\":\"name\",\"value\":\"Arjun\",\"country\":\"IN\"},{\"id\":\"contact-2\",\"type\":\"email\",\"value\":\"alice.smith@example.com\",\"options\":{\"ai_mode\":\"fallback\"}},{\"id\":\"contact-3\",\"type\":\"username\",\"value\":\"prenses\",\"country\":\"TR\",\"forceToGenderize\":true}]}", Encoding.UTF8, "application/json");

using var response = await client.SendAsync(request);
var raw = await response.Content.ReadAsStringAsync();
if (!(response.Content.Headers.ContentType?.MediaType?.Contains("json") ?? false))
    throw new InvalidOperationException($"HTTP {(int)response.StatusCode}: expected JSON");
using var result = JsonDocument.Parse(raw);
if (!response.IsSuccessStatusCode)
{
    Console.Error.WriteLine(result.RootElement); // Preserve Problem Details.
    Environment.ExitCode = 1;
}
else
{
    Console.WriteLine(result.RootElement);
    // For batches, inspect every item even on HTTP 200.
}
```

**Go**

Go 1.22+; स्टैंडर्ड लाइब्रेरी। main.go के रूप में सेव करें और go run main.go चलाएँ।

```go
package main

import (
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "os"
    "strings"
    "time"
)

func requiredEnv(name string) string {
    value := os.Getenv(name)
    if value == "" { panic("Set " + name) }
    return value
}

func run() error {
    apiKey := requiredEnv("GENDERAPI_API_KEY")
    body := "{\"items\":[{\"id\":\"contact-1\",\"type\":\"name\",\"value\":\"Arjun\",\"country\":\"IN\"},{\"id\":\"contact-2\",\"type\":\"email\",\"value\":\"alice.smith@example.com\",\"options\":{\"ai_mode\":\"fallback\"}},{\"id\":\"contact-3\",\"type\":\"username\",\"value\":\"prenses\",\"country\":\"TR\",\"forceToGenderize\":true}]}"
    request, err := http.NewRequest("POST", "https://api.genderapi.io/api/v2/gender/batch", strings.NewReader(body))
    if err != nil { return err }
    request.Header.Set("Authorization", "Bearer " + apiKey)
    request.Header.Set("Content-Type", "application/json")
    client := &http.Client{
        Timeout: 30 * time.Second,
        CheckRedirect: func(req *http.Request, via []*http.Request) error {
            return http.ErrUseLastResponse
        },
    }
    response, err := client.Do(request)
    if err != nil { return err }
    defer response.Body.Close()
    raw, err := io.ReadAll(response.Body)
    if err != nil { return err }
    if !strings.Contains(response.Header.Get("Content-Type"), "json") || !json.Valid(raw) {
        return fmt.Errorf("HTTP %d: expected a JSON response", response.StatusCode)
    }
    if response.StatusCode < 200 || response.StatusCode >= 300 {
        return fmt.Errorf("HTTP %d: %s", response.StatusCode, raw)
    }
    fmt.Println(string(raw))
    // For batches, inspect every item even on HTTP 200.
    return nil
}

func main() {
    if err := run(); err != nil {
        fmt.Fprintln(os.Stderr, err) // Keep Problem Details for error handling.
        os.Exit(1)
    }
}
```

## बैच रिस्पॉन्स पढ़ें

यह उदाहरण 1 अक्टूबर 2026 को प्राप्त दो वास्तविक परिणामों, एक डेटासेट मिलान और एक अज्ञात परिणाम, को सेवा प्रदाता की एक उदाहरण-स्वरूप विफलता के साथ जोड़ता है। यह आंशिक रूप से सफल HTTP 200 रिस्पॉन्स दिखाता है, ऊपर दिए गए बैच अनुरोध का अपेक्षित परिणाम नहीं। दोनों सफल आइटम पर 1-1 क्रेडिट लगता है; विफल आइटम पर शून्य शुल्क की पुष्टि है।

```json
{
  "data": [
    {
      "index": 0,
      "id": "known",
      "charged_credits": 1,
      "data": {
        "input": {
          "type": "name",
          "value": "Arjun",
          "country": "IN"
        },
        "name": "arjun",
        "gender": "male",
        "country": "IN",
        "confidence": 0.9964061096136568,
        "confidence_kind": "observed_frequency",
        "sample_count": 1113,
        "source": "dataset",
        "result_status": "identified",
        "reason": null,
        "country_source": "dataset",
        "match": {
          "name": "arjun",
          "method": "normalized",
          "scope": "country",
          "country": "IN"
        }
      }
    },
    {
      "index": 1,
      "id": "missing",
      "charged_credits": 1,
      "data": {
        "input": {
          "type": "name",
          "value": "zzzxxyy",
          "country": null
        },
        "name": null,
        "gender": null,
        "country": null,
        "confidence": null,
        "confidence_kind": null,
        "sample_count": null,
        "source": "none",
        "result_status": "unknown",
        "reason": "not_found",
        "country_source": null,
        "match": {
          "name": null,
          "method": null,
          "scope": null,
          "country": null
        }
      }
    },
    {
      "index": 2,
      "id": "failed",
      "charged_credits": 0,
      "error": {
        "type": "urn:genderapi:problem:ai_upstream_error",
        "title": "ai upstream error",
        "status": 502,
        "detail": "The AI provider could not complete the request.",
        "instance": "urn:uuid:11111111-1111-4111-8111-111111111111",
        "code": "ai_upstream_error",
        "request_id": "11111111-1111-4111-8111-111111111111",
        "documentation": "https://api.genderapi.io/api/v2/errors",
        "action": "inspect_billing_before_retry"
      }
    }
  ],
  "meta": {
    "request_id": "11111111-1111-4111-8111-111111111111",
    "duration_ms": 12,
    "access": {
      "mode": "ip_trial",
      "reason": "api_key_missing"
    },
    "usage": {
      "charged_credits": 2,
      "remaining_credits": 6,
      "billing_status": "confirmed",
      "resets_at": "2026-09-26T12:00:00.000Z",
      "limit": 10,
      "period_seconds": 86400
    },
    "summary": {
      "total": 3,
      "succeeded": 2,
      "identified": 1,
      "unknown": 1,
      "failed": 1
    }
  }
}
```

## बैच परिणाम के फ़ील्ड

| फ़ील्ड | प्रकार | Nullable | उदाहरण | विवरण |
| --- | --- | --- | --- | --- |
| `data` | `array<object>` | नहीं | `[…]` | क्रमबद्ध परिणाम। हर आइटम में एक अनुमान या एक त्रुटि होती है; हर आइटम जाँचें। |
| `data[].index` | `integer` | नहीं | `0` | भेजे गए items ऐरे में शून्य से शुरू होने वाली स्थिति। |
| `data[].id` | `string` | नहीं | `"contact-1"` | आपका इनपुट पहचानकर्ता, सिर्फ़ दिए जाने पर मौजूद। |
| `data[].charged_credits` | `integer` | नहीं | `1` | पुष्टि हुए रिफ़ंड के बाद आइटम का कुल शुल्क। पूरी बिलिंग की पुष्टि न हो, तो इसे अंतिम न मानें। |
| `data[].data` | `object` | नहीं | `{…}` | सफल आइटम में मौजूद, अज्ञात परिणामों सहित। रिस्पॉन्स गाइड में बताए गए अनुमान के फ़ील्ड इस्तेमाल करता है। |
| `data[].error` | `object` | नहीं | `{…}` | विफल आइटम में data की जगह मौजूद। त्रुटि गाइड में बताए गए Problem Details फ़ील्ड इस्तेमाल करता है। |

## बैच सारांश के फ़ील्ड

| फ़ील्ड | प्रकार | Nullable | उदाहरण | विवरण |
| --- | --- | --- | --- | --- |
| `meta.summary.total` | `integer` | नहीं | `3` | बैच में आइटम की कुल संख्या। |
| `meta.summary.succeeded` | `integer` | नहीं | `2` | सफल आइटम, अज्ञात अनुमानों सहित। |
| `meta.summary.identified` | `integer` | नहीं | `1` | non-null gender वाले सफल आइटम। |
| `meta.summary.unknown` | `integer` | नहीं | `1` | null gender वाले सफल आइटम; इन परिणामों पर शुल्क लगता है। |
| `meta.summary.failed` | `integer` | नहीं | `1` | विफल आइटम। total = succeeded + failed; succeeded = identified + unknown। |

## एक्सेस, बिलिंग और अनुरोध का मेटाडेटा

| फ़ील्ड | प्रकार | Nullable | उदाहरण | विवरण |
| --- | --- | --- | --- | --- |
| `meta.request_id` | `string` | नहीं | `"550e8400-e29b-41d4-a716-446655440000"` | इस HTTP प्रयास का यूनिक पहचानकर्ता; X-Request-ID में भी भेजा जाता है। |
| `meta.duration_ms` | `integer` | नहीं | `42` | मिलीसेकंड में अनुरोध प्रोसेस होने का समय। |
| `meta.access.mode` | `string` | नहीं | `"api_key"` | api_key, ip_trial या unauthenticated। पेड अकाउंट इस्तेमाल करते समय api_key की पुष्टि करें। |
| `meta.access.reason` | `string` | हाँ | `null` | IP ट्रायल पर जाने का कारण: api_key_missing, api_key_invalid या api_key_not_found; बाकी मामलों में null। |
| `meta.usage.charged_credits` | `integer` | हाँ | `1` | कुल कटे हुए क्रेडिट। शुल्क लगने से पहले या पूरे रिफ़ंड की पुष्टि के बाद शून्य; बिलिंग की पुष्टि न होने पर null। |
| `meta.usage.remaining_credits` | `integer` | हाँ | `99` | प्रक्रिया पूरी होने के समय का बैलेंस। नेगेटिव हो सकता है; उपलब्ध न होने या बिलिंग की पुष्टि न होने पर null। |
| `meta.usage.billing_status` | `string` | नहीं | `"confirmed"` | not_charged, confirmed या unconfirmed। विफल अनुमान का दोबारा प्रयास करने से पहले इसे जाँचें। |
| `meta.usage.resets_at` | `string` | हाँ | `"2026-09-27T12:00:00.000Z"` | UTC में IP ट्रायल रीसेट होने का समय (ISO 8601); API कुंजी वाले अकाउंट के लिए या पता न होने पर null। |
| `meta.usage.limit` | `integer` | हाँ | `10` | IP ट्रायल की सीमा; API कुंजी वाले अकाउंट के लिए null। |
| `meta.usage.period_seconds` | `integer` | हाँ | `86400` | सेकंड में IP ट्रायल की अवधि; API कुंजी वाले अकाउंट के लिए null। |

## बैच के क्रेडिट और दोबारा प्रयास की योजना बनाएँ

अपनी मौजूदा Bearer API कुंजी से प्रमाणीकरण करें और Content-Type: application/json भेजें। भेजा गया हर बैच एक नई प्रक्रिया है। आंशिक विफलता के बाद दोबारा प्रयास करते समय बिलिंग जाँचकर सिर्फ़ विफल आइटम भेजें; सफल आइटम दोबारा भेजने पर उन पर फिर से शुल्क लगता है।

बैच आइटम में AI डिफ़ॉल्ट रूप से off रहता है और हर सफल आइटम पर 1 क्रेडिट लगता है। स्पष्ट रूप से चुने गए fallback पर भी AI सहित कुल 1 क्रेडिट लगता है। always पर 2 क्रेडिट लगते हैं। forceToGenderize पर डेटासेट से परिणाम मिलने पर 1 और AI इस्तेमाल होने पर 2 क्रेडिट लगते हैं। सफल अज्ञात परिणामों पर शुल्क लगता है। बैच शुरू करने के लिए 1 पॉज़िटिव शुरुआती क्रेडिट काफ़ी है; अंतिम शुल्क के बाद बैलेंस नेगेटिव हो सकता है।

- [प्रमाणीकरण](https://www.genderapi.io/hi/docs/v2/authentication)
- [हर आइटम के AI विकल्प](https://www.genderapi.io/hi/docs/v2/ai-options)
- [त्रुटियाँ और दोबारा प्रयास](https://www.genderapi.io/hi/docs/v2/errors-and-retries)

## संपर्क सूची प्रोसेस करें और हर पंक्ति का हिसाब रखें

बैच एंडपॉइंट सिर्फ़ नामों की सूची, सिर्फ़ ईमेल की सूची और मिले-जुले इनपुट संभालता है। API कुंजी वाले काम को अधिकतम 50 आइटम के हिस्सों में बाँटें; IP ट्रायल में हर अनुरोध में अधिकतम 10 आइटम भेजे जा सकते हैं। काम की अपनी प्रगति खुद दर्ज करें और हर आइटम को उसके बैच में यूनिक id दें। लौटाया गया index भेजे गए उसी हिस्से में शून्य से शुरू होने वाली स्थिति है, पूरी संपर्क सूची में नहीं।

| चरण | क्या सेव या जाँच करें | यह क्यों ज़रूरी है |
| --- | --- | --- |
| 1. हर हिस्सा तैयार करें | अपनी स्रोत पंक्ति और आइटम id सुरक्षित रखें; हर आइटम के लिए country और AI विकल्प सेट करें। | यह न मानें कि हर नाम सभी संपर्कों में यूनिक होगा। |
| 2. पूरा रिस्पॉन्स पढ़ें | meta.request_id सेव करें और data[] की हर एंट्री को id या index से मिलाएँ। | HTTP 200 में सफल अनुमान और आइटम की त्रुटियाँ, दोनों हो सकते हैं। |
| 3. सफल परिणाम सेव करें | identified और unknown अनुमान रखें, JSON null और साक्ष्य वाले फ़ील्ड सहित। | अज्ञात परिणाम पूरी हुई और शुल्क वाली प्रक्रिया है; यह अपने-आप दोबारा भेजी जाने वाली विफल पंक्ति नहीं है। |
| 4. त्रुटियों और क्रेडिट का मिलान करें | दूसरा अनुरोध तय करने से पहले हर error और meta.usage.billing_status जाँचें। | बिलिंग की पुष्टि होने पर सिर्फ़ वही विफल आइटम दोबारा भेजें जिनकी त्रुटि दोबारा प्रयास के लायक हो। सफल आइटम पर फिर से शुल्क लगेगा। |
| 5. अनिश्चित दोबारा प्रयास रोकें | बिलिंग की पुष्टि न होने या नेटवर्क विफलता से परिणाम पता न होने पर अनुरोध ID सुरक्षित रखें। | पूरा हिस्सा बिना सोचे दोबारा न भेजें; पहले त्रुटियों और बिलिंग के निर्देश देखें। |

- [त्रुटियाँ, टाइमआउट और दोबारा प्रयास के फ़ैसले](https://www.genderapi.io/hi/docs/v2/errors-and-retries)
- [बिलिंग स्टेटस और क्रेडिट](https://www.genderapi.io/hi/docs/v2/credits-and-usage)

## हर संपर्क के लिए अनुमान का मोड चुनें

चलाया जा सकने वाला यह अनुरोध तीन अलग नीतियाँ इस्तेमाल करता है: पूरे नाम के लिए सिर्फ़ डेटासेट, ईमेल के लिए सामान्य AI फ़ॉलबैक और यूज़रनेम के लिए निकनेम समझने वाला फ़ॉलबैक। यह सिर्फ़ उदाहरण इनपुट है, इस बात का वादा नहीं कि तीनों संपर्कों के लिए लिंग मिलेगा। कोड के ऊपर प्रोग्रामिंग भाषा चुनें और चलाने से पहले GENDERAPI_API_KEY सेट करें।

forceToGenderize के बिना, बैच आइटम में AI डिफ़ॉल्ट रूप से off रहता है, जो एकल अनुरोधों से अलग है। सामान्य AI फ़ॉलबैक के लिए fallback स्पष्ट रूप से सेट करें। off और सामान्य fallback, दोनों पर हर सफल आइटम के लिए 1 क्रेडिट लगता है; always डेटासेट छोड़ देता है और उस पर 2 क्रेडिट लगते हैं। forceToGenderize पर डेटासेट से परिणाम मिलने पर 1 और AI इस्तेमाल होने पर कुल 2 क्रेडिट लगते हैं। सफल अज्ञात परिणामों पर भी शुल्क लगता है। forceToGenderize को off या always के साथ न मिलाएँ।

ये उदाहरण अपने सर्वर पर चलाएँ। प्रोसेस एनवायरनमेंट में GENDERAPI_API_KEY को अपनी मौजूदा API कुंजी पर सेट करें। पक्का करें कि meta.access.mode का मान api_key है: पहचानी न गई कुंजी IP ट्रायल पर जा सकती है।

अनुमान का हर अनुरोध, दोबारा प्रयास सहित, शुल्क वाली नई प्रक्रिया है। ये उदाहरण अपने-आप दोबारा प्रयास नहीं करते। दूसरा अनुरोध भेजने से पहले बिलिंग स्टेटस देखें।

HTTP 4xx और 5xx वाले JSON रिस्पॉन्स में त्रुटि की बॉडी बनी रहती है और प्रोग्राम शून्य से अलग एग्ज़िट स्टेटस लौटाता है। दोबारा प्रयास से पहले code, action और meta.usage.billing_status देखें। HTTP 200 वाले बैच रिस्पॉन्स में हर आइटम का data या error भी जाँचें।

**cURL**

POSIX शेल में cURL 7.76+। अपने टर्मिनल में चलाएँ।

```bash
curl --silent --show-error --fail-with-body --max-time 30 \
  --request POST 'https://api.genderapi.io/api/v2/gender/batch' \
  --header "Authorization: Bearer ${GENDERAPI_API_KEY:?Set GENDERAPI_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{
  "items": [
    {
      "id": "contact-001",
      "type": "name",
      "value": "Ayşe Yılmaz",
      "country": "TR",
      "options": {
        "ai_mode": "off"
      }
    },
    {
      "id": "contact-002",
      "type": "email",
      "value": "alice.smith@example.com",
      "options": {
        "ai_mode": "fallback"
      }
    },
    {
      "id": "contact-003",
      "type": "username",
      "value": "prenses",
      "country": "TR",
      "forceToGenderize": true
    }
  ]
}'
```

**JavaScript / Node.js**

Node.js 22+; बिल्ट-इन fetch। example.mjs के रूप में सेव करें और node example.mjs चलाएँ।

```javascript
// Server-side Node.js. Save as example.mjs.
const apiKey = process.env.GENDERAPI_API_KEY;
if (!apiKey) throw new Error("Set GENDERAPI_API_KEY");
const body = {
  "items": [
    {
      "id": "contact-001",
      "type": "name",
      "value": "Ayşe Yılmaz",
      "country": "TR",
      "options": {
        "ai_mode": "off"
      }
    },
    {
      "id": "contact-002",
      "type": "email",
      "value": "alice.smith@example.com",
      "options": {
        "ai_mode": "fallback"
      }
    },
    {
      "id": "contact-003",
      "type": "username",
      "value": "prenses",
      "country": "TR",
      "forceToGenderize": true
    }
  ]
};

const response = await fetch("https://api.genderapi.io/api/v2/gender/batch", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
  signal: AbortSignal.timeout(30_000),
  redirect: "error",
});
const raw = await response.text();
if (!(response.headers.get("content-type") ?? "").includes("json")) {
  throw new Error(`HTTP ${response.status}: expected JSON; request ID ${response.headers.get("x-request-id")}`);
}
const result = JSON.parse(raw); // Also accepts application/problem+json.
if (!response.ok) {
  console.error(`HTTP ${response.status}`, result);
  process.exitCode = 1; // A retry is a new operation; inspect billing first.
} else {
  console.log(JSON.stringify(result, null, 2));
  // For batches, inspect every item: HTTP 200 may contain item errors.
}
```

**Python**

Python 3.10+; स्टैंडर्ड लाइब्रेरी। example.py के रूप में सेव करें और python3 example.py चलाएँ।

```python
import json
import os
import sys
import urllib.error
import urllib.request

api_key = os.environ.get("GENDERAPI_API_KEY")
if not api_key:
    raise RuntimeError("Set GENDERAPI_API_KEY")
body = json.loads("{\"items\":[{\"id\":\"contact-001\",\"type\":\"name\",\"value\":\"Ayşe Yılmaz\",\"country\":\"TR\",\"options\":{\"ai_mode\":\"off\"}},{\"id\":\"contact-002\",\"type\":\"email\",\"value\":\"alice.smith@example.com\",\"options\":{\"ai_mode\":\"fallback\"}},{\"id\":\"contact-003\",\"type\":\"username\",\"value\":\"prenses\",\"country\":\"TR\",\"forceToGenderize\":true}]}")

class NoRedirect(urllib.request.HTTPRedirectHandler):
    def redirect_request(self, req, fp, code, msg, headers, newurl):
        return None

request = urllib.request.Request(
    "https://api.genderapi.io/api/v2/gender/batch",
    method="POST",
    data=json.dumps(body).encode("utf-8"),
    headers={
        "Authorization": "Bearer " + api_key,
        "Content-Type": "application/json",
    },
)
opener = urllib.request.build_opener(NoRedirect())
try:
    response = opener.open(request, timeout=30)
except urllib.error.HTTPError as error:
    response = error  # Keep the Problem Details body on non-2xx responses.
with response:
    status = response.status
    raw = response.read().decode("utf-8")
    if "json" not in response.headers.get("Content-Type", ""):
        raise RuntimeError(f"HTTP {status}: expected a JSON response")
    result = json.loads(raw)
print(json.dumps(result, indent=2), file=sys.stderr if status >= 300 else sys.stdout)
if not 200 <= status < 300:
    sys.exit(1)  # Inspect code, action and billing before retrying.
# For batches, inspect every item even when HTTP status is 200.
```

**PHP**

cURL एक्सटेंशन के साथ PHP 8+। example.php के रूप में सेव करें और php example.php चलाएँ।

```php
<?php
$apiKey = getenv('GENDERAPI_API_KEY');
if (!$apiKey) {
    throw new RuntimeException('Set GENDERAPI_API_KEY');
}
$body = json_decode('{"items":[{"id":"contact-001","type":"name","value":"Ayşe Yılmaz","country":"TR","options":{"ai_mode":"off"}},{"id":"contact-002","type":"email","value":"alice.smith@example.com","options":{"ai_mode":"fallback"}},{"id":"contact-003","type":"username","value":"prenses","country":"TR","forceToGenderize":true}]}', true, 512, JSON_THROW_ON_ERROR);

$ch = curl_init('https://api.genderapi.io/api/v2/gender/batch');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => false,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode($body, JSON_THROW_ON_ERROR),
]);
$raw = curl_exec($ch);
if ($raw === false) {
    throw new RuntimeException(curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE) ?: '';
curl_close($ch);
if (strpos($contentType, 'json') === false) {
    throw new RuntimeException("HTTP $status: expected a JSON response");
}
$result = json_decode($raw, true, 512, JSON_THROW_ON_ERROR);
$output = json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . PHP_EOL;
if ($status < 200 || $status >= 300) {
    fwrite(STDERR, $output); // Preserve the Problem Details body.
    exit(1);
}
echo $output;
// For batches, inspect every item; HTTP 200 can contain item errors.
```

**Java**

Java 17+; स्टैंडर्ड HTTP क्लाइंट। GenderApiExample.java के रूप में सेव करें और java GenderApiExample.java चलाएँ।

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;

public class GenderApiExample {
    private static String requiredEnv(String name) {
        String value = System.getenv(name);
        if (value == null || value.isBlank()) throw new IllegalStateException("Set " + name);
        return value;
    }

    public static void main(String[] args) throws Exception {
        String apiKey = requiredEnv("GENDERAPI_API_KEY");
        String body = "{\"items\":[{\"id\":\"contact-001\",\"type\":\"name\",\"value\":\"Ayşe Yılmaz\",\"country\":\"TR\",\"options\":{\"ai_mode\":\"off\"}},{\"id\":\"contact-002\",\"type\":\"email\",\"value\":\"alice.smith@example.com\",\"options\":{\"ai_mode\":\"fallback\"}},{\"id\":\"contact-003\",\"type\":\"username\",\"value\":\"prenses\",\"country\":\"TR\",\"forceToGenderize\":true}]}";
        HttpClient client = HttpClient.newBuilder()
            .connectTimeout(Duration.ofSeconds(10))
            .followRedirects(HttpClient.Redirect.NEVER)
            .build();
        HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.genderapi.io/api/v2/gender/batch"))
            .timeout(Duration.ofSeconds(30))
            .header("Authorization", "Bearer " + apiKey)
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(body, StandardCharsets.UTF_8))
            .build();
        HttpResponse<String> response = client.send(request,
            HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
        if (!response.headers().firstValue("content-type").orElse("").contains("json")) {
            throw new IllegalStateException("HTTP " + response.statusCode() + ": expected JSON");
        }
        // JSON text; parse with your application's JSON library when integrating.
        if (response.statusCode() < 200 || response.statusCode() >= 300) {
            System.err.println(response.body()); // Includes Problem Details.
            System.exit(1);
        }
        System.out.println(response.body());
        // For batches, inspect each item's data or error, including on HTTP 200.
    }
}
```

**C# / .NET**

.NET 8+ कंसोल ऐप्लिकेशन। कंसोल प्रोजेक्ट में Program.cs के रूप में इस्तेमाल करें, फिर dotnet run चलाएँ।

```csharp
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

string RequiredEnv(string name) =>
    !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(name))
        ? Environment.GetEnvironmentVariable(name)!
        : throw new InvalidOperationException($"Set {name}");

var apiKey = RequiredEnv("GENDERAPI_API_KEY");
using var handler = new HttpClientHandler { AllowAutoRedirect = false };
using var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(30) };
using var request = new HttpRequestMessage(HttpMethod.Post, "https://api.genderapi.io/api/v2/gender/batch");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
request.Content = new StringContent("{\"items\":[{\"id\":\"contact-001\",\"type\":\"name\",\"value\":\"Ayşe Yılmaz\",\"country\":\"TR\",\"options\":{\"ai_mode\":\"off\"}},{\"id\":\"contact-002\",\"type\":\"email\",\"value\":\"alice.smith@example.com\",\"options\":{\"ai_mode\":\"fallback\"}},{\"id\":\"contact-003\",\"type\":\"username\",\"value\":\"prenses\",\"country\":\"TR\",\"forceToGenderize\":true}]}", Encoding.UTF8, "application/json");

using var response = await client.SendAsync(request);
var raw = await response.Content.ReadAsStringAsync();
if (!(response.Content.Headers.ContentType?.MediaType?.Contains("json") ?? false))
    throw new InvalidOperationException($"HTTP {(int)response.StatusCode}: expected JSON");
using var result = JsonDocument.Parse(raw);
if (!response.IsSuccessStatusCode)
{
    Console.Error.WriteLine(result.RootElement); // Preserve Problem Details.
    Environment.ExitCode = 1;
}
else
{
    Console.WriteLine(result.RootElement);
    // For batches, inspect every item even on HTTP 200.
}
```

**Go**

Go 1.22+; स्टैंडर्ड लाइब्रेरी। main.go के रूप में सेव करें और go run main.go चलाएँ।

```go
package main

import (
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "os"
    "strings"
    "time"
)

func requiredEnv(name string) string {
    value := os.Getenv(name)
    if value == "" { panic("Set " + name) }
    return value
}

func run() error {
    apiKey := requiredEnv("GENDERAPI_API_KEY")
    body := "{\"items\":[{\"id\":\"contact-001\",\"type\":\"name\",\"value\":\"Ayşe Yılmaz\",\"country\":\"TR\",\"options\":{\"ai_mode\":\"off\"}},{\"id\":\"contact-002\",\"type\":\"email\",\"value\":\"alice.smith@example.com\",\"options\":{\"ai_mode\":\"fallback\"}},{\"id\":\"contact-003\",\"type\":\"username\",\"value\":\"prenses\",\"country\":\"TR\",\"forceToGenderize\":true}]}"
    request, err := http.NewRequest("POST", "https://api.genderapi.io/api/v2/gender/batch", strings.NewReader(body))
    if err != nil { return err }
    request.Header.Set("Authorization", "Bearer " + apiKey)
    request.Header.Set("Content-Type", "application/json")
    client := &http.Client{
        Timeout: 30 * time.Second,
        CheckRedirect: func(req *http.Request, via []*http.Request) error {
            return http.ErrUseLastResponse
        },
    }
    response, err := client.Do(request)
    if err != nil { return err }
    defer response.Body.Close()
    raw, err := io.ReadAll(response.Body)
    if err != nil { return err }
    if !strings.Contains(response.Header.Get("Content-Type"), "json") || !json.Valid(raw) {
        return fmt.Errorf("HTTP %d: expected a JSON response", response.StatusCode)
    }
    if response.StatusCode < 200 || response.StatusCode >= 300 {
        return fmt.Errorf("HTTP %d: %s", response.StatusCode, raw)
    }
    fmt.Println(string(raw))
    // For batches, inspect every item even on HTTP 200.
    return nil
}

func main() {
    if err := run(); err != nil {
        fmt.Fprintln(os.Stderr, err) // Keep Problem Details for error handling.
        os.Exit(1)
    }
}
```

- [अज्ञात परिणाम समझें](https://www.genderapi.io/hi/docs/v2/responses#application-decisions)
- [ईमेल इनपुट के नियम](https://www.genderapi.io/hi/docs/v2/gender-from-email)
- [यूज़रनेम और निकनेम के नियम](https://www.genderapi.io/hi/docs/v2/gender-from-username)
