REST API 参考
四个端点,统一响应格式。以下所有内容均实时对接您的账户。
https://namegender.com/api
免费注册
快速开始
在仪表板中创建密钥,然后发送第一个请求。无需 SDK。
curl "https://namegender.com/api?name=Ay%C5%9Fe&country=TR" \
-H "Authorization: Bearer YOUR_API_KEY"
<?php
$query = http_build_query(['name' => 'Ayşe', 'country' => 'TR']);
$ch = curl_init('https://namegender.com/api?' . $query);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY'],
]);
$result = json_decode(curl_exec($ch), true);
echo $result['gender']; // female
echo $result['probability']; // 100
const params = new URLSearchParams({ name: 'Ayşe', country: 'TR' });
const response = await fetch(`https://namegender.com/api?${params}`, {
headers: { Authorization: 'Bearer YOUR_API_KEY' },
});
const result = await response.json();
console.log(result.gender); // "female"
console.log(result.probability); // 100
import requests
response = requests.get(
"https://namegender.com/api",
params={"name": "Ayşe", "country": "TR"},
headers={"Authorization": "Bearer YOUR_API_KEY"},
)
result = response.json()
print(result["gender"]) # female
print(result["probability"]) # 100
require "net/http"
require "json"
uri = URI("https://namegender.com/api")
uri.query = URI.encode_www_form(name: "Ayşe", country: "TR")
request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Bearer YOUR_API_KEY"
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
puts JSON.parse(response.body)["gender"] # female
req, _ := http.NewRequest("GET", "https://namegender.com/api?name=Ay%C5%9Fe&country=TR", nil)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
var result struct {
Gender string `json:"gender"`
Probability int `json:"probability"`
}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result.Gender) // female
每个端点返回相同的结构,因此你可以切换输入而无需修改解析代码。
身份验证
通过三种方式之一传递你的 API key。建议使用 Authorization header:查询字符串会被记录在服务器日志和浏览器历史中。
Authorization: Bearer ng_live_xxxxxxxxxxxx
X-Api-Key: ng_live_xxxxxxxxxxxx
https://namegender.com/api?name=Ayşe&key=ng_live_xxxxxxxxxxxx
你可以从仪表板将 key 限制到特定 IP 地址。
客户端库
单个 API、四种输入类型,以及能处理其他服务无法应对的文件的批量工具。
查看全部https://namegender.com/api
从名字识别性别
接受名字或全名。查询前会去除头衔、中间名和姓氏,因此「Dr. Ayşe Yılmaz」和「Ayşe」会返回相同结果。
| 参数 | 类型 | 描述 |
|---|---|---|
name
必需
|
string
|
要分类的名字。名字或全名。 |
country
可选
|
string
|
ISO 3166-1 alpha-2 国家代码。对于性别因地区而异的名字(如 Andrea,在意大利是男性名字,在德国是女性名字),可提高准确度。 |
askToAI
可选
|
boolean
|
当数据库中不存在该名字时,回退使用语言模型。需要额外消耗一个点数。 |
forceToGenderize
可选
|
boolean
|
即使置信度低于阈值也返回最可能的性别。默认关闭,因为确定地给出掷硬币的答案比没有答案更糟。 |
curl "https://namegender.com/api?name=Jordan" \
-H "Authorization: Bearer YOUR_API_KEY"
{
"status": true,
"used_credits": 1,
"remaining_credits": 49999,
"expires": null,
"q": "Jordan",
"name": "Jordan",
"gender": "male",
"country": null,
"total_names": 62240,
"probability": 84,
"confidence": "high",
"duration": "1ms",
"source": "db",
"matched_as": null
}
https://namegender.com/api/email
从邮箱识别性别
从邮箱地址的本地部分(@ 前)提取名字,然后进行分类。"ayse.yilmaz84@example.com" 解析为 Ayşe。
| 参数 | 类型 | 描述 |
|---|---|---|
email
必需
|
string
|
邮箱地址。仅使用 @ 前的部分。 |
country
可选
|
string
|
ISO 3166-1 alpha-2 国家代码。对于性别因地区而异的名字(如 Andrea,在意大利是男性名字,在德国是女性名字),可提高准确度。 |
askToAI
可选
|
boolean
|
当数据库中不存在该名字时,回退使用语言模型。需要额外消耗一个点数。 |
此处不支持 forceToGenderize:名字是内部提取的,对不确定的提取结果强制指定会叠加两层猜测。
curl "https://namegender.com/api/email?email=ayse.yilmaz84%40example.com" \
-H "Authorization: Bearer YOUR_API_KEY"
{
"status": true,
"q": "ayse.yilmaz84@example.com",
"name": "Ayse",
"gender": "female",
"probability": 95,
"confidence": "unverified",
"total_names": 655,
"duration": "1ms",
"source": "db"
}
https://namegender.com/api/username
从用户名判断性别
支持驼峰式、蛇形命名、末尾数字和开头 @ 符号。"AyseYilmaz84" 解析为 Ayşe。
| 参数 | 类型 | 描述 |
|---|---|---|
username
必需
|
string
|
用户名或账号。开头的 @ 符号会被忽略。 |
country
可选
|
string
|
ISO 3166-1 alpha-2 国家代码。对于性别因地区而异的名字(如 Andrea,在意大利是男性名字,在德国是女性名字),可提高准确度。 |
askToAI
可选
|
boolean
|
当数据库中不存在该名字时,回退使用语言模型。需要额外消耗一个点数。 |
forceToGenderize
可选
|
boolean
|
即使置信度低于阈值也返回最可能的性别。默认关闭,因为确定地给出掷硬币的答案比没有答案更糟。 |
curl "https://namegender.com/api/username?username=AyseYilmaz84" \
-H "Authorization: Bearer YOUR_API_KEY"
{
"status": true,
"q": "AyseYilmaz84",
"name": "Ayse",
"gender": "female",
"probability": 95,
"confidence": "unverified",
"source": "db"
}
https://namegender.com/api/bulk
批量请求
一次请求最多支持 100 个名字。使用此功能而不是循环调用:一次批量调用处理 100 个名字只需一次往返和一次去重查询。
| 参数 | 类型 | 描述 |
|---|---|---|
names
必需
|
string[]
|
名字数组。最多 100 项。 |
type
可选
|
string
|
项目类型:name、email 或 username。默认为 name。 |
country
可选
|
string
|
应用于请求中的每一项。 |
curl -X POST "https://namegender.com/api/bulk" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"names": ["Ayşe", "Mehmet", "Priya", "Wei"]}'
<?php
$ch = curl_init('https://namegender.com/api/bulk');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'names' => ['Ayşe', 'Mehmet', 'Priya', 'Wei'],
]),
]);
$data = json_decode(curl_exec($ch), true);
foreach ($data['results'] as $row) {
printf("%-8s %-7s %d%%\n", $row['q'], $row['gender'] ?? '?', $row['probability']);
}
const response = await fetch('https://namegender.com/api/bulk', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({ names: ['Ayşe', 'Mehmet', 'Priya', 'Wei'] }),
});
const { results, summary } = await response.json();
console.log(summary.match_rate); // 100
results.forEach(r => console.log(r.q, r.gender, r.probability));
import requests
response = requests.post(
"https://namegender.com/api/bulk",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"names": ["Ayşe", "Mehmet", "Priya", "Wei"]},
)
data = response.json()
print(data["summary"]["match_rate"]) # 100
for row in data["results"]:
print(row["q"], row["gender"], row["probability"])
{
"status": true,
"used_credits": 4,
"remaining_credits": 49995,
"duration": "2ms",
"summary": {
"total": 4,
"identified": 4,
"unknown": 0,
"match_rate": 100
},
"results": [
{ "q": "Ayşe", "gender": "female", "probability": 95, "total_names": 0, "confidence": "unverified", "source": "db" },
{ "q": "Mehmet", "gender": "male", "probability": 95, "total_names": 0, "confidence": "unverified", "source": "db" },
{ "q": "Priya", "gender": "female", "probability": 95, "total_names": 0, "confidence": "unverified", "source": "db" },
{ "q": "Wei", "gender": "male", "probability": 85, "total_names": 0, "confidence": "unverified", "source": "db" }
]
}
结果按发送顺序返回。积分按名字数计费,如果余额不足,整个请求在任何处理前会被拒绝,所以你永远不会得到半处理的批次。
摘要区块一目了然地显示匹配率,让你决定是否需要在处理其余数据前清洗输入数据。
https://namegender.com/api/me
账户与配额
查看剩余余额,不消费积分。
curl "https://namegender.com/api/me" \
-H "Authorization: Bearer YOUR_API_KEY"
{
"status": true,
"email": "you@example.com",
"remaining_credits": 50099,
"purchased_credits": 50000,
"free_today": 99,
"free_daily_limit": 100,
"lifetime_requests": 12480,
"expires": null
}
非拉丁字母
输入原文字的姓名,我们将其关联到参考数据。无需额外参数:我们自动检测字母类型并应用相应策略。
阿拉伯文省略短元音,因此 محمد 音译为 "mhmd",而我们的数据中为 "muhammed"。我们改为匹配辅音模式,并保留阴性标记 ة,使 خالد (Khalid) 和 خالدة (Khalida) 区分开来。同时支持用阿拉伯字母书写的波斯语和乌尔都语姓名。
转换为拼音。中文姓名中姓氏在前,例如 李明 的姓为 李 (Li),名为 明 (Ming) — 我们在查询前会去除姓氏。单个字符作为完整的名字进行处理。
与中文相同的姓氏优先处理方式,使用常见的韩国姓氏。
平假名和片假名正确识别(ひろし → Hiroshi)。
俄语、乌克兰语、保加利亚语和塞尔维亚语名字可直接音译。
印地语、马拉地语和尼泊尔语名字。已正确处理固有的末尾元音(राहुल → Rahul,而非 "Rahula")。
日语汉字和中文字符占据相同的 Unicode 范围,因此我们无法仅从字符本身区分它们。汉字输入被识别为中文:我们未曾精确保存的汉字名字会被给予普通话读音,但对于日语名字通常是错误的(健太被读作「jian tai」,而实际名字是 Kenta)。我们已保存的名字可精确匹配并正确识别。为确保准确,请用平假名或拉丁字母提交日语名字。
泰语像阿拉伯语一样省略元音,需要专门的匹配层。目前尚未实现,这些返回 null。
# Arap yazısı — ünsüz iskeleti üzerinden eşleşir
curl "https://namegender.com/api?name=%D9%85%D8%AD%D9%85%D8%AF" -H "Authorization: Bearer KEY"
# -> { "gender": "male", "probability": 100, "source": "script", "matched_as": "mahamad" }
# Çince — soyadı ayıklanır, verilen ad sorgulanır
curl "https://namegender.com/api?name=%E6%9D%8E%E6%98%8E" -H "Authorization: Bearer KEY"
# -> { "gender": "male", "probability": 92, "source": "db" }
当我们无法桥接脚本时,响应将返回 gender: null 且 source: none。请检查 source 字段:script 表示我们进行了音译,db 表示我们直接匹配了您发送的字符。这两种方式的 confidence 不同,我们会向您显示您获得的是哪一种。
响应字段
在所有端点中保持一致。
| 字段 | 类型 | 描述 |
|---|---|---|
status
|
boolean
|
请求失败时为 false。先检查这个字段。 |
used_credits
|
integer
|
此次请求消耗的额度。 |
remaining_credits
|
integer
|
请求后剩余的额度。 |
expires
|
null
|
始终为 null。购买的额度不会过期。 |
q
|
string
|
你的输入,原封不动地回显。 |
name
|
string
|
移除头衔和姓氏后实际查询的名字。 |
gender
|
string
|
男、女或 null(当我们不够确定时)。 |
country
|
string
|
统计数据的来源国家,或用于全球汇总的 null。 |
total_names
|
integer
|
这个答案基于多少真实人物。0 表示来源提供比例而非计数,不代表答案不可靠。 |
probability
|
integer
|
对所述性别的置信度,50 到 100。性别为 null 时为 0。 |
duration
|
string
|
服务器端处理时间。 |
其他服务不提供的两个字段
source 告诉你答案的来源:参考数据库、模糊匹配或 AI 备选方案。matched_as 显示模糊匹配命中的条目。通过这两个字段,你可以决定对单个结果的信任程度,而不是盲目接受。
| 字段 | 类型 | 描述 |
|---|---|---|
source
|
string
|
db、fuzzy、llm 或 none。 |
confidence
|
string
|
高、中、低、未验证或未知,基于样本证据。 |
matched_as
|
string
|
模糊匹配时,匹配到的数据库条目。否则为 null。 |
错误代码
错误返回 JSON 响应体,包含 status: false 和机器可读的错误字符串。根据错误码而非消息匹配:消息会被翻译且可能变化。
| 代码 | HTTP | 含义 |
|---|---|---|
missing_key |
401 | API key 缺失。请将其作为 "key" 参数或 Authorization: Bearer header 传递。 |
invalid_key |
401 | 此 API key 无效。 |
revoked_key |
401 | 此 API key 已被撤销。 |
blocked |
403 | 账户已被冻结。请联系支持团队。 |
email_not_verified |
403 | 该账户的邮箱地址尚未确认。请打开我们发送的确认链接,或在控制台重新申请。 |
ip_not_allowed |
403 | 不允许从此 IP 地址对此 key 发起请求。 |
forbidden |
403 | 您无权执行此操作。 |
no_credits |
402 | 您的额度已耗尽。请购买更多或等待每日免费额度重置。 |
missing_input |
400 | "name" 参数为必填项。 |
invalid_input |
422 | "name" 参数无效。 |
too_many_items |
422 | 单次请求最多可发送 100 项。 |
ai_consent_required |
422 | askToAI 会将姓名发送给第三方 AI 提供商,但该账户尚未同意此操作。查看"ai"字段了解提供商信息,然后在仪表板设置中启用 AI 查询功能。 |
unknown_endpoint |
404 | 此路径没有 endpoint。请根据 API 文档检查 URL。 |
method_not_allowed |
405 | 此 endpoint 不接受 DELETE 请求。 |
payload_too_large |
413 | 请求体过大。 |
rate_limited |
429 | 请求过于频繁。请放慢速度,稍后重试。 |
not_ready |
503 | 姓名数据库正在重建中。请稍后重试。 |
server_error |
500 | 我们这边出现问题。我们已收到通知。 |
{
"status": false,
"error": "no_credits",
"message": "You are out of credits. Buy more or wait for your daily free quota to reset.",
"request_id": "req_9c1f5b2a7e0d4a13",
"docs": "https://namegender.com/docs#error-no_credits"
}
速率限制
正常使用不会触及限制。该上限用于防止泄露的密钥被滥用,限制按 API 密钥而非 IP 计算,这样多个客户共用同一服务器时不会相互消耗配额。
当前限制:每个密钥每分钟 1,200 个请求。需要更高限制?告诉我们,我们会为你的账户提升。
每个响应都包含标准的 X-RateLimit-Limit 和 X-RateLimit-Remaining header。
从其他服务商迁移
我们的响应字段和参数名称遵循通用约定,因此切换通常只需改一行:基础 URL。
- https://api.other-provider.io/api?name=Ayşe&key=KEY
+ https://namegender.com/api?name=Ayşe&key=KEY
askToAI 和 forceToGenderize 保持原始拼写正是为了这个原因。如果你依赖的字段缺失,告诉我们,我们会添加。
编码您的输入
名字可能包含空格和非 ASCII 字符。在将其放入查询字符串之前,请对值进行 URL 编码,或者使用 POST 方法并使用 JSON 正文。
Ayşe Yılmaz -> Ay%C5%9Fe%20Y%C4%B1lmaz
محمد -> %D9%85%D8%AD%D9%85%D8%AF
中村 -> %E4%B8%AD%E6%9D%91