通过用户名获取性别 - 单次请求

通过用户名获取性别端点,允许您通过分析用户名或昵称来判断一个人的性别。 所有参数通过 JSON 格式的 POST 请求发送。您必须在 Authorization 头中使用 Bearer token 进行身份验证。

请求 URL

POST https://api.genderapi.io/api/username

必需的 HTTP 请求头

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

请求体参数

参数 类型 是否必填 说明
username String 要分析的用户名或昵称。可以是社交媒体用户名、屏幕名或别名。 也可能包含非真实姓名的词汇,比如幻想词汇或品牌名。
country String 两位字母的国家代码 (ISO 3166-1 alpha-2), 用于提高预测准确率。例如:土耳其用 TR
askToAI Boolean 若设置为 true,当数据库中找不到提取到的姓名时,API 会调用 AI 模型来判断性别。
forceToGenderize Boolean 若设置为 true,即使用户名看起来不像真实人名(如幻想词或昵称,例如 sparkling_unicorn), API 也会尝试预测性别。

请求示例


cURL 示例

curl -X POST "https://api.genderapi.io/api/username" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -d '{"username": "sparkling_unicorn", "country": "US", "askToAI": true, "forceToGenderize": true}'

PHP cURL 示例

<?php
$url = "https://api.genderapi.io/api/username";

$data = array(
    "username" => "sparkling_unicorn",
    "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/username", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_API_KEY"
  },
  body: JSON.stringify({
    username: "sparkling_unicorn",
    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/username"

payload = {
    "username": "sparkling_unicorn",
    "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": "sparkling_unicorn",
  "name": "Sparkling",
  "gender": "female",
  "country": "US",
  "total_names": 9876,
  "probability": 92,
  "duration": "6ms"
}

响应字段

字段 类型 说明
status Boolean 指示请求是否成功。
used_credits Integer 此次请求消耗的额度。
remaining_credits Integer 此次请求后,账户剩余的额度。
expires Integer (timestamp) 您的套餐过期时间,Unix 时间戳格式。
q String 您提交的输入查询(用户名)。
name String 从用户名中提取到的名字。
gender Enum[String] 预测的性别。可能的值:malefemalenull
country String 预测过程中参考的国家代码。
total_names Integer 此次预测所用的样本数量。
probability Integer 性别预测的置信度百分比。
duration String 处理请求所需时间(例如 6ms)。