Skip to Content
AaviDocs

API

The four public routes under /api: method, input, output shape, limits and errors.

The site has exactly four routes. None needs a key or a sign-in. None behaves differently for a special caller, and no reply allows another site to read it. The code is in apps/web/app/api.

RouteWhat it doesLimit per client per minute
POST /api/lookupOne address in, one answer or one named non-answer out10
GET /api/countDetroit's live count by class60
GET /api/citiesDaily history for all ten sources. ?source=KEY narrows it to one.60
GET /api/check?source=KEYFive random records from one source, raw value beside our class5

Limits and errors that apply to every route

  • A request past the limit gets status 429, the body {"state":"refused","reason":"too-many-requests"} and a Retry-After header.
  • A request of the wrong shape is refused before any upstream call, with {"state":"refused","reason":"..."}. The reasons and their statuses are: method 405, cross-site 403, origin 403, content-type 415, too-large 413, bad-body 400, bad-query 400, bad-source 400 and no-client 400.
  • A request from a browser page on another site is refused (cross-site). Scripts and tools that send none of the browser headers pass.
  • No reply sets an Access-Control-Allow-Origin header.
  • Text from a city or from EPA leaves as a plain string with control characters dropped and a length cap.

POST /api/lookup

Input. A JSON body with address, and when you are confirming, confirm. Both are strings. The content type must be application/json, the body at most 2,048 bytes, and any other key is refused. The typed address must be 1 to 100 characters. The address travels in the body, never in the URL.

curl -s https://aavi.vercel.app/api/lookup \
  -H "content-type: application/json" \
  -d '{"address":"<street number and name, city, state ZIP>"}'

Use a public building, not someone's home.

Output. Always a JSON object with a state. There are ten states.

An answer has the state answer and these keys:

KeyHolds
matchedAddressThe line the Census geocoder matched, not the typed text
classOne of lead, galvanized-requiring-replacement, unknown, non-lead
wholeLineThe part for the whole line, or the text not-published
utilitySide, homeSideThe text not-published, or an object with a class (null when the city classifies no official part of that side) and a list of parts
recordCountThe number of records for this home
sourceName, sourceUrl, sourceThe publisher's name, its https link, and the source key
asOfThe source's own date: an object with date and basis, or the text date not published or date unavailable

A part has field (the field name the city uses), role (official or raise-only), raw (the raw value, or null) and class.

The nine non-answers carry no class:

StateExtra keysMeaning
confirm-addresschoices: one lineThe geocoder found a different real address. Send the same request again with confirm set to this exact line.
more-than-one-addresschoices: up to 10 lines, and choicesCut when the list was cut shortPick one of the geocoder's own lines and send it as confirm.
not-coveredwaterSystems: up to 3, each with id and name, when EPA's layer has oneNo city Aavi reads covers this address.
could-not-confirm-utilityutilities: up to 10, each with name and publisherPageMore than one utility answered, or the Census codes were missing.
address-not-foundnoneThe Census geocoder found nothing.
no-exact-matchnoneThe utility's list has no record for exactly this address.
could-not-confirm-unique-matchnoneA record could not be narrowed to one home.
source-unavailablenoneA city server failed, timed out or was refused.
source-changednoneThe city's field list changed, so Aavi is not answering until it is checked.

A lookup is never cached. The route's time budget is 30 seconds.

GET /api/count

Input. None. Any query string is refused.

Output. Detroit's own count by class, asked of Detroit's own server and cached for about 10 minutes.

{
  "source": "detroit",
  "name": "Detroit Water and Sewerage Department",
  "askedAt": "<time of the call to the city>",
  "asOf": "date not published",
  "total": 0,
  "counts": {
    "lead": 0,
    "galvanized-requiring-replacement": 0,
    "unknown": 0,
    "non-lead": 0
  },
  "basis": "<how the counts were made>",
  "version": "<engine version>"
}

The four counts add up to total. askedAt is the time of the call, never the record's date. A failed refresh returns {"state":"source-unavailable"} or {"state":"source-changed"} and is cached for 30 seconds at most.

GET /api/cities

Input. None, or ?source=KEY with one of the ten source keys. Any other query, a repeated key or an unknown key is refused.

Output. An object with a cities list, one entry per source, read from the store:

KeyHolds
key, name, publisherPageThe source key, its name and the publisher's own https page
city, stateThe city name (null for a state or county source) and the state
status, takenAtThe latest census status and its time
staleTrue when the last good count is more than 36 hours old
daysUp to 90 days of history, each with day, status, total and counts
fieldsChangedOnThe days on which the field fingerprint changed
countDropsThe days on which the lead or unknown count fell by more than 10 percent

The reply is cached for about 5 minutes. If the store cannot be read, the reply is {"state":"store-unavailable"} with status 503. The answer path of a lookup never reads the store.

GET /api/check

Input. ?source=KEY, required, with one of the ten source keys. The client cannot choose the records or the count.

Output. Five random records from that source. Each row carries a record id, the raw value and the class of each part, and the overall class. It carries no house number or street.

{
  "source": "<source key>",
  "asOf": "<the source's own date>",
  "rows": [
    {
      "rowId": "<record id>",
      "parts": { "wholeLine": { "raw": "<raw value>", "class": "unknown" } },
      "class": "unknown"
    }
  ]
}

A parts object holds any of wholeLine, utilitySide and homeSide. If the city fails, takes too long or has changed its fields, the reply is {"state":"source-unavailable"} or {"state":"source-changed"}. A check is never cached, and its time budget is 25 seconds.