{
  "openapi": "3.1.0",
  "info": {
    "title": "Lendtrain Agent API",
    "version": "2.1.0",
    "description": "Structured refinance estimates and conversational guidance. Atlantic Home Mortgage, LLC dba Lendtrain. NMLS #1844873. Equal Housing Opportunity. No application submission, credit pull, rate lock, or messaging."
  },
  "servers": [
    {
      "url": "https://www.lendtrain.com"
    }
  ],
  "paths": {
    "/api/agents/quote": {
      "post": {
        "operationId": "quote",
        "summary": "Price a known refinance scenario",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuoteRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completed response. Inspect status and disclosures before presenting an estimate.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuoteResponse"
                }
              }
            }
          },
          "400": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "504": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "FHA is never returned. VA requires explicit borrower eligibility and fee status. VA rate-and-term from a non-VA or unknown loan requires officer review. 15-second upstream timeout. 10 requests/min/IP shared with site pricing. Savings require complete current-loan data and are omitted for cash-out. Costs and savings refer to parRate. Other rate choices change costs. Cash-out excludes financed closing costs. Estimates only, not underwriting approval."
      }
    },
    "/api/chat": {
      "post": {
        "operationId": "chat",
        "summary": "Ask the refinance advisor",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completed response. Inspect status and disclosures before presenting an estimate.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "$ref": "#/components/schemas/ChatStreamEvent"
                },
                "example": "data: {\"text\":\"Final answer\"}\n\ndata: [DONE]\n\n"
              }
            }
          },
          "400": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "504": {
            "description": "JSON error. Correct invalid inputs or retry temporary errors with bounded backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Defaults to SSE. Set stream:false for JSON with structured quotes. 90-second deadline. 20 requests/min/IP. Pricing calls share the 10/min/IP pricing limit. vaEligibilityConfirmed:true is required for VA. No application submission, rate lock, credit pull, or email actions."
      }
    }
  },
  "components": {
    "schemas": {
      "QuoteRequest": {
        "type": "object",
        "properties": {
          "state": {
            "type": "string",
            "enum": [
              "AL",
              "FL",
              "GA",
              "KY",
              "NC",
              "OR",
              "SC",
              "TN",
              "TX",
              "UT"
            ]
          },
          "loanBalance": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 10000000
          },
          "propertyValue": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 50000000
          },
          "creditScore": {
            "type": "integer",
            "minimum": 300,
            "maximum": 850
          },
          "occupancy": {
            "type": "string",
            "enum": [
              "primary",
              "secondHome",
              "investment"
            ]
          },
          "propertyType": {
            "type": "string",
            "enum": [
              "singleFamily",
              "condo",
              "townhouse",
              "multiUnit",
              "manufactured"
            ]
          },
          "units": {
            "type": "integer",
            "minimum": 1,
            "maximum": 4
          },
          "loanPurpose": {
            "type": "string",
            "enum": [
              "rateTermRefi",
              "cashOutRefi"
            ]
          },
          "cashOutAmount": {
            "type": "number",
            "minimum": 0,
            "maximum": 10000000
          },
          "loanTerm": {
            "anyOf": [
              {
                "type": "number",
                "const": 10
              },
              {
                "type": "number",
                "const": 15
              },
              {
                "type": "number",
                "const": 20
              },
              {
                "type": "number",
                "const": 25
              },
              {
                "type": "number",
                "const": 30
              }
            ]
          },
          "currentLoanType": {
            "type": "string",
            "enum": [
              "conventional",
              "fha",
              "va",
              "unknown"
            ]
          },
          "isVeteran": {
            "type": "boolean",
            "description": "True only when the borrower explicitly confirms VA eligibility. Otherwise false."
          },
          "currentRate": {
            "anyOf": [
              {
                "type": "number",
                "minimum": 0,
                "maximum": 30
              },
              {
                "type": "null"
              }
            ]
          },
          "currentMonthlyPayment": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 100000
              },
              {
                "type": "null"
              }
            ],
            "description": "Principal and interest only, excluding escrow and mortgage insurance."
          },
          "remainingTermMonths": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 1,
                "maximum": 480
              },
              {
                "type": "null"
              }
            ]
          },
          "currentMonthlyMip": {
            "anyOf": [
              {
                "type": "number",
                "minimum": 0,
                "maximum": 10000
              },
              {
                "type": "null"
              }
            ]
          },
          "vaFundingFeeType": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "firstTime",
                  "subsequent",
                  "exempt"
                ]
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "state",
          "loanBalance",
          "propertyValue",
          "creditScore",
          "occupancy",
          "propertyType",
          "units",
          "loanPurpose",
          "cashOutAmount",
          "loanTerm",
          "currentLoanType",
          "isVeteran",
          "currentRate",
          "currentMonthlyPayment",
          "remainingTermMonths",
          "currentMonthlyMip",
          "vaFundingFeeType"
        ],
        "additionalProperties": false
      },
      "ChatRequest": {
        "type": "object",
        "properties": {
          "messages": {
            "minItems": 1,
            "maxItems": 50,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "user",
                    "assistant"
                  ]
                },
                "content": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 10000
                }
              },
              "required": [
                "role",
                "content"
              ],
              "additionalProperties": false
            }
          },
          "stream": {
            "type": "boolean"
          },
          "vaEligibilityConfirmed": {
            "type": "boolean"
          }
        },
        "required": [
          "messages"
        ],
        "additionalProperties": false
      },
      "RateOption": {
        "type": "object",
        "properties": {
          "rate": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "apr": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "points": {
            "type": "number"
          },
          "dollarAmount": {
            "type": "number"
          },
          "monthlyPI": {
            "type": "number",
            "minimum": 0
          },
          "monthlyPayment": {
            "type": "number",
            "minimum": 0
          },
          "totalMonthlyPayment": {
            "type": "number",
            "minimum": 0
          },
          "monthlyMI": {
            "type": "number",
            "minimum": 0
          },
          "isPar": {
            "type": "boolean"
          },
          "label": {
            "type": "string"
          },
          "borrowerPaidPoints": {
            "type": "number",
            "minimum": 0,
            "description": "Borrower-paid points in dollars."
          },
          "lenderCredit": {
            "type": "number",
            "minimum": 0,
            "description": "Credit toward closing costs in dollars, not cash proceeds."
          }
        },
        "required": [
          "rate",
          "apr",
          "points",
          "dollarAmount",
          "label",
          "borrowerPaidPoints",
          "lenderCredit"
        ],
        "additionalProperties": false
      },
      "Product": {
        "type": "object",
        "properties": {
          "eligible": {
            "type": "boolean",
            "const": true
          },
          "parRate": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "apr": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "monthlyPI": {
            "type": "number",
            "minimum": 0
          },
          "totalMonthlyPayment": {
            "type": "number",
            "minimum": 0
          },
          "rateOptions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RateOption"
            }
          },
          "fullRateChain": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RateOption"
            }
          },
          "ltv": {
            "type": "number",
            "minimum": 0
          },
          "closingCosts": {
            "type": "object",
            "properties": {
              "total": {
                "type": "number",
                "minimum": 0
              },
              "lenderFees": {
                "type": "object",
                "properties": {
                  "underwriting": {
                    "type": "number",
                    "minimum": 0
                  },
                  "discountPoints": {
                    "type": "number"
                  }
                },
                "required": [
                  "underwriting",
                  "discountPoints"
                ],
                "additionalProperties": false
              },
              "thirdPartyFees": {
                "type": "object",
                "properties": {
                  "creditReport": {
                    "type": "number",
                    "minimum": 0
                  },
                  "appraisal": {
                    "type": "number",
                    "minimum": 0
                  },
                  "floodCert": {
                    "type": "number",
                    "minimum": 0
                  },
                  "taxService": {
                    "type": "number",
                    "minimum": 0
                  },
                  "subtotal": {
                    "type": "number",
                    "minimum": 0
                  }
                },
                "required": [
                  "creditReport",
                  "appraisal",
                  "floodCert",
                  "taxService",
                  "subtotal"
                ],
                "additionalProperties": false
              },
              "titleSettlement": {
                "type": "object",
                "properties": {
                  "settlementFee": {
                    "type": "number",
                    "minimum": 0
                  },
                  "titleInsurance": {
                    "type": "number",
                    "minimum": 0
                  },
                  "cpl": {
                    "type": "number",
                    "minimum": 0
                  },
                  "subtotal": {
                    "type": "number",
                    "minimum": 0
                  }
                },
                "required": [
                  "settlementFee",
                  "titleInsurance",
                  "cpl",
                  "subtotal"
                ],
                "additionalProperties": false
              },
              "governmentRecording": {
                "type": "object",
                "properties": {
                  "recordingFees": {
                    "type": "number",
                    "minimum": 0
                  },
                  "stateTaxes": {
                    "type": "number",
                    "minimum": 0
                  },
                  "subtotal": {
                    "type": "number",
                    "minimum": 0
                  }
                },
                "required": [
                  "recordingFees",
                  "stateTaxes"
                ],
                "additionalProperties": false
              },
              "productSpecific": {
                "type": "object",
                "properties": {
                  "vaFundingFee": {
                    "type": "number",
                    "minimum": 0
                  }
                },
                "additionalProperties": false
              }
            },
            "required": [
              "total",
              "lenderFees",
              "thirdPartyFees",
              "titleSettlement",
              "governmentRecording"
            ],
            "additionalProperties": false
          },
          "monthlySavings": {
            "type": "number"
          },
          "annualSavings": {
            "type": "number"
          },
          "breakevenMonths": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "totalInterestSaved": {
            "type": "number"
          },
          "conventionalMI": {
            "type": "object",
            "properties": {
              "annualRate": {
                "type": "number",
                "minimum": 0
              },
              "monthlyAmount": {
                "type": "number",
                "minimum": 0
              },
              "coveragePercent": {
                "type": "number",
                "minimum": 0
              }
            },
            "required": [
              "annualRate",
              "monthlyAmount",
              "coveragePercent"
            ],
            "additionalProperties": false
          },
          "financedFees": {
            "type": "object",
            "properties": {
              "vaFundingFee": {
                "type": "number",
                "minimum": 0
              },
              "fundingFeePercent": {
                "type": "number",
                "minimum": 0
              },
              "totalFinanced": {
                "type": "number",
                "minimum": 0
              },
              "totalLoanAmount": {
                "type": "number",
                "minimum": 0
              }
            },
            "required": [
              "totalFinanced",
              "totalLoanAmount"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "eligible",
          "parRate",
          "apr",
          "monthlyPI",
          "totalMonthlyPayment",
          "rateOptions",
          "ltv",
          "closingCosts"
        ],
        "additionalProperties": false
      },
      "IneligibleProduct": {
        "type": "object",
        "required": [
          "eligible",
          "reason"
        ],
        "properties": {
          "eligible": {
            "const": false
          },
          "reason": {
            "type": "string"
          }
        }
      },
      "QuoteResponse": {
        "type": "object",
        "required": [
          "status",
          "products",
          "recommendedProduct",
          "effectiveDate",
          "calculatedAt",
          "savingsAvailable",
          "assumptions",
          "notices",
          "disclosure",
          "nextStep"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "quoted",
              "no_eligible_products"
            ]
          },
          "products": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "conventional": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/Product"
                  },
                  {
                    "$ref": "#/components/schemas/IneligibleProduct"
                  }
                ]
              },
              "va": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/Product"
                  },
                  {
                    "$ref": "#/components/schemas/IneligibleProduct"
                  }
                ]
              }
            }
          },
          "recommendedProduct": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "conventional",
              "va",
              null
            ]
          },
          "effectiveDate": {
            "type": "string",
            "description": "Rate sheet effective date as supplied by the pricing service."
          },
          "effectiveTime": {
            "type": "string"
          },
          "calculatedAt": {
            "type": "string"
          },
          "savingsAvailable": {
            "type": "boolean"
          },
          "assumptions": {
            "type": "object",
            "properties": {
              "lockPeriodDays": {
                "const": 30
              },
              "otherClosingCostsFinanced": {
                "const": false
              },
              "requestedCashOut": {
                "type": "number"
              },
              "baseLoanAmount": {
                "type": "number"
              }
            }
          },
          "notices": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "disclosure": {
            "type": "string"
          },
          "nextStep": {
            "type": "object",
            "properties": {
              "action": {
                "const": "borrower_application"
              },
              "url": {
                "type": "string",
                "format": "uri"
              },
              "requiresBorrowerAction": {
                "const": true
              },
              "instructions": {
                "type": "string"
              }
            }
          }
        }
      },
      "ChatResponse": {
        "type": "object",
        "required": [
          "role",
          "content",
          "quotes"
        ],
        "properties": {
          "role": {
            "const": "assistant"
          },
          "content": {
            "type": "string"
          },
          "quotes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/QuoteResponse"
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error",
          "code"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string"
          }
        }
      },
      "ChatStreamEvent": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "text"
            ],
            "properties": {
              "text": {
                "type": "string"
              }
            }
          },
          {
            "$ref": "#/components/schemas/Error"
          }
        ],
        "description": "SSE data payload. Comments start with a colon. Read until the literal data: [DONE]. An error event means failure, including on HTTP 200."
      }
    }
  }
}
