← 返回生成器
OpenAPI 3.1 JSON

鉴权

除健康检查、就绪检查和 OpenAPI 外,所有接口都需要管理员控制台创建的 Bearer Token。令牌支持读取或生成权限、每分钟限速和到期时间。

Authorization: Bearer YOUR_API_TOKEN
GET/api/v1/health
权限: public

检查 API 进程是否可用。

参数

此接口没有请求参数。

调用示例

curl "https://address.example/api/v1/health" \

成功响应

{
  "status": "ok"
}
GET/api/v1/ready
权限: public

检查 API 和 PostgreSQL 是否可以接收流量。

参数

此接口没有请求参数。

调用示例

curl "https://address.example/api/v1/ready" \

成功响应

{
  "status": "ready"
}
GET/api/v1/countries
权限: read

列出支持的国家、能力、地址数量和快捷区域。

参数

此接口没有请求参数。

调用示例

curl "https://address.example/api/v1/countries" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \

成功响应

{
  "data": [
    {
      "code": "US",
      "residentialAvailable": true,
      "residentialCount": 50000,
      "generationMode": "synchronized-pool"
    }
  ]
}
GET/api/v1/availability
权限: read

返回轻量级住宅地址可用性列表。

参数

此接口没有请求参数。

调用示例

curl "https://address.example/api/v1/availability" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \

成功响应

{
  "data": [
    {
      "code": "US",
      "residentialAvailable": true
    }
  ]
}
GET/api/v1/client-context
权限: read

解析请求 IP 对应的国家和位置上下文。

参数

ip可选 · query · string可选 IPv4 或 IPv6;省略时使用当前请求 IP。

调用示例

curl "https://address.example/api/v1/client-context?ip=198.51.100.7" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \

成功响应

{
  "data": {
    "country": "US",
    "region": "California",
    "city": "Los Angeles",
    "matchLevel": "city"
  }
}
GET/api/v1/locations/search
权限: read

分页搜索州省、城市、区县或邮编。

参数

country可选 · query · string · 默认值: USISO 3166-1 alpha-2 国家或地区代码。
field可选 · query · string · 默认值: city要返回的目录字段。
q可选 · query · string可选、不区分大小写的搜索文本。
region可选 · query · string精确的上级行政区值。
regionId可选 · query · string稳定的上级行政区 ID。
cityId可选 · query · string稳定的上级城市 ID。
residential可选 · query · boolean · 默认值: false仅统计已发布的住宅记录。
cursor可选 · query · string上一页返回的不透明游标。
limit可选 · query · integer · 默认值: 100 · 20-200每页 20 至 200 条。

调用示例

curl "https://address.example/api/v1/locations/search?country=US&field=city&regionId=1416&limit=100" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \

成功响应

{
  "data": {
    "cities": [
      {
        "id": "example-city",
        "value": "Los Angeles",
        "availableCount": 120
      }
    ],
    "total": 1,
    "nextCursor": null
  }
}
GET/api/v1/generate
权限: generate

随机生成一个已发布的真实住宅地址和测试资料。

参数

country可选 · query · string · 默认值: USISO 3166-1 alpha-2 国家或地区代码。
region可选 · query · string精确的一级行政区值。
regionId可选 · query · string位置搜索返回的行政区 ID。
city可选 · query · string精确城市值。
cityId可选 · query · string位置搜索返回的城市 ID。
district可选 · query · string支持国家的精确区县值。
districtId可选 · query · string位置搜索返回的稳定区县 ID。
postcode可选 · query · string精确邮编值。
postcodeId可选 · query · string位置搜索返回的邮编 ID。
mode可选 · query · string使用 ip-region 按请求或指定 IP 匹配。
ip可选 · query · stringip-region 模式使用的 IPv4 或 IPv6。
q可选 · query · string必须出现在所选地址字段中的文本。
strategy可选 · query · string · 默认值: random选择策略;两种模式都从已同步数据库选择。
residential可选 · query · boolean · 默认值: true兼容旧客户端的参数;生成接口始终返回住宅记录。
seed可选 · query · string可选的可复现随机种子。
requestId可选 · query · string调用方提供的请求关联 ID。

调用示例

curl "https://address.example/api/v1/generate?country=US&region=California&requestId=YOUR_REQUEST_ID" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \

成功响应

{
  "data": {
    "requestId": "YOUR_REQUEST_ID",
    "country": "US",
    "mode": "residential",
    "sourcesTried": [
      "address-pool-v2"
    ],
    "result": {
      "address": {
        "id": "address-id",
        "countryCode": "US",
        "formattedAddress": "Example address"
      }
    }
  }
}
POST/api/v1/generate/batch
权限: generate

