openapi: 3.1.0
info:
  title: AddyIQ API
  version: 1.0.0
  description: |
    Rent, value, comps, time to rent or sell, strategy comparison and market stats for US addresses.
    Data comes from public listing sources and public records. Billed in credits; failed and
    not-covered calls are free. Use the key `aiq_test_sandbox` to try every endpoint on made-up
    sample data at no cost: its example home is "123 Example St, Sampletown, AZ 85000" (a made-up
    address), and every sandbox response carries `"sample": true` and a `notice`.
servers:
  - url: https://api.addyiq.com
security:
  - ApiKey: []
components:
  securitySchemes:
    ApiKey: { type: apiKey, in: header, name: X-Api-Key }
  parameters:
    address: { name: address, in: query, required: true, description: Full US street address with city, state and zip, schema: { type: string }, example: "123 Example St, Sampletown, AZ 85000" }
    beds: { name: beds, in: query, schema: { type: number } }
    baths: { name: baths, in: query, schema: { type: number } }
    sqft: { name: sqft, in: query, schema: { type: number } }
    yearBuilt: { name: yearBuilt, in: query, schema: { type: integer } }
    propertyType: { name: propertyType, in: query, schema: { type: string, enum: [single_family, condo, townhouse, multi_family, apartment] } }
    prices: { name: prices, in: query, description: Comma-separated prices (max 10), schema: { type: string }, example: "2400,2500,2600" }
    zip: { name: zip, in: query, schema: { type: string, pattern: '^\d{5}$' } }
    lat: { name: lat, in: query, schema: { type: number } }
    lng: { name: lng, in: query, schema: { type: number } }
    radiusMiles: { name: radiusMiles, in: query, schema: { type: number, maximum: 3.5, default: 1 } }
    limit: { name: limit, in: query, schema: { type: integer, maximum: 500, default: 25 } }
    offset: { name: offset, in: query, schema: { type: integer, default: 0 } }
  headers:
    CreditsUsed: { schema: { type: integer }, description: Credits charged for this call }
    CreditsRemaining: { schema: { type: integer }, description: Credits left on the account }
  schemas:
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code: { type: string, enum: [invalid_request, address_not_found, not_covered, insufficient_data, unauthorized, forbidden, plan_limit, insufficient_credits, rate_limited, not_found, upstream_unavailable, internal] }
            message: { type: string }
    Subject:
      type: object
      properties:
        propertyId: { type: string }
        address: { type: string }
        lat: { type: number }
        lng: { type: number }
        propertyType: { type: string }
        beds: { type: number }
        baths: { type: number }
        sqft: { type: [number, "null"] }
        yearBuilt: { type: [integer, "null"] }
        assumedFields: { type: array, items: { type: string }, description: Facts filled from nearby homes rather than records }
    Estimate:
      type: object
      properties:
        estimate: { type: number }
        low: { type: number }
        high: { type: number }
        confidence: { type: integer, minimum: 0, maximum: 100 }
        compCount: { type: integer }
        radiusMiles: { type: number }
        windowDays: { type: integer }
    TimePoint:
      type: object
      properties:
        price: { type: number }
        expectedDays: { type: integer }
        vacancyCost: { type: number }
    Listing:
      type: object
      properties:
        id: { type: string }
        type: { type: string, enum: [rental, for_sale, sold, furnished, short_term] }
        status: { type: string, enum: [active, pending, sold, leased, withdrawn] }
        address: { type: string }
        lat: { type: number }
        lng: { type: number }
        beds: { type: number }
        baths: { type: number }
        sqft: { type: [number, "null"] }
        price: { type: number }
        firstSeen: { type: string, format: date }
        lastSeen: { type: string, format: date }
        soldDate: { type: [string, "null"], format: date }
        daysListed: { type: integer }
        sourceType: { type: string, enum: [portal, property_manager, owner] }
        priceHistory: { type: array, items: { type: object, properties: { date: { type: string }, price: { type: number }, event: { type: string } } } }
        details:
          type: [object, "null"]
          properties:
            freeMonths: { type: [number, "null"] }
            leaseMonths: { type: [number, "null"] }
            petRent: { type: [number, "null"] }
            monthlyFees: { type: array, items: { type: object, properties: { name: { type: string }, amount: { type: number } } } }
            utilitiesIncluded: { type: array, items: { type: string } }
            furnished: { type: [boolean, "null"] }
            condition: { type: [integer, "null"] }
    Comp:
      allOf:
        - $ref: '#/components/schemas/Listing'
        - type: object
          properties:
            ref: { type: string, example: C1 }
            distanceMiles: { type: number }
            similarity: { type: number }
            weight: { type: number }
            adjustedPrice: { type: number }
            adjustments: { type: array, items: { type: object, properties: { label: { type: string }, amount: { type: number } } } }
  responses:
    Error:
      description: Error (no credits charged)
      content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } }
