请求概览
从用户名推导出可能的姓名
GenderAPI 会在提交的用户名中查找名称信号,然后结合数据库证据、国家背景,以及在需要时的AI备用方案来预测性别。
Input
→sparkling_unicorn提取的信号
→SparklingPrediction
女性 · 92%MethodPOST
内容类型application/json
AuthenticationBearer令牌
AI选项Available
HDR
必需的HTTP头
授权请求
Content-Typeapplication/jsonAuthorizationBearer YOUR_API_KEYJSON 请求体
参数
| Parameter | Type | Requirement | Description |
|---|---|---|---|
username | string | 必填项 | 需要分析的用户名、社交账号、显示名称或昵称。 |
country | string | 可选 | ISO 3166-1 alpha-2 国家代码,例如 US 或 TR,用于区域上下文。 |
askToAI | boolean | 可选 | 当为 true 时,如果提取的名称在数据库中无结果,则使用 AI 降级处理。 |
forceToGenderize | boolean | 可选 | 当为 true 时,尝试对别名或不符合典型名称格式的输入进行预测。 |
置信度很重要:对于弱或非人类姓名信号的强制结果可能不够可靠。在采取预测行动前需评估
probability。代码示例
发送用户名请求
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}'JavaScript
const response = await 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 })
});Python
import requests
response = requests.post(
"https://api.genderapi.io/api/username",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"username": "sparkling_unicorn", "country": "US", "askToAI": True, "forceToGenderize": True}
)
print(response.json())200 响应
提取的信号 and prediction
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"
}响应字段
| Field | Type | Description |
|---|---|---|
status | boolean | 请求是否成功完成。 |
used_credits | integer | 本次请求消耗的信用额度。 |
remaining_credits | integer | 请求后剩余的信用额度。 |
expires | integer | 套餐过期时间,以 UNIX 时间戳表示。 |
q | string | 请求中提交的原始用户名。 |
name | string | 从用户名中提取的可能姓名。 |
gender | string | null | 预测值:男、女或空值。 |
country | string | 预测所考虑的国家代码。 |
total_names | integer | 支持该预测的样本数量。 |
probability | integer | 预测置信度,以百分比表示。 |
duration | string | 服务器处理时间。 |
将用户名视为间接信号
一个用户名可能描述一个品牌、角色或概念,而非一个人。确认提取结果是否具有意义,并为您的使用场景建立可接受的概率阈值。name一个用户名可能描述一个品牌、角色或概念,而非一个人。确认提取结果是否具有意义,并为您的使用场景建立可接受的概率阈值。
下一步指南