使用结构化筛选、排除条件和唯一性控制批量生成最多 50 个住宅地址。

参数

count必填 · body · integer · 1-50要生成的地址数量。
filters必填 · body · object国家以及精确行政区、邮编或文本筛选条件。
options可选 · body · object随机性、唯一性、策略和请求关联选项。
excludeAddressIds可选 · body · array不得返回的地址 ID 列表。

调用示例

curl -X POST "https://address.example/api/v1/generate/batch" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{
  "count": 3,
  "filters": {
    "country": "US",
    "region": "California",
    "city": "Los Angeles"
  },
  "options": {
    "unique": true,
    "strategy": "random",
    "seed": "example-seed"
  },
  "excludeAddressIds": []
}'

成功响应

{
  "data": {
    "requestId": "batch-request-id",
    "requestedCount": 3,
    "returnedCount": 3,
    "unique": true,
    "results": [
      {
        "address": {
          "id": "address-id",
          "countryCode": "US"
        }
      }
    ]
  }
}
GET/api/v1/locations/hierarchy
权限: read

列出国家、省州或城市的下一级行政区或邮编。

参数

country必填 · query · stringISO 3166-1 alpha-2 国家或地区代码。
childType必填 · query · string要返回的下级目录类型。
parentType可选 · query · string · 默认值: countryparentId 指定的上级类型。
parentId可选 · query · string稳定的省州或城市 ID;国家上级时省略。
q可选 · query · string可选的下级名称搜索文本。
residential可选 · query · boolean · 默认值: true包含住宅可用数量并禁用无覆盖选项。
cursor可选 · query · string上一页返回的不透明游标。
limit可选 · query · integer · 默认值: 100 · 20-200每页 20 至 200 条。

调用示例

curl "https://address.example/api/v1/locations/hierarchy?country=US&parentType=region&parentId=1416&childType=city&limit=100" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \

成功响应

{
  "data": {
    "parent": {
      "type": "region",
      "id": "1416"
    },
    "childType": "city",
    "children": [
      {
        "id": "example-city",
        "value": "Los Angeles",
        "availableCount": 120
      }
    ],
    "total": 1,
    "nextCursor": null
  }
}
GET/api/v1/coverage
权限: read

返回已启用国家的三项同步完成规则。

参数

country可选 · query · string可选的 ISO 国家代码筛选。
includeComplete可选 · query · boolean · 默认值: true是否包含已经满足全部三项规则的国家。

调用示例

curl "https://address.example/api/v1/coverage?country=US&includeComplete=true" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \

成功响应

{
  "data": {
    "countries": [
      {
        "countryCode": "US",
        "complete": false,
        "rules": {
          "total": {
            "current": 42000,
            "target": 50000,
            "met": false
          },
          "administrativeCoverage": {
            "actual": 0.98,
            "target": 1,
            "met": false
          },
          "regionalMinimums": {
            "actual": 0.95,
            "target": 1,
            "met": false
          }
        }
      }
    ]
  }
}
GET/api/v1/addresses/{id}
权限: read

通过生成结果中的 ID 查询当前仍在发布的同步地址。

参数

id必填 · path · string生成或批量生成接口返回的地址 ID。

调用示例

curl "https://address.example/api/v1/addresses/pool-v2-address-id" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \

成功响应

{
  "data": {
    "address": {
      "id": "pool-v2-address-id",
      "countryCode": "US",
      "formattedAddress": "Example address"
    }
  }
}
POST/api/v1/address-translation
权限: generate

将已同步地址翻译为支持的显示语言。

参数

addressId必填 · body · stringgenerate 返回的地址 ID。
targetLocale必填 · body · string目标显示语言。

调用示例

curl -X POST "https://address.example/api/v1/address-translation" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{
  "addressId": "address-id",
  "targetLocale": "zh-CN"
}'

成功响应

{
  "data": {
    "components": {
      "street": "示例街道",
      "houseNumber": "20"
    },
    "lines": [
      "示例地址"
    ],
    "singleLine": "示例地址"
  }
}
GET/api/v1/data-health
权限: read

报告各国家同步地址池健康状态和配置错误。

参数

此接口没有请求参数。

调用示例

curl "https://address.example/api/v1/data-health" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \

成功响应

{
  "data": {
    "healthy": true,
    "countries": [
      {
        "code": "US",
        "ready": true,
        "count": 50000
      }
    ],
    "configurationErrors": []
  }
}

错误处理

400INVALID_REQUEST
401UNAUTHORIZED
404NO_POOL_COVERAGE / ADDRESS_NOT_FOUND
429RATE_LIMITED · Retry-After: 60
500 / 503INTERNAL_ERROR / SERVICE_UNAVAILABLE