名前による性別判定 - 単一リクエスト
Get Gender by Name エンドポイントを使用すると、 単一のファーストネームの性別を判定できます。 すべてのパラメータは JSON の POST リクエストとして送信されます。 認証には Authorization ヘッダーで Bearer トークン方式を使用する必要があります。
リクエスト URL
POST https://api.genderapi.io/api
必須 HTTP ヘッダー
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY
リクエストボディのパラメータ
パラメータ | 型 | 必須 | 説明 |
---|---|---|---|
name | String | 必須 | 判定したいファーストネーム。敬称やタイトルは含めず、単語1つで指定してください。 |
country | String | 任意 |
性別判定の精度を高めるための 2 文字の国コード(
ISO 3166-1 alpha-2)。
例:トルコの場合は TR 。
|
askToAI | Boolean | 任意 |
true に設定すると、指定した名前がデータベースに存在しない場合、
AI モデルに性別判定を依頼します。
|
forceToGenderize | Boolean | 任意 |
true に設定すると、
ニックネームやファンタジー名(例:sparkling unicorn )など、
一般的な人名でない入力に対しても性別推測を試みます。
|
リクエスト例
cURL の例
curl -X POST "https://api.genderapi.io/api" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"name": "Alice", "country": "US", "askToAI": true, "forceToGenderize": true}'
PHP cURL の例
<?php
$url = "https://api.genderapi.io/api";
$data = array(
"name" => "Alice",
"country" => "US",
"askToAI" => true,
"forceToGenderize" => true
);
$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", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
},
body: JSON.stringify({
name: "Alice",
country: "US",
askToAI: true,
forceToGenderize: true
})
})
.then(response => response.json())
.then(data => console.log(data));
Python requests の例
import requests
url = "https://api.genderapi.io/api"
payload = {
"name": "Alice",
"country": "US",
"askToAI": True,
"forceToGenderize": True
}
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": 1,
"remaining_credits": 4999,
"expires": 1743659200,
"q": "Alice",
"name": "Alice",
"gender": "female",
"country": "US",
"total_names": 10234,
"probability": 98,
"duration": "4ms"
}
レスポンスフィールド
フィールド | 型 | 説明 |
---|---|---|
status | Boolean | リクエストが成功したかどうか。 |
used_credits | Integer | このリクエストで消費したクレジット数。 |
remaining_credits | Integer | このリクエスト後に残っているクレジット数。 |
expires | Integer (timestamp) | パッケージの有効期限(UNIX タイムスタンプ)。 |
q | String | 送信した入力(name)。 |
name | String | 解析された、または抽出されたファーストネーム。 |
gender | Enum[String] | 予測された性別。可能な値は male 、female 、または null 。 |
country | String | 予測に使用された国コード。 |
total_names | Integer | この予測に使用されたサンプル数。 |
probability | Integer | 性別予測の信頼度(%)。 |
duration | String | リクエスト処理にかかった時間(例:4ms )。 |
注意:
入力する名前などの値に、予期しない文字が含まれないように注意してください。
特殊文字やスペースを使用する場合は、エラーを避けるために正しく JSON エンコードしてください。