openapi: 3.1.0
info:
  title: Quick Lube Data Developer API
  version: 1.0.0
  summary: Deterministic oil service specs. No scraping. No guessing.
  description: |
    Built from the real routes in quick-lube-data-backend (audit 2026-10-31),
    NOT from proposed paths. Data source: Neon Postgres
    (public.motor_oil_specs, public.filter_fitments, public.filter_year_certification).
    Search is deterministic: ambiguous engines return candidates, never a guess.
    Pricing: the credit costs in the endpoint summaries are the paid-plan
    prices. On a trial key, every chargeable call costs 1 credit, flat;
    calls listed at 0 credits stay free on every plan.
  contact:
    name: Quick Lube Data
    url: https://quicklubedata.com/docs
servers:
  - url: https://quicklube-backend.vercel.app/api/v1
    description: Production (verified in frontend BFF default + live /docs examples)
security:
  - apiKeyHeader: []
  - bearerKey: []
paths:
  /developer/years:
    get:
      operationId: listYears
      summary: Supported years (0 credits)
      responses:
        '200':
          description: Years list
          content:
            application/json:
              schema:
                type: object
                properties:
                  success: { type: boolean, example: true }
                  years: { type: array, items: { type: integer } }
        '401': { $ref: '#/components/responses/Unauthorized' }
  /developer/makes:
    get:
      operationId: listMakes
      summary: Makes for a year (0 credits)
      parameters:
        - { name: year, in: query, required: true, schema: { type: integer, minimum: 1999, maximum: 2027 }, example: 2019 }
      responses:
        '200':
          description: Makes list
          content:
            application/json:
              schema:
                type: object
                properties:
                  success: { type: boolean }
                  makes: { type: array, items: { type: string } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
  /developer/models:
    get:
      operationId: listModels
      summary: Models for year + make (0 credits)
      parameters:
        - { name: year, in: query, required: true, schema: { type: integer } }
        - { name: make, in: query, required: true, schema: { type: string }, example: Chevrolet }
      responses:
        '200':
          description: Models list
          content:
            application/json:
              schema:
                type: object
                properties:
                  success: { type: boolean }
                  models: { type: array, items: { type: string } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
  /developer/engines:
    get:
      operationId: listEngines
      summary: Engines for year + make + model (0 credits)
      parameters:
        - { name: year, in: query, required: true, schema: { type: integer } }
        - { name: make, in: query, required: true, schema: { type: string } }
        - { name: model, in: query, required: true, schema: { type: string }, example: "Silverado 1500" }
      responses:
        '200':
          description: Engines list
          content:
            application/json:
              schema:
                type: object
                properties:
                  success: { type: boolean }
                  engines: { type: array, items: { type: string } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
  /developer/search:
    get:
      operationId: searchVehicle
      summary: Deterministic natural-language resolver (1 credit)
      description: |
        Statuses: resolved, engine_required (candidates returned, no guessing),
        make_model_mismatch (verified suggestion returned), model_required,
        make_required, year_required, not_found, invalid_query (400).
      parameters:
        - { name: q, in: query, required: true, schema: { type: string, minLength: 2, maxLength: 160 }, example: "2019 Chevy Silverado 1500" }
      responses:
        '200':
          description: Resolver result; matches carry the canonical ServiceSpec when resolved
          headers:
            X-QLD-Credit-Cost: { schema: { type: integer }, description: Credits charged for this call }
            X-QLD-Credits-Remaining: { schema: { type: integer } }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/SearchResult' }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
  /developer/vehicles/service-spec:
    get:
      operationId: getServiceSpec
      summary: Canonical service spec (2 credits)
      parameters:
        - { name: year, in: query, required: true, schema: { type: integer }, example: 2019 }
        - { name: make, in: query, required: true, schema: { type: string }, example: Chevrolet }
        - { name: model, in: query, required: true, schema: { type: string }, example: "Silverado 1500" }
        - { name: engine, in: query, required: true, schema: { type: string }, example: "5.3" }
      responses:
        '200':
          description: Normalized spec. Unverified/N/A source values become null — never invented.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success: { type: boolean, example: true }
                  spec: { $ref: '#/components/schemas/ServiceSpec' }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404': { $ref: '#/components/responses/NotFound' }
  /developer/vehicles/fluids:
    get:
      operationId: getFluids
      summary: Drivetrain fluids on their own (2 credits)
      description: |
        The fluid dataset sold unbundled: automatic and manual
        transmission fluid, transfer case, and front and rear
        differential fluids for one exact vehicle and engine. The same
        values also ride inside the service spec; this endpoint serves
        them alone. Only a resolved answer charges: an unsettled engine
        answers engine_required (free), and a settled vehicle whose
        catalog row carries no fluid values answers 404 no_fluid_data
        (free).
      parameters:
        - { name: year, in: query, required: true, schema: { type: integer }, example: 2019 }
        - { name: make, in: query, required: true, schema: { type: string }, example: Chevrolet }
        - { name: model, in: query, required: true, schema: { type: string }, example: "Silverado 1500" }
        - { name: engine, in: query, required: true, schema: { type: string }, example: "5.3" }
      responses:
        '200':
          description: Normalized fluid spec, or engine_required with the engine menu. Unverified/N/A source values become null, never invented.
          headers:
            X-QLD-Credit-Cost: { schema: { type: integer }, description: Credits charged for this call }
            X-QLD-Credits-Remaining: { schema: { type: integer } }
          content:
            application/json:
              schema:
                type: object
                properties:
                  success: { type: boolean, example: true }
                  status: { type: string, example: engine_required }
                  spec: { $ref: '#/components/schemas/FluidSpec' }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404':
          description: No fluid data for that vehicle, or no verified record for that configuration
          content:
            application/json:
              example: { success: false, error: no_fluid_data, message: "No fluid data exists for that vehicle." }
  /developer/filter-years:
    get:
      operationId: listFilterYears
      summary: Certified Filter API years (0 credits)
      description: A year is exposed only at 100% certified WIX, NAPA Gold, and STP coverage for that year.
      responses:
        '200':
          description: Certified years
          content:
            application/json:
              schema:
                type: object
                properties:
                  success: { type: boolean }
                  years: { type: array, items: { type: integer } }
        '401': { $ref: '#/components/responses/Unauthorized' }
  /developer/filters:
    get:
      operationId: getFilterFitment
      summary: Oil filter cross-reference — WIX / NAPA Gold / STP (1 credit)
      parameters:
        - { name: year, in: query, required: true, schema: { type: integer }, example: 2027 }
        - { name: make, in: query, required: true, schema: { type: string }, example: Acura }
        - { name: model, in: query, required: true, schema: { type: string }, example: Mdx }
        - { name: engine, in: query, required: true, schema: { type: string }, example: "3.5" }
      responses:
        '200':
          description: Verified fitment
          content:
            application/json:
              schema:
                type: object
                properties:
                  success: { type: boolean }
                  spec: { $ref: '#/components/schemas/FilterSpec' }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404': { $ref: '#/components/responses/NotFound' }
        '422':
          description: Year not certified for the public Filter API
          content:
            application/json:
              example:
                success: false
                error: unsupported_filter_year
                message: That model year is not certified for the public Filter API.
                supportedYears: [2027, 2026, 2025, 2024, 2023]
  /developer/vin/{vin}:
    get:
      operationId: decodeVin
      summary: VIN decode plus resolved service spec and filters (3 credits)
      description: |
        The VIN is decoded server-side through NHTSA vPIC and resolved
        against the catalog. A resolved answer carries the decoded
        identity, the normalized ServiceSpec, and the FilterSpec when
        filter data exists (null when it does not). Bad calls are free:
        invalid VIN (400), decode failure (502), not found (404), and a
        200 engine_required answer with the engine menu all charge 0.
        An optional engine query parameter pins the engine exactly.
      parameters:
        - { name: vin, in: path, required: true, schema: { type: string, minLength: 17, maxLength: 17 }, example: "1HGCM82633A004352" }
        - { name: engine, in: query, required: false, schema: { type: string } }
      responses:
        '200':
          description: Resolved spec, or engine_required with the engine menu
          headers:
            X-QLD-Credit-Cost: { schema: { type: integer }, description: Credits charged for this call }
            X-QLD-Credits-Remaining: { schema: { type: integer } }
          content:
            application/json:
              schema:
                type: object
                properties:
                  success: { type: boolean }
                  status: { type: string, example: engine_required }
                  vin: { type: string }
                  decoded: { type: object }
                  vehicle: { type: object }
                  spec: { $ref: '#/components/schemas/ServiceSpec' }
                  filters: { $ref: '#/components/schemas/FilterSpec', nullable: true }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404': { $ref: '#/components/responses/NotFound' }
  /developer/vehicles/tire-fitment:
    get:
      operationId: getTireFitment
      summary: Tire and wheel fitment (2 credits)
      description: |
        Fitment data comes from the Wheel-Size provider; the catalog
        itself holds no tire data. While the provider connection is not
        enabled on the backend, this endpoint answers 503
        tire_data_not_configured and charges nothing. A resolved fitment
        charges 2 credits; an empty provider answer is 404 no_tire_data
        and charges nothing.
      parameters:
        - { name: year, in: query, required: true, schema: { type: integer }, example: 2019 }
        - { name: make, in: query, required: true, schema: { type: string }, example: Chevrolet }
        - { name: model, in: query, required: true, schema: { type: string }, example: "Silverado 1500" }
        - { name: generation, in: query, required: false, schema: { type: string } }
        - { name: modification, in: query, required: false, schema: { type: string } }
        - { name: region, in: query, required: false, schema: { type: string } }
      responses:
        '200':
          description: Resolved fitment from the Wheel-Size provider
          headers:
            X-QLD-Credit-Cost: { schema: { type: integer }, description: Credits charged for this call }
            X-QLD-Credits-Remaining: { schema: { type: integer } }
          content:
            application/json:
              schema:
                type: object
                properties:
                  success: { type: boolean, example: true }
                  vehicle: { type: object }
                  fitment: { type: array, items: { type: object } }
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404':
          description: No tire fitment data for that vehicle
          content:
            application/json:
              example: { success: false, error: no_tire_data, message: "No tire fitment data exists for that vehicle." }
        '503':
          description: Tire data connection not enabled yet
          content:
            application/json:
              example: { success: false, error: tire_data_not_configured, message: "Tire fitment is not available yet: the Wheel-Size provider connection has not been enabled on this API." }
  /api-keys:
    get:
      operationId: listApiKeys
      summary: List your API keys (user session JWT, not an API key)
      security:
        - userJwt: []
      responses:
        '200': { description: Key list (secrets never returned) }
    post:
      operationId: createApiKey
      summary: Create an API key — secret shown once. Requires an active subscription.
      security:
        - userJwt: []
      requestBody:
        required: true
        content:
          application/json:
            example: { name: "Production website", environment: live }
      responses:
        '200': { description: Created key with one-time secret }
  /api-keys/usage:
    get:
      operationId: getApiKeyUsage
      summary: Current monthly usage (user session JWT)
      security:
        - userJwt: []
      responses:
        '200': { description: Usage for the current month }
  /api-keys/{id}:
    delete:
      operationId: revokeApiKey
      summary: Revoke an API key (user session JWT)
      security:
        - userJwt: []
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      responses:
        '200': { description: Revoked }
components:
  securitySchemes:
    apiKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key
      description: "qld_live_... — shown once at creation; stored only as SHA-256 hash"
    bearerKey:
      type: http
      scheme: bearer
      description: Same API key sent as a Bearer token
    userJwt:
      type: http
      scheme: bearer
      description: Quick Lube Data user session (key management only)
  responses:
    BadRequest:
      description: Missing or invalid parameters
      content:
        application/json:
          example: { success: false, message: "Valid year, make, model, and engine are required" }
    Unauthorized:
      description: "Missing API key (verified live 2026-10-31: error api_key_required), invalid or revoked key (invalid_api_key), or credit limit exceeded (429, api_credit_limit_exceeded)"
      content:
        application/json:
          example: { success: false, error: api_key_required, message: "Provide a Quick Lube Data API key" }
    NotFound:
      description: No verified record for that configuration — returned honestly, never invented
      content:
        application/json:
          example: { success: false, message: "Vehicle specification not found" }
  schemas:
    ServiceSpec:
      type: object
      properties:
        vehicle:
          type: object
          properties:
            id: { type: string }
            year: { type: integer }
            make: { type: string }
            model: { type: string }
            engine: { type: string }
        oil:
          type: object
          properties:
            viscosity: { type: string, nullable: true, example: "0W-20" }
            capacity:
              type: object
              properties:
                display: { type: string, nullable: true, example: "7.6 qts. with filter" }
                quarts: { type: number, nullable: true }
                liters: { type: number, nullable: true }
            drainPlugTorque:
              type: object
              properties:
                display: { type: string, nullable: true, example: "18 ft. lbs." }
                ftLbs: { type: number, nullable: true }
                nm: { type: number, nullable: true }
        fluids:
          type: object
          properties:
            automaticTransmission: { type: string, nullable: true }
            manualTransmission: { type: string, nullable: true }
            transferCase: { type: string, nullable: true }
            frontDifferential: { type: string, nullable: true }
            rearDifferential: { type: string, nullable: true }
        maintenance:
          type: object
          properties:
            oilLifeResetInstructions: { type: string, nullable: true }
        dataQuality:
          type: object
          properties:
            coreOilSpecAvailable: { type: boolean }
            releaseStatusCode: { type: string }
            releaseStatus: { type: string, nullable: true }
            sourceDataset: { type: string, nullable: true }
    FluidSpec:
      type: object
      properties:
        vehicle:
          type: object
          properties:
            id: { type: string }
            year: { type: integer }
            make: { type: string }
            model: { type: string }
            engine: { type: string }
        fluids:
          type: object
          properties:
            automaticTransmission: { type: string, nullable: true }
            manualTransmission: { type: string, nullable: true }
            transferCase: { type: string, nullable: true }
            frontDifferential: { type: string, nullable: true }
            rearDifferential: { type: string, nullable: true }
        dataQuality:
          type: object
          properties:
            fluidDataAvailable: { type: boolean }
            releaseStatusCode: { type: string }
            releaseStatus: { type: string, nullable: true }
            sourceDataset: { type: string, nullable: true }
    FilterSpec:
      type: object
      properties:
        vehicle:
          type: object
          properties:
            id: { type: string }
            year: { type: integer }
            make: { type: string }
            model: { type: string }
            engine: { type: string }
        filters:
          type: object
          properties:
            wix: { type: string, nullable: true }
            napaGold: { type: string, nullable: true }
            stp: { type: string, nullable: true }
        verification:
          type: object
          properties:
            status: { type: string }
            source: { type: string, nullable: true }
            verifiedAt: { type: string, nullable: true }
    SearchResult:
      type: object
      properties:
        success: { type: boolean }
        status:
          type: string
          enum: [resolved, engine_required, make_model_mismatch, model_required, make_required, year_required, not_found, invalid_query]
        query: { type: string }
        normalized: { type: object }
        matches:
          type: array
          items: { $ref: '#/components/schemas/ServiceSpec' }
        suggestion: { type: object, nullable: true }
        options: { type: object, nullable: true }
