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.
| Route | What it does | Limit per client per minute |
|---|---|---|
POST /api/lookup | One address in, one answer or one named non-answer out | 10 |
GET /api/count | Detroit's live count by class | 60 |
GET /api/cities | Daily history for all ten sources. ?source=KEY narrows it to one. | 60 |
GET /api/check?source=KEY | Five random records from one source, raw value beside our class | 5 |
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 aRetry-Afterheader. - A request of the wrong shape is refused before any upstream call, with
{"state":"refused","reason":"..."}. The reasons and their statuses are:method405,cross-site403,origin403,content-type415,too-large413,bad-body400,bad-query400,bad-source400 andno-client400. - 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-Originheader. - 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:
| Key | Holds |
|---|---|
matchedAddress | The line the Census geocoder matched, not the typed text |
class | One of lead, galvanized-requiring-replacement, unknown, non-lead |
wholeLine | The part for the whole line, or the text not-published |
utilitySide, homeSide | The 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 |
recordCount | The number of records for this home |
sourceName, sourceUrl, source | The publisher's name, its https link, and the source key |
asOf | The 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:
| State | Extra keys | Meaning |
|---|---|---|
confirm-address | choices: one line | The geocoder found a different real address. Send the same request again with confirm set to this exact line. |
more-than-one-address | choices: up to 10 lines, and choicesCut when the list was cut short | Pick one of the geocoder's own lines and send it as confirm. |
not-covered | waterSystems: up to 3, each with id and name, when EPA's layer has one | No city Aavi reads covers this address. |
could-not-confirm-utility | utilities: up to 10, each with name and publisherPage | More than one utility answered, or the Census codes were missing. |
address-not-found | none | The Census geocoder found nothing. |
no-exact-match | none | The utility's list has no record for exactly this address. |
could-not-confirm-unique-match | none | A record could not be narrowed to one home. |
source-unavailable | none | A city server failed, timed out or was refused. |
source-changed | none | The 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:
| Key | Holds |
|---|---|
key, name, publisherPage | The source key, its name and the publisher's own https page |
city, state | The city name (null for a state or county source) and the state |
status, takenAt | The latest census status and its time |
stale | True when the last good count is more than 36 hours old |
days | Up to 90 days of history, each with day, status, total and counts |
fieldsChangedOn | The days on which the field fingerprint changed |
countDrops | The 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.
The Kiro power
A Kiro power with one local MCP server and two tools, so any Kiro agent can ask Aavi what a city's record says about a home's water line.
Run it yourself
Clone the repo, install, set the environment variable names, test, build, run the command-line tools and the live proof, and deploy your own copy.