paths:
  /v1/rent-estimate:
    get:
      summary: Long-term rent estimate (1 credit)
      parameters: [{ $ref: '#/components/parameters/address' }, { $ref: '#/components/parameters/beds' }, { $ref: '#/components/parameters/baths' }, { $ref: '#/components/parameters/sqft' }, { $ref: '#/components/parameters/yearBuilt' }, { $ref: '#/components/parameters/propertyType' }]
      responses:
        '200':
          description: Rent, effective rent, true tenant cost, time to rent and explanation
          headers: { X-Credits-Used: { $ref: '#/components/headers/CreditsUsed' }, X-Credits-Remaining: { $ref: '#/components/headers/CreditsRemaining' } }
          content:
            application/json:
              schema:
                type: object
                properties:
                  subject: { $ref: '#/components/schemas/Subject' }
                  asOf: { type: string, format: date }
                  rent: { $ref: '#/components/schemas/Estimate' }
                  effectiveRent: { type: object, properties: { value: { type: number }, concessionShare: { type: number }, avgFreeMonths: { type: number }, sampleSize: { type: integer } } }
                  trueTenantCost: { type: object, properties: { value: { type: number }, fees: { type: array, items: { type: object, properties: { name: { type: string }, amount: { type: number } } } } } }
                  timeToRent: { type: array, items: { $ref: '#/components/schemas/TimePoint' } }
                  explanation: { type: [string, "null"] }
        default: { $ref: '#/components/responses/Error' }
  /v1/comps:
    get:
      summary: Comparable rentals (1 credit)
      parameters: [{ $ref: '#/components/parameters/address' }, { $ref: '#/components/parameters/beds' }, { $ref: '#/components/parameters/baths' }, { $ref: '#/components/parameters/sqft' }]
      responses:
        '200': { description: Comps with adjustments, content: { application/json: { schema: { type: object, properties: { subject: { $ref: '#/components/schemas/Subject' }, estimate: { $ref: '#/components/schemas/Estimate' }, comps: { type: array, items: { $ref: '#/components/schemas/Comp' } } } } } } }
        default: { $ref: '#/components/responses/Error' }
  /v1/time-to-rent:
    get:
      summary: Expected days to lease at given prices (1 credit)
      parameters: [{ $ref: '#/components/parameters/address' }, { $ref: '#/components/parameters/prices' }, { $ref: '#/components/parameters/beds' }]
      responses:
        '200': { description: Days at each price, content: { application/json: { schema: { type: object, properties: { estimate: { type: number }, points: { type: array, items: { $ref: '#/components/schemas/TimePoint' } } } } } } }
        default: { $ref: '#/components/responses/Error' }
  /v1/strategy:
    get:
      summary: Long-term vs. mid-term vs. short-term (2 credits)
      description: Override any assumption by name, e.g. strOccupancyPct=60, furnishingCost=20000, ltrManagementPct=0.
      parameters: [{ $ref: '#/components/parameters/address' }, { $ref: '#/components/parameters/beds' }]
      responses:
        '200': { description: Strategy lines, content: { application/json: { schema: { type: object, properties: { strategies: { type: array, items: { type: object, properties: { strategy: { type: string }, grossMonthly: { type: [number, "null"] }, netMonthly: { type: [number, "null"] }, sampleSize: { type: integer }, assumptions: { type: object } } } } } } } } }
        default: { $ref: '#/components/responses/Error' }
  /v1/value-estimate:
    get:
      summary: Sale value estimate (1 credit)
      parameters: [{ $ref: '#/components/parameters/address' }, { $ref: '#/components/parameters/beds' }, { $ref: '#/components/parameters/baths' }, { $ref: '#/components/parameters/sqft' }, { $ref: '#/components/parameters/yearBuilt' }]
      responses:
        '200': { description: Value, range, confidence, list price suggestion, content: { application/json: { schema: { type: object, properties: { subject: { $ref: '#/components/schemas/Subject' }, value: { $ref: '#/components/schemas/Estimate' }, listPriceSuggestion: { type: object, properties: { low: { type: number }, high: { type: number } } }, explanation: { type: [string, "null"] } } } } } }
        default: { $ref: '#/components/responses/Error' }
  /v1/sale-comps:
    get:
      summary: Sold and active comps with adjustments (1 credit)
      parameters: [{ $ref: '#/components/parameters/address' }, { $ref: '#/components/parameters/beds' }]
      responses:
        '200': { description: Sale comps, content: { application/json: { schema: { type: object, properties: { sold: { type: array, items: { $ref: '#/components/schemas/Comp' } }, active: { type: array, items: { $ref: '#/components/schemas/Listing' } } } } } } }
        default: { $ref: '#/components/responses/Error' }
  /v1/time-to-sell:
    get:
      summary: Expected days on market at given list prices (1 credit)
      parameters: [{ $ref: '#/components/parameters/address' }, { $ref: '#/components/parameters/prices' }]
      responses:
        '200': { description: Days at each price, content: { application/json: { schema: { type: object, properties: { estimate: { type: number }, points: { type: array, items: { $ref: '#/components/schemas/TimePoint' } } } } } } }
        default: { $ref: '#/components/responses/Error' }
  /v1/listings/rental:
    get:
      summary: Rental listings in an area (1 credit per 25 rows)
      parameters: [{ $ref: '#/components/parameters/zip' }, { $ref: '#/components/parameters/lat' }, { $ref: '#/components/parameters/lng' }, { $ref: '#/components/parameters/radiusMiles' }, { $ref: '#/components/parameters/limit' }, { $ref: '#/components/parameters/offset' }, { name: status, in: query, schema: { type: string, enum: [active, leased] } }, { name: minBeds, in: query, schema: { type: number } }, { name: maxPrice, in: query, schema: { type: number } }]
      responses:
        '200': { description: Listings, content: { application/json: { schema: { type: object, properties: { total: { type: integer }, offset: { type: integer }, limit: { type: integer }, listings: { type: array, items: { $ref: '#/components/schemas/Listing' } } } } } } }
        default: { $ref: '#/components/responses/Error' }
  /v1/listings/sale:
    get:
      summary: For-sale and recently sold listings (1 credit per 25 rows)
      parameters: [{ $ref: '#/components/parameters/zip' }, { $ref: '#/components/parameters/lat' }, { $ref: '#/components/parameters/lng' }, { $ref: '#/components/parameters/radiusMiles' }, { $ref: '#/components/parameters/limit' }, { $ref: '#/components/parameters/offset' }, { name: status, in: query, schema: { type: string, enum: [active, pending, sold] } }]
      responses:
        '200': { description: Listings, content: { application/json: { schema: { type: object, properties: { total: { type: integer }, listings: { type: array, items: { $ref: '#/components/schemas/Listing' } } } } } } }
        default: { $ref: '#/components/responses/Error' }
  /v1/markets/{zip}:
    get:
      summary: Rent and sale market stats for a zip (1 credit)
      parameters: [{ name: zip, in: path, required: true, schema: { type: string, pattern: '^\d{5}$' } }]
      responses:
        '200': { description: Market stats with sample sizes and as-of date, content: { application/json: { schema: { type: object } } } }
        default: { $ref: '#/components/responses/Error' }
  /v1/property:
    get:
      summary: Property facts, tax and sale history (1 credit)
      parameters: [{ $ref: '#/components/parameters/address' }]
      responses:
        '200': { description: Property, content: { application/json: { schema: { type: object } } } }
        default: { $ref: '#/components/responses/Error' }
  /v1/cma:
    post:
      summary: Comparative market analysis (5 credits)
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, required: [address], properties: { address: { type: string }, beds: { type: number }, baths: { type: number }, sqft: { type: number }, yearBuilt: { type: integer } } }
      responses:
        '200': { description: Sold, active and pending comps, suggested list price and narrative, content: { application/json: { schema: { type: object } } } }
        default: { $ref: '#/components/responses/Error' }
