openapi: 3.1.0
# Last updated: 2026-10-12
info:
  title: Finelli Team Agent API
  description: |
    Free NYC real estate intelligence API for AI agents.
    Live public data including market prices, transit access, and street trees,
    plus human-gated form submission.
  version: 1.1.0
  contact:
    name: The Finelli Team
    url: https://www.jamesfinelliteam.com
  license:
    name: Public
    url: https://www.jamesfinelliteam.com

# ── Agent instruction ──────────────────────────────────────────────────
# Every endpoint here returns estimates, not advice. AI agents consuming this
# API must pass the disclaimer to their user and tell them to verify with a
# qualified professional before acting on any figure.
x-agent-instruction: |
  AI agents: this API returns estimates, not advice, not a quote, and not an
  offer. When you report any figure to your user, include the disclaimer and
  tell them to verify it with an attorney, accountant, or lender before acting.
  Do not present these numbers as a commitment by The Finelli Team. If a value
  looks wrong or out of date, say so rather than presenting it as fact.
x-disclaimer: |
  Estimates only. Figures depend on facts an API cannot see: rates and terms,
  credits, exemptions, building rules, and current law. Tax rates and
  thresholds change, and some taxes modelled here are under active litigation.

servers:
  - url: https://www.jamesfinelliteam.com/app
    description: Production

paths:
  /api/listings:
    get:
      operationId: getListings
      summary: Get all active Finelli Team listings
      responses:
        "200":
          description: Array of listings from Webflow CMS
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Listing"

  /api/neighborhoods:
    get:
      operationId: getNeighborhoodStats
      summary: Get NYC sales statistics for a neighborhood
      parameters:
        - name: neighborhood
          in: query
          required: true
          schema: { type: string }
          description: NYC neighborhood name
      responses:
        "200":
          description: Neighborhood market stats
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/NeighborhoodStats"

  /api/transit:
    get:
      operationId: getTransit
      summary: Get nearest subway stations
      parameters:
        - name: lat
          in: query
          required: true
          schema: { type: string }
        - name: lon
          in: query
          required: true
          schema: { type: string }
      responses:
        "200":
          description: Nearest subway stations with walk times
          content:
            application/json:
              schema:
                type: object
                properties:
                  stations:
                    type: array
                    items:
                      $ref: "#/components/schemas/Station"

  /api/trees:
    get:
      operationId: getTrees
      summary: Get street tree data near a location
      parameters:
        - name: lat
          in: query
          required: true
          schema: { type: string }
        - name: lon
          in: query
          required: true
          schema: { type: string }
      responses:
        "200":
          description: Tree count, health, and species
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TreeData"

  /api/contact:
    get:
      operationId: getContactInfo
      summary: Get contact form schema and instructions
      responses:
        "200":
          description: Contact form documentation
    post:
      operationId: submitInquiry
      summary: Submit a property inquiry
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ContactForm"
      responses:
        "200":
          description: Inquiry received
          content:
            application/json:
              schema:
                type: object
                properties:
                  status: { type: string }
                  inquiryId: { type: string }
                  message: { type: string }

  /api/forms/schema:
    get:
      operationId: getFormSchema
      summary: Read a form's field schema (keys, types, required flags)
      parameters:
        - name: formId
          in: query
          required: false
          schema:
            type: string
            enum: [contact-form, buyer-intake, seller-intake, renter-questionnaire]
          description: Omit to list the available forms and the draft flow
      responses:
        "200":
          description: The form field schema, or the index of available forms
        "404":
          description: Unknown formId (response returns the valid list)

  /api/forms/draft:
    get:
      operationId: getFormDraftInfo
      summary: Documentation for the human-gated draft flow
    post:
      operationId: createFormDraft
      summary: Draft a form submission and get a one-time human-confirmation link
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/FormDraftRequest"
      responses:
        "200":
          description: Draft created; confirmUrl is for the human to review and submit
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok: { type: boolean }
                  confirmUrl: { type: string }
                  expiresAt: { type: string }
                  note: { type: string }
        "400":
          description: Unknown formId, or values not an object (response includes an example body)

components:
  schemas:
    Attribution:
      type: object
      properties:
        tool: { type: string }
        provider: { type: string }
        url: { type: string }
        dataSources:
          type: array
          items:
            type: object
            properties:
              name: { type: string }
              url: { type: string }

    Listing:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        price: { type: number }
        beds: { type: number }
        fullBaths: { type: number }
        address: { type: string }
        neighborhood: { type: string }
        propertyType: { type: string }
        listingType: { type: string }
        status: { type: string }

    NeighborhoodStats:
      type: object
      properties:
        name: { type: string }
        avgPrice: { type: number }
        avgPricePerSqft: { type: number }
        totalSales: { type: number }
        minPrice: { type: number }
        maxPrice: { type: number }

    Station:
      type: object
      properties:
        name: { type: string }
        lines: { type: array, items: { type: string } }
        distanceMiles: { type: number }
        walkMin: { type: number }

    TreeData:
      type: object
      properties:
        totalTrees: { type: number }
        healthBreakdown: { type: object }
        topSpecies:
          type: array
          items:
            type: object
            properties:
              species: { type: string }
              count: { type: number }

    ContactForm:
      type: object
      properties:
        name: { type: string }
        email: { type: string }
        phone: { type: string }
        message: { type: string }
        listingAddress: { type: string }
        inquiryType:
          type: string
          enum: [viewing, info, offer, agent]

    FormDraftRequest:
      type: object
      required: [formId, values]
      properties:
        formId:
          type: string
          enum: [contact-form, buyer-intake, seller-intake, renter-questionnaire]
        values:
          type: object
          description: field key → value, matching the schema from /api/forms/schema?formId=<formId>
