名前による性別判定 - 複数リクエスト

Multiple Names エンドポイントを利用すると、 一度のリクエストで最大 100 件の名前の性別を分析できます。 これは大量処理や高パフォーマンスの統合に便利です。 すべてのパラメータは JSON の POST リクエストで送信されます。 認証には Authorization ヘッダーで Bearer トークン方式を使用する必要があります。

各名前に country フィルタを追加することで、 特定の国に基づく性別判定結果を取得できます。 指定した国で結果が見つからない場合は、 API はグローバルな名前データの結果を返します。

また各名前ごとに任意の id フィールドを渡すことができます。 この値は、あなたのデータベース上の任意の文字列または整数で構いません。 API はレスポンスに同じ id を返すので、 入力データと結果を照合するのに便利です。

注意: 複数リクエストは AIベースの推論モデルには対応していません。 askToAI のようなパラメータは一括処理では利用できません。

データに非ラテン文字(例:中国語)で書かれた名前が多い場合は、 より正確な結果を得るために askToAI を使った単一リクエストを送信することを強くお勧めします。

リクエスト URL

POST https://api.genderapi.io/api/name/multi/country

必須 HTTP ヘッダー

  • Content-Type: application/json
  • Authorization: Bearer YOUR_API_KEY

リクエストボディのパラメータ

フィールド 必須 説明
data Array of Objects 必須 名前とオプションパラメータの配列。1回のリクエストで最大 100 件まで送信可能。
name String 必須(各オブジェクト内) 解析したいファーストネーム。
country String 任意 性別判定の精度を高めるための 2 文字の国コード( ISO 3166-1 alpha-2)。 例:TR はトルコ。
id String または Integer 任意 結果とあなたのデータベースを紐づけるためのオプションの ID。 レスポンスにも同じ id が返されます。

リクエストボディ例

{
  "data": [
    { "name": "Andrea", "country": "DE", "id": "123" },
    { "name": "andrea", "country": "IT", "id": "456" },
    { "name": "james", "country": "US", "id": "789" }
  ]
}

リクエスト例


cURL の例

curl -X POST "https://api.genderapi.io/api/name/multi/country" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -d '{"data":[{"name":"Andrea","country":"DE","id":"123"},{"name":"andrea","country":"IT","id":"456"},{"name":"james","country":"US","id":"789"}]}'

PHP cURL の例

<?php
$url = "https://api.genderapi.io/api/name/multi/country";

$data = array(
    "data" => array(
        array(
            "name" => "Andrea",
            "country" => "DE",
            "id" => "123"
        ),
        array(
            "name" => "andrea",
            "country" => "IT",
            "id" => "456"
        ),
        array(
            "name" => "james",
            "country" => "US",
            "id" => "789"
        )
    )
);

$payload = json_encode($data);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type: application/json",
    "Authorization: Bearer YOUR_API_KEY"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>

JavaScript fetch の例

fetch("https://api.genderapi.io/api/name/multi/country", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_API_KEY"
  },
  body: JSON.stringify({
    data: [
      { name: "Andrea", country: "DE", id: "123" },
      { name: "andrea", country: "IT", id: "456" },
      { name: "james", country: "US", id: "789" }
    ]
  })
})
.then(response => response.json())
.then(data => console.log(data));

Python requests の例

import requests

url = "https://api.genderapi.io/api/name/multi/country"

payload = {
    "data": [
        { "name": "Andrea", "country": "DE", "id": "123" },
        { "name": "andrea", "country": "IT", "id": "456" },
        { "name": "james", "country": "US", "id": "789" }
    ]
}

headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_API_KEY"
}

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

print(response.json())

JSON レスポンス例

{
  "status": true,
  "used_credits": 3,
  "remaining_credits": 7265,
  "expires": 1717069765,
  "names": [
    {
      "name": "andrea",
      "q": "Andrea",
      "gender": "female",
      "country": "DE",
      "total_names": 644,
      "probability": 88,
      "id": "optional"
    },
    {
      "name": "andrea",
      "q": "andrea",
      "gender": "male",
      "country": "IT",
      "total_names": 13537,
      "probability": 98,
      "id": "optional"
    },
    {
      "name": "james",
      "q": "james",
      "gender": "male",
      "country": "US",
      "total_names": 45274,
      "probability": 100,
      "id": "optional"
    }
  ],
  "duration": "5ms"
}

レスポンスフィールド

フィールド 説明
status Boolean リクエストが成功したかどうか。
used_credits Integer このリクエストで消費したクレジット数。
remaining_credits Integer このリクエスト後に残っているクレジット数。
expires Integer (timestamp) パッケージの有効期限(UNIX タイムスタンプ)。
names Array of objects 入力した各名前の結果リスト。
names[].name String 正規化された名前(小文字)。
names[].q String 送信した元のクエリ(大文字小文字を区別)。
names[].gender Enum[String] 推定された性別:malefemale、または null
names[].country String 予測に使用された国コード。
names[].total_names Integer この予測に使用されたサンプル数。
names[].probability Integer 性別予測の信頼度(%)。
names[].id String / Integer リクエスト時に送信した id と同じ値。結果と自身のレコードを紐づける際に利用。
duration String リクエスト処理にかかった時間(例:5ms)。
注意: 複数の名前を送る際は、JSON 配列が正しくフォーマットされており、 100 件を超えないようにしてください。 id フィールドを使うことで、 自身のレコードと API の返却結果を照合できます。