API 参考
将匿名化集成到您的应用程序中
完整的 REST API 用于程序化 PII 检测和匿名化。
基础 URL
https://anonymize.today/api所有 API 端点都相对于此基础 URL。例如,分析端点是 https://anonymize.today/api/presidio/analyze.
身份验证
使用 Bearer 令牌对 API 请求进行身份验证:
Authorization: Bearer YOUR_API_TOKEN获取 API 令牌
- 登录到您的 anonymize.today 账户
- 转到设置 → 账户 → API 令牌
- 点击生成新令牌
- 复制并安全存储您的令牌(将不再显示)
安全提示
切勿在客户端代码或公共存储库中暴露您的 API 令牌。请使用环境变量和服务器端请求。
请求中的令牌
TypeScript
const response = await fetch('https://anonymize.today/api/presidio/analyze', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.ANONYMIZE_API_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ text, entities }),
});Python
import os
import requests
headers = {
"Authorization": f"Bearer {os.environ['ANONYMIZE_API_TOKEN']}",
"Content-Type": "application/json"
}
response = requests.post(
"https://anonymize.today/api/presidio/analyze",
headers=headers,
json={"text": text, "entities": entities}
)cURL
curl -X POST https://anonymize.today/api/presidio/analyze \
-H "Authorization: Bearer $ANONYMIZE_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "John Doe works at Acme Corp", "entities": ["PERSON", "ORGANIZATION"]}'速率限制
| 端点类型 | 速率限制 | 突发允许:10 个请求 |
|---|---|---|
| Authentication | 3 requests/second | 5 requests |
| Analysis & Anonymization | 30 requests/second | 50 requests |
| Presets & Settings | 10 requests/second | 20 requests |
当速率受到限制时,API 返回 429 请求过多,并带有 Retry-After 头,指示何时可以重试。
核心端点
分析文本
检测文本中的 PII 实体。返回检测到的实体的位置和类型。
匿名化文本
使用各种操作符匿名化检测到的 PII 实体。
解匿名化文本
使用相同的加密密钥将加密实体恢复为其原始值。
匿名化操作符
| 操作符 | 描述 | 可逆 | 示例 |
|---|---|---|---|
| replace | 替换为占位符 | No | John → [PERSON] |
| mask | 部分遮蔽字符 | No | john@email.com → j***@email.com |
| redact | 完全删除 | No | John → (empty) |
| hash | 单向 SHA-256 哈希 | No | John → a3f2b1c4... |
| encrypt | AES-256-GCM 加密 | Yes | John → [ENC:...] |
操作符配置
// Replace operator
{ "type": "replace", "new_value": "[PERSON]" }
// Mask operator
{
"type": "mask",
"masking_char": "*",
"chars_to_mask": 5,
"from_end": false
}
// Hash operator
{ "type": "hash", "hash_type": "sha256" }
// Encrypt operator (requires encryption key in user settings)
{ "type": "encrypt" }
// Redact operator
{ "type": "redact" }预设 API
实体类型
anonymize.today 支持 256 种实体类型,分为 10 个类别:
Personal
PERSON, EMAIL_ADDRESS, PHONE_NUMBER
Financial
CREDIT_CARD, IBAN_CODE, SWIFT_CODE, CRYPTO
Location
LOCATION, ADDRESS, COORDINATES
Government
SSN, PASSPORT, DRIVER_LICENSE, NATIONAL_ID
Contact
URL, DOMAIN_NAME
Technical
IP_ADDRESS, MAC_ADDRESS
Temporal
DATE_TIME, AGE
Organizational
ORGANIZATION, JOB_TITLE
Medical
MEDICAL_LICENSE, HEALTH_ID
Custom
User-defined patterns
请参阅预设文档中的完整实体类型列表。 Presets documentation.
支持的语言
API 支持 27 种语言进行 PII 识别:
| 代码 | 语言 | 引擎 |
|---|---|---|
| en | English | spaCy |
| de | German | spaCy |
| es | Spanish | spaCy |
| fr | French | spaCy |
| it | Italian | spaCy |
| pt | Portuguese | spaCy |
| nl | Dutch | spaCy |
| pl | Polish | spaCy |
| ru | Russian | spaCy |
| ja | Japanese | spaCy |
| zh | Chinese | spaCy |
| ko | Korean | spaCy |
| ar | Arabic | Transformer |
| hi | Hindi | Transformer |
| tr | Turkish | Transformer |
附加语言:罗马尼亚语、希腊语、克罗地亚语、斯洛文尼亚语、马其顿语、瑞典语、丹麦语、挪威语、芬兰语、乌克兰语、立陶宛语、加泰罗尼亚语
错误处理
标准 HTTP 状态代码:
| 状态 | 含义 | 描述 |
|---|---|---|
| 200 | OK | Request succeeded |
| 201 | Created | Resource created successfully |
| 400 | Bad Request | 400 - 错误请求(无效参数) |
| 401 | Unauthorized | 401 - 未授权(无效或缺失令牌) |
| 402 | Payment Required | Insufficient tokens |
| 403 | Forbidden | Access denied to resource |
| 404 | Not Found | Resource not found |
| 429 | Too Many Requests | 429 - 速率限制(请求过多) |
| 500 | Internal Error | 500 - 服务器错误(联系支持) |
错误响应格式
{
"error": {
"code": "INSUFFICIENT_TOKENS",
"message": "You need 5 tokens but only have 2 remaining",
"details": {
"required": 5,
"available": 2
}
}
}完整示例
TypeScript/Node.js
import fetch from 'node-fetch';
const API_BASE = 'https://anonymize.today/api';
const API_TOKEN = process.env.ANONYMIZE_API_TOKEN;
async function analyzeAndAnonymize(text: string) {
// Step 1: Analyze
const analyzeResponse = await fetch(`${API_BASE}/presidio/analyze`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
text,
entities: ['PERSON', 'EMAIL_ADDRESS', 'PHONE_NUMBER'],
language: 'en',
}),
});
const { results } = await analyzeResponse.json();
if (results.length === 0) {
return { text, anonymized: false };
}
// Step 2: Anonymize
const anonymizeResponse = await fetch(`${API_BASE}/presidio/anonymize`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
text,
analyzer_results: results,
anonymizers: {
DEFAULT: { type: 'replace', new_value: '[REDACTED]' },
},
}),
});
return anonymizeResponse.json();
}
// Usage
const result = await analyzeAndAnonymize('Contact John Doe at john@example.com');
console.log(result.text); // "Contact [REDACTED] at [REDACTED]"
Python
import os
import requests
API_BASE = "https://anonymize.today/api"
API_TOKEN = os.environ["ANONYMIZE_API_TOKEN"]
def analyze_and_anonymize(text: str) -> dict:
headers = {
"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"
}
# Step 1: Analyze
analyze_response = requests.post(
f"{API_BASE}/presidio/analyze",
headers=headers,
json={
"text": text,
"entities": ["PERSON", "EMAIL_ADDRESS", "PHONE_NUMBER"],
"language": "en"
}
)
results = analyze_response.json()["results"]
if not results:
return {"text": text, "anonymized": False}
# Step 2: Anonymize
anonymize_response = requests.post(
f"{API_BASE}/presidio/anonymize",
headers=headers,
json={
"text": text,
"analyzer_results": results,
"anonymizers": {
"DEFAULT": {"type": "replace", "new_value": "[REDACTED]"}
}
}
)
return anonymize_response.json()
# Usage
result = analyze_and_anonymize("Contact John Doe at john@example.com")
print(result["text"]) # "Contact [REDACTED] at [REDACTED]"
Related Documentation
最后更新:2026年3月