通过姓名批量识别性别
批量姓名端点允许你在单个请求中分析最多100个姓名的性别。 这对于批量处理和高性能集成非常有用。 所有参数通过POST请求以JSON格式发送。你必须在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 | 对象数组 | 是 | 包含姓名及其可选参数的数组。每次请求最多100个条目。 |
name | 字符串 | 是(每个对象) | 你要分析的名字。 |
country | 字符串 | 否 |
用于提升预测准确性的双字母国家代码(ISO 3166-1 alpha-2)。
例如:TR (土耳其)。
|
id | 字符串或整数 | 否 |
你自定义的可选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 | 整数 (时间戳) | 套餐到期时间(UNIX时间戳)。 |
names | 对象数组 | 每个输入姓名的结果列表。 |
names[].name | 字符串 | 姓名的标准化(小写)形式。 |
names[].q | 字符串 | 你提交的原始查询(区分大小写)。 |
names[].gender | 枚举字符串 | 预测性别:male (男)、female (女)或null 。 |
names[].country | 字符串 | 预测时考虑的国家代码。 |
names[].total_names | 整数 | 此次预测所用的样本数量。 |
names[].probability | 整数 | 性别预测的置信度百分比。 |
names[].id | 字符串/整数 | 你在请求中发送的同一个id 。用于匹配你的记录。 |
duration | 字符串 | 本次请求的总处理时间(如5ms )。 |
警告:
如果你发送多个姓名,请确保你的JSON数组格式正确,且不超过100个名字。
使用
id
字段将你自己的记录与API返回的结果进行关联。