{
  "openapi": "3.1.0",
  "info": {
    "title": "PropertyInsight Property Data REST API",
    "version": "1.0.0",
    "description": "Authenticated, read-only access to authorized saved property data. These endpoints do not acquire or refresh upstream data. Availability depends on the saved record and access rights."
  },
  "servers": [
    {
      "url": "https://app.propertyinsight.ai/api/platform/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/property/search": {
      "post": {
        "summary": "DB-only property search (no vendor dispatch).",
        "operationId": "propertySearch",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "address",
                      "apn",
                      "borrower",
                      "clip",
                      "id"
                    ],
                    "default": "address",
                    "description": "Lookup type. `address`/`apn`/`borrower` run a LIKE-based search; `clip` resolves a canonical property key or legacy external key exactly; `id` resolves the internal property id exactly."
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100
                  },
                  "cursor": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Paginated property hits.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Envelope"
                }
              }
            }
          }
        }
      }
    },
    "/property/{clip}/canonical": {
      "get": {
        "summary": "Canonical overview bundle for a property.",
        "operationId": "propertyCanonical",
        "parameters": [
          {
            "name": "clip",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Canonical property key, legacy external key, or internal property id."
          }
        ],
        "responses": {
          "200": {
            "description": "Canonical overview bundle.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Envelope"
                }
              }
            }
          }
        }
      }
    },
    "/property/{clip}/{domain}": {
      "get": {
        "summary": "Read an authorized saved property domain with freshness metadata. A domain without a payload reader returns null with metadata; availability varies by saved record.",
        "operationId": "propertyDomain",
        "parameters": [
          {
            "name": "clip",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "domain",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "ownership",
                "liens",
                "taxes",
                "tax_payments",
                "valuation",
                "foreclosure",
                "property_details",
                "ownership_transfers",
                "mortgage_history",
                "current_mortgage",
                "transaction_history",
                "documents",
                "document_images",
                "risks",
                "hoa",
                "climate_risk",
                "involuntary_liens",
                "solar_pace_liens",
                "buildings",
                "site_location",
                "comparables",
                "liens_enriched",
                "ownership_transfers_market_latest",
                "avm_thv_summary",
                "propensity_heloc_score",
                "propensity_rent_score",
                "propensity_sale_score",
                "propensity_purchase_score",
                "propensity_refinance_score",
                "title_chain",
                "taxes_history",
                "valuation_history",
                "rental_valuation",
                "home_equity",
                "census_geography",
                "county_property",
                "area_profile",
                "area_schools",
                "area_sales_trend",
                "area_amenities"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Domain freshness/health wrapped in the standard envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Envelope"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ErrorBody": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "hint": {
            "type": "string"
          },
          "requiredEntitlement": {
            "type": "string"
          },
          "gatedDomains": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "upgradeHint": {
            "type": "string"
          },
          "retryAfterSeconds": {
            "type": "integer",
            "minimum": 0
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "Meta": {
        "type": "object",
        "required": [
          "requestId",
          "source",
          "vendorOpaque",
          "generatedAt",
          "freshness",
          "lastRefreshedAt"
        ],
        "properties": {
          "requestId": {
            "type": "string",
            "format": "uuid"
          },
          "source": {
            "type": "string",
            "enum": [
              "supabase_canonical"
            ]
          },
          "vendorOpaque": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "freshness": {
            "type": "object",
            "description": "Per-domain freshness state, keys are dataset-type strings, values are `fresh`/`stale`/`missing`/`error`. Empty object for endpoints that don't read canonical data.",
            "additionalProperties": {
              "type": "string"
            }
          },
          "lastRefreshedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "ISO timestamp of the most recent canonical refresh; `null` for non-canonical endpoints."
          },
          "gatedDomains": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Domains the call was refused on (entitlement gate)."
          },
          "upgradeHint": {
            "type": "string",
            "description": "Surface upgrade copy when an entitlement is the blocker."
          },
          "provenance": {
            "$ref": "#/components/schemas/SourceProvenance"
          },
          "extras": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "SourceProvenance": {
        "type": "object",
        "description": "Which class of source supplied each domain, as of when, and how much disagreement was retained. OPTIONAL and frequently absent — treat a missing block as 'not stated', never as 'single source, no conflicts'.",
        "required": [
          "policyVersion",
          "domains"
        ],
        "properties": {
          "policyVersion": {
            "type": "string",
            "description": "Opaque token for the governing source policy. Compare for equality only; it changes exactly when the policy changes."
          },
          "domains": {
            "type": "object",
            "description": "Keyed by dataset-type string.",
            "additionalProperties": {
              "$ref": "#/components/schemas/SourceProvenanceDomain"
            }
          },
          "supplemental": {
            "type": "array",
            "description": "Evidence observed AFTER the snapshot froze. Structurally separate from `domains`: these are not snapshot facts. Absent when nothing arrived late.",
            "items": {
              "type": "object",
              "required": [
                "domain",
                "sourceClass",
                "observedAt",
                "summary"
              ],
              "properties": {
                "domain": {
                  "type": "string"
                },
                "sourceClass": {
                  "$ref": "#/components/schemas/SourceClass"
                },
                "observedAt": {
                  "type": "string",
                  "format": "date-time",
                  "nullable": true
                },
                "summary": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "SourceProvenanceDomain": {
        "type": "object",
        "required": [
          "winner",
          "dataAsOf",
          "conflictCount",
          "supplementalCount"
        ],
        "properties": {
          "winner": {
            "$ref": "#/components/schemas/SourceClass"
          },
          "dataAsOf": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Latest observation time among the values actually displayed."
          },
          "conflictCount": {
            "type": "integer",
            "minimum": 0,
            "description": "Fields where two sources supplied differing valid values. Both values are retained; the configured priority decides which one is served."
          },
          "supplementalCount": {
            "type": "integer",
            "minimum": 0,
            "description": "Fields whose served value was observed after this snapshot froze."
          }
        }
      },
      "SourceClass": {
        "type": "string",
        "enum": [
          "data_provider",
          "county_assessor",
          "county_treasurer",
          "county_recorder",
          "county_gis",
          "county_official",
          "document_image",
          "derived"
        ],
        "description": "Opaque source class. Commercial sources collapse to a single `data_provider` member by design — this surface never identifies which one, and no member is reverse-mappable to a brand."
      },
      "Pagination": {
        "type": "object",
        "required": [
          "limit",
          "nextCursor"
        ],
        "properties": {
          "limit": {
            "type": "integer",
            "minimum": 1
          },
          "nextCursor": {
            "type": "string",
            "nullable": true
          },
          "totalEstimated": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "Envelope": {
        "type": "object",
        "required": [
          "data",
          "error",
          "meta"
        ],
        "properties": {
          "data": {},
          "error": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ErrorBody"
              },
              {
                "type": "null"
              }
            ]
          },
          "meta": {
            "$ref": "#/components/schemas/Meta"
          },
          "pagination": {
            "$ref": "#/components/schemas/Pagination"
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Personal/team API token (T10). Mint at /account/api-tokens."
      }
    }
  }
}