基础用法
发起第一个 GenderAPI 请求
提交一个输入值,即可获得预测性别、概率、国家和额度使用信息。输入是姓名时使用基础接口;只有邮箱地址或用户名时,请使用相应的专用接口。
身份验证
使用 key 查询参数添加 API 密钥。生产环境密钥应保存在服务器端,切勿将私有密钥暴露在浏览器代码或公开代码仓库中。
GET
根据姓名判断性别
名字或完整姓名
输入名字或完整姓名时,请使用基础接口。
https://api.genderapi.io/apicURL
curl "https://api.genderapi.io/api?name=Alice&key=YOUR_API_KEY"可选参数
| 参数 | 类型 | 说明 |
|---|---|---|
country | string | 两位国家代码,例如 CN 或 US。 |
askToAI | boolean | 设为 true 时,如果数据库未找到姓名,将尝试使用 AI 补充分析。 |
forceToGenderize | boolean | 尝试分析看起来可能不像真实姓名的特殊输入。 |
请谨慎使用:对虚构姓名、昵称或低信息量输入进行强制预测时,准确度可能较低。
GET
根据邮箱判断性别
邮箱地址
邮箱接口会先从地址中提取可能的姓名,再进行性别判断。
https://api.genderapi.io/api/emailcURL
curl "https://api.genderapi.io/api/email?email=alice.smith%40example.com&country=CN&askToAI=true&key=YOUR_API_KEY"由于姓名由系统内部提取,此接口不支持
forceToGenderize 参数。GET
根据用户名判断性别
社交平台用户名
用户名、账号名或昵称中可能包含可识别姓名时,请使用此接口。
https://api.genderapi.io/api/usernamecURL
curl "https://api.genderapi.io/api/username?username=sparkling_unicorn&country=US&askToAI=true&forceToGenderize=true&key=YOUR_API_KEY"JSON 响应
了解 GenderAPI 响应结构
以上三个接口使用相同的核心响应结构。
200 OK
{
"status": true,
"used_credits": 1,
"remaining_credits": 4999,
"expires": 1743659200,
"q": "Alice",
"name": "alice",
"gender": "female",
"country": "US",
"total_names": 325,
"probability": 98,
"duration": "4ms"
}响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
status | boolean | 请求是否成功完成。 |
used_credits | integer | 本次请求消耗的 API 额度。 |
remaining_credits | integer | 请求完成后剩余的 API 额度。 |
expires | integer | 套餐到期时间,以 UNIX 时间戳表示。 |
q | string | 原始的姓名、邮箱地址或用户名查询值。 |
name | string | 标准化或从输入中提取的名字。 |
gender | string | null | 预测结果:male、female 或 null。 |
country | string | 最可能的 ISO 3166-1 alpha-2 国家代码。 |
total_names | integer | 用于支持本次预测的姓名记录数量。 |
probability | integer | 以百分比表示的预测概率。 |
duration | string | 服务器处理本次请求所用的时间。 |
始终对输入值进行 URL 编码
空格和特殊字符必须由 HTTP 客户端进行编码。例如,应使用 sparkling%20unicorn,而不是直接发送未编码的空格。
继续开发