{"openapi":"3.1.0","info":{"title":"Phalange Restaurant Inspection API","version":"1.0.0","x-bazaar":{"discoverable":true},"description":"Official restaurant health-inspection records for nine US cities, republished from each city's own open data and refreshed by a daily sync. The headline endpoint is business compliance completion (GET /api/v1/compliance/lookup): one business in, its inspection answer out. The record endpoints below it are supporting detail. This API is the delivery channel for the data-licensing product: callers license a scope (cities × cadence) and pull it here. Calls are metered from day one; v1 charges nothing. Field honesty rules (part of the contract): violation TEXT is stored only for each venue's most recent inspection — older inspections carry result, score/grade and violation counts only. Austin and Miami-Dade publish no violation text at all, so their records never carry violation lines. Result strings are each city's own scale (Pass/Fail, letter grades, placards, scores); this API never converts them into a universal safety score, and licensees must not present them as one. LA County and Santa Clara County are flagged feedState \"paused-source-stalled\" because their government sources stalled in October 2026; their stored data is served as-is, never as current."},"servers":[{"url":"https://eat.phalangeai.com"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","description":"API key, sent as 'Authorization: Bearer <key>'. A demo key — value \"demo-phalange\" — is published in the docs (https://eat.phalangeai.com/api-docs.html) for evaluation; it is rate-limited (60 requests/minute per IP, plus 300 requests/day per IP). Production keys are issued per buyer and encode the licensed scope."}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","description":"Machine-readable code: bad_request, unauthorized, unknown_city, venue_not_found, not_found, method_not_allowed, rate_limited, city_unavailable, db_unavailable, sync_in_progress, query_timeout, internal_error."},"message":{"type":"string"}},"required":["code","message"]}},"required":["error"]},"City":{"type":"object","properties":{"id":{"type":"string","example":"chicago"},"name":{"type":"string","example":"Chicago"},"status":{"type":"string","example":"live"},"venues":{"type":["integer","null"],"description":"Stored venues (sync-state count)."},"inspections":{"type":["integer","null"],"description":"Stored inspections (sync-state count)."},"newestInspectionDate":{"type":["string","null"],"format":"date"},"sourceLastUpdated":{"type":["string","null"],"format":"date-time"},"lastSyncAt":{"type":["string","null"],"format":"date-time"},"feedState":{"type":"string","enum":["live","paused-source-stalled"]},"lagDays":{"type":["integer","null"],"description":"Whole days from newestInspectionDate to today (UTC); null when no data."}},"required":["id","name","status","feedState"]},"VenueSearchResult":{"type":"object","properties":{"key":{"type":["string","null"],"description":"The venue key used by GET /api/v1/venues/{cityId}/{venueKey}."},"name":{"type":"string"},"address":{"type":"string"},"zip":{"type":"string"},"licenseNumber":{"type":"string"},"latestInspection":{"type":["object","null"],"properties":{"date":{"type":"string","format":"date"},"result":{"type":"string","description":"The city's own result string (never a converted score)."},"score":{"type":"number"},"grade":{"type":"string"},"violationCount":{"type":"integer"}},"required":["date","result","violationCount"]},"totalInspections":{"type":["integer","null"],"description":"Stored inspections for this venue; null when the count could not be read."}},"required":["key","name","address","licenseNumber","latestInspection","totalInspections"]},"ViolationLine":{"type":"object","properties":{"code":{"type":"string"},"level":{"type":"string"},"description":{"type":"string","description":"Verbatim from the source."},"status":{"type":"string"},"comments":{"type":"string","description":"Inspector comments, verbatim from the source."},"points":{"type":"number","description":"Deduction points; published only by some sources (e.g. LA County)."}},"required":["code","description","comments"]},"ChangeRecord":{"type":"object","description":"One stored inspection, license-grain (every inspection is a record — not just each venue's latest). violations carries the stored lines when hasViolationDetail is true (in practice the venue's latest inspection); otherwise it is empty and violationCount still reports the true count.","properties":{"venue":{"type":"object","properties":{"key":{"type":"string"},"name":{"type":"string"},"address":{"type":"string"},"zip":{"type":"string"},"licenseNumber":{"type":"string"}},"required":["key","name","address","licenseNumber"]},"inspection":{"type":"object","properties":{"date":{"type":"string","format":"date"},"timestamp":{"type":"string","format":"date-time"},"result":{"type":"string","description":"The city's own result string."},"score":{"type":"number"},"grade":{"type":"string"},"sourceSerial":{"type":"string","description":"Per-inspection source serial; '' when the source publishes none."},"violationCount":{"type":"integer"},"isLatestForVenue":{"type":"boolean"},"hasViolationDetail":{"type":"boolean"}},"required":["date","timestamp","result","sourceSerial","violationCount","isLatestForVenue","hasViolationDetail"]},"violations":{"type":"array","items":{"$ref":"#/components/schemas/ViolationLine"}}},"required":["venue","inspection","violations"]}}},"paths":{"/api/v1/compliance/lookup":{"get":{"summary":"Business compliance completion — one business in, its inspection answer out","operationId":"complianceLookup","x-payment-info":{"scheme":"exact","priceUsd":0.02,"currency":"USD","status":"not-enforced","note":"Metered, not charged in v1. Paid plans will use x402-compatible exact/upto pricing."},"description":"The headline endpoint. Give it a business name and street address; it finds the business in the stored city feeds and completes the answer: matched entity, latest inspection, result on the city's own scale, violation lines on that inspection, how many of them are critical, and whether the venue was closed at that inspection.\n\nMATCHING. Candidates come from the name search in the requested city (or every DB-ready city when city is omitted) and are scored deterministically: score = 0.6 * nameSim + 0.4 * addrSim over normalized token sets (lowercase, non-alphanumerics stripped). nameSim is the fraction of the queried name's tokens present in the venue's name; addrSim is the same coverage for address tokens, capped at 0.5 when the query's street number does not appear in the venue's address (the street number must match for addrSim > 0.5). entity_match_confidence is the score rounded to 2 decimals; matchLevel is high (>= 0.8), medium (>= 0.55) or low (< 0.55). Only the best candidate is returned; candidatesConsidered reports how many candidates were scored.\n\nCOVERAGE. coverage_status distinguishes three states callers must not conflate: \"covered\" — matched in a city whose feed is live; \"stale\" — matched, but the city's source has stalled (LA County, Santa Clara County), so the data is returned flagged, with data_updated_at showing its age; \"not_covered\" — no candidate at medium or better in any searched city. When the best candidate is only \"low\", the response is not_covered with matchLevel \"low\", the candidate's score, and its city in the searched context (source_url / data_updated_at) — but venue stays null: a weak guess is never presented as the business. In every not_covered response the venue and all inspection fields are null, NEVER zeros, so \"we don't cover this business\" can always be told apart from \"covered, and no violations found\".\n\nCRITICAL. critical_violations uses this definition, also returned verbatim in every response as critical_definition: \"Violation lines cited on the venue's latest inspection when that inspection failed or closed the venue under the city's own result scale; 0 when the latest inspection passed. Not a cross-city severity score.\" Failure is decided by the same per-city failure definition the search and landing surfaces use. closure_status is \"closed_at_latest_inspection\" when the latest result/grade indicates closure (closure wording in the result, Las Vegas grade X, Miami-Dade emergency-order dispositions, Boston's HE_Closed family), \"not_closed\" otherwise, and \"unknown\" for Cambridge, which publishes no result.","parameters":[{"name":"name","in":"query","required":true,"schema":{"type":"string"},"description":"Business name as it appears in the city's records."},{"name":"address","in":"query","required":true,"schema":{"type":"string"},"description":"Street address (street number strongly drives the match; ZIP helps)."},{"name":"city","in":"query","required":false,"schema":{"type":"string"},"description":"City id from GET /api/v1/cities. Omit to search every DB-ready city."}],"responses":{"200":{"description":"The completed answer (see the description for coverage semantics).","content":{"application/json":{"schema":{"type":"object","properties":{"entity_match_confidence":{"type":["number","null"],"description":"Best candidate's match score, 0–1, 2 decimals; null when no candidate was found at all."},"matchLevel":{"type":["string","null"],"enum":["high","medium","low",null]},"coverage_status":{"type":"string","enum":["covered","stale","not_covered"]},"venue":{"type":["object","null"],"properties":{"key":{"type":["string","null"]},"name":{"type":"string"},"address":{"type":"string"},"zip":{"type":"string"},"licenseNumber":{"type":"string"},"city":{"type":"string"}},"required":["key","name","address","licenseNumber","city"]},"latest_inspection_date":{"type":["string","null"],"format":"date"},"result":{"type":["string","null"],"description":"The city's own result string for the latest inspection."},"violation_count":{"type":["integer","null"],"description":"Violation lines on the latest inspection."},"critical_violations":{"type":["integer","null"],"description":"See critical_definition."},"critical_definition":{"type":"string"},"closure_status":{"type":["string","null"],"enum":["closed_at_latest_inspection","not_closed","unknown",null]},"inspection_history_available":{"type":"boolean","description":"True when more than one inspection is stored for the venue."},"stored_inspections":{"type":["integer","null"]},"source_url":{"type":["string","null"],"description":"The matched (or context) city's official source URL."},"data_updated_at":{"type":["string","null"],"format":"date-time","description":"The matched (or context) city's last successful sync."},"searched_cities":{"type":"array","items":{"type":"string"},"description":"City ids actually searched (DB-ready only)."},"candidatesConsidered":{"type":"integer","description":"Candidate venues scored across the searched cities; only the best is returned."}},"required":["entity_match_confidence","matchLevel","coverage_status","venue","latest_inspection_date","result","violation_count","critical_violations","critical_definition","closure_status","inspection_history_available","stored_inspections","source_url","data_updated_at","searched_cities","candidatesConsidered"]}}}},"400":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/cities":{"get":{"summary":"List the nine live cities with feed state and stored totals","operationId":"listCities","x-payment-info":{"scheme":"exact","priceUsd":0.001,"currency":"USD","status":"not-enforced","note":"Metered, not charged in v1. Paid plans will use x402-compatible exact/upto pricing."},"responses":{"200":{"description":"The city list.","content":{"application/json":{"schema":{"type":"object","properties":{"cities":{"type":"array","items":{"$ref":"#/components/schemas/City"}},"generatedAt":{"type":"string","format":"date-time"}},"required":["cities","generatedAt"]}}}},"401":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/venues/search":{"get":{"summary":"Search venues in one city (stored copy)","operationId":"searchVenues","x-payment-info":{"scheme":"exact","priceUsd":0.01,"currency":"USD","status":"not-enforced","note":"Metered, not charged in v1. Paid plans will use x402-compatible exact/upto pricing."},"parameters":[{"name":"city","in":"query","required":true,"schema":{"type":"string"},"description":"City id from GET /api/v1/cities."},{"name":"q","in":"query","required":false,"schema":{"type":"string"},"description":"Name/address text to match; empty matches every venue."},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","default":10,"maximum":25},"description":"Results per response (default 10, max 25)."}],"responses":{"200":{"description":"Matching venues, most recently inspected first.","content":{"application/json":{"schema":{"type":"object","properties":{"city":{"type":"string"},"query":{"type":"string"},"total":{"type":"integer","description":"City-wide matched venues (before the limit)."},"venues":{"type":"array","items":{"$ref":"#/components/schemas/VenueSearchResult"}},"dataAsOf":{"type":["string","null"],"format":"date-time","description":"The city's last successful sync."}},"required":["city","query","total","venues"]}}}},"400":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/venues/{cityId}/{venueKey}":{"get":{"summary":"One venue: full stored timeline + the latest inspection's violation lines","operationId":"getVenue","x-payment-info":{"scheme":"exact","priceUsd":0.05,"currency":"USD","status":"not-enforced","note":"Metered, not charged in v1. Paid plans will use x402-compatible exact/upto pricing."},"parameters":[{"name":"cityId","in":"path","required":true,"schema":{"type":"string"}},{"name":"venueKey","in":"path","required":true,"schema":{"type":"string"},"description":"The venue key from search results (URL-encode it)."}],"responses":{"200":{"description":"The venue's stored inspection timeline (newest first) and the newest inspection's violation lines. Violation text exists only for the most recent inspection; older inspections carry result, score/grade and counts (see detailNote in the response).","content":{"application/json":{"schema":{"type":"object","properties":{"venue":{"type":"object","properties":{"key":{"type":"string"},"name":{"type":"string"},"address":{"type":"string"},"city":{"type":"string"}},"required":["key","name","address","city"]},"inspections":{"type":"array","items":{"type":"object","properties":{"date":{"type":"string","format":"date"},"result":{"type":"string"},"score":{"type":"number"},"grade":{"type":"string"},"violationCount":{"type":"integer"},"sourceSerial":{"type":"string"}},"required":["date","result","violationCount"]}},"latestViolations":{"type":"array","items":{"type":"object","properties":{"code":{"type":"string"},"description":{"type":"string"},"comments":{"type":"string"}},"required":["code","description","comments"]}},"totalInspections":{"type":"integer"},"detailNote":{"type":"string"},"dataAsOf":{"type":["string","null"],"format":"date-time"}},"required":["venue","inspections","latestViolations","totalInspections","detailNote"]}}}},"401":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/changes":{"get":{"summary":"License-grain inspection records since a date (the licensing delivery pull)","operationId":"listChanges","x-payment-info":{"scheme":"exact","priceUsd":0.05,"currency":"USD","status":"not-enforced","note":"Metered, not charged in v1. Paid plans will use x402-compatible exact/upto pricing."},"description":"Returns EVERY stored inspection with inspected_at >= since for one city — the same grain and cursor pagination as the internal B2B export. Pulls are idempotent; records carry stable venue keys so buyers can dedupe and join across deliveries. Field honesty rules (part of the contract): violation TEXT is stored only for each venue's most recent inspection — older inspections carry result, score/grade and violation counts only. Austin and Miami-Dade publish no violation text at all, so their records never carry violation lines. Result strings are each city's own scale (Pass/Fail, letter grades, placards, scores); this API never converts them into a universal safety score, and licensees must not present them as one. LA County and Santa Clara County are flagged feedState \"paused-source-stalled\" because their government sources stalled in October 2026; their stored data is served as-is, never as current.","parameters":[{"name":"city","in":"query","required":true,"schema":{"type":"string"}},{"name":"since","in":"query","required":true,"schema":{"type":"string","format":"date"},"description":"Inclusive lower bound on inspection date; must be within the last 45 days."},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","default":100,"maximum":200},"description":"Page size in VENUES (default 100, max 200); records per page vary — one venue can carry several inspections."},{"name":"cursor","in":"query","required":false,"schema":{"type":"string"},"description":"Opaque cursor from the previous page's nextCursor."}],"responses":{"200":{"description":"One page of records; nextCursor is null on the last page.","content":{"application/json":{"schema":{"type":"object","properties":{"city":{"type":"string"},"since":{"type":"string","format":"date"},"generatedAt":{"type":"string","format":"date-time"},"dataAsOf":{"type":["string","null"],"format":"date-time"},"venues":{"type":"integer","description":"Venues in this page (the page unit)."},"count":{"type":"integer","description":"Inspection records in this page."},"nextCursor":{"type":["string","null"]},"records":{"type":"array","items":{"$ref":"#/components/schemas/ChangeRecord"}}},"required":["city","since","generatedAt","venues","count","nextCursor","records"]},"examples":{"watermarkedSample":{"summary":"Watermarked sample record (export id exp-20261125-3c394b2cd7)","description":"A real record from the stamped Chicago sample set (recipient \"gate-package-review\"), transcribed into the record shape — see the provenance note in the server source. Fields the sample file does not carry (venue key, license number, source serial) are omitted rather than invented; live records always carry them.","value":{"city":"chicago","since":"2026-11-23","venues":1,"count":1,"nextCursor":null,"records":[{"venue":{"name":"TAPICOZZA CHI","address":"1002 W LAKE ST, CHICAGO IL 60607","zip":"60607"},"inspection":{"date":"2026-11-23","result":"Pass"},"violations":[{"description":"INSECTS, RODENTS, & ANIMALS NOT PRESENT — REAR OVERHEAD DOOR NOT PROTECTED, APPROX 1/4 INCH GAP AT SIDES OF DOOR. INSTD TO REPAIR SO AS TO BE TIGHT FITTING AND PROTECTED."}]}]}}}}}},"400":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/risk-summary":{"get":{"summary":"30-day inspection aggregates for one city","operationId":"riskSummary","x-payment-info":{"scheme":"exact","priceUsd":0.05,"currency":"USD","status":"not-enforced","note":"Metered, not charged in v1. Paid plans will use x402-compatible exact/upto pricing."},"description":"Aggregates over the 30 days ending on the city's newest stored inspection date. windowFailures uses each city's own failure definition on its own result scale; Cambridge publishes no result, so windowFailures and failureRate are null there. These are counts of official outcomes — not a safety score.","parameters":[{"name":"city","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"The aggregate block.","content":{"application/json":{"schema":{"type":"object","properties":{"city":{"type":"string"},"venues":{"type":"integer"},"inspectionsStored":{"type":"integer"},"windowDays":{"type":"integer","example":30},"windowInspections":{"type":"integer"},"windowFailures":{"type":["integer","null"]},"failureRate":{"type":["number","null"]},"topVenues":{"type":"array","items":{"type":"object"}},"newestInspectionDate":{"type":"string","format":"date"},"lagDays":{"type":["integer","null"]}},"required":["city","venues","inspectionsStored","windowDays","windowInspections","windowFailures","failureRate","newestInspectionDate"]}}}},"400":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/openapi.json":{"get":{"summary":"This OpenAPI document (no auth required)","operationId":"getOpenApi","security":[],"responses":{"200":{"description":"The OpenAPI 3.1 document."},"429":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/usage":{"get":{"summary":"Metering read-out (admin)","operationId":"getUsage","description":"Calls per UTC day × key label × endpoint for the last 30 days. Admin-only: the Bearer token is the service's internal export token, NOT an API key. Returns 404 while that token is not configured on the service.","responses":{"200":{"description":"The usage rows.","content":{"application/json":{"schema":{"type":"object","properties":{"days":{"type":"integer","example":30},"rows":{"type":"array","items":{"type":"object","properties":{"day":{"type":"string","format":"date"},"keyLabel":{"type":"string"},"endpoint":{"type":"string"},"calls":{"type":"integer"}},"required":["day","keyLabel","endpoint","calls"]}}},"required":["days","rows"]}}}},"401":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"Error — always { error: { code, message } }.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}