> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hapi.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Calculate a mortgage

> Calculate a mortgage based on the provided inputs.



## OpenAPI

````yaml https://api.hapi.so/openapi.json post /calculate
openapi: 3.1.0
info:
  title: h.api API
  version: 0.1.0
servers:
  - url: https://api.hapi.so/
    description: h.api
security: []
paths:
  /calculate:
    post:
      tags:
        - Mortgage Calculation
      summary: Calculate a mortgage
      description: Calculate a mortgage based on the provided inputs.
      operationId: Calculate_Mortgage_calculate_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CalculateMortgageReqDto'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CalculateMortgageResDto'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
        - APIKeyQuery: []
components:
  schemas:
    CalculateMortgageReqDto:
      properties:
        home_price:
          type: number
          exclusiveMinimum: 0
          title: Home Price
          description: The listing price of the home.
          examples:
            - 600000
        down_payment_amt:
          type: number
          exclusiveMinimum: 0
          title: Down Payment Amount
          description: >-
            The down payment amount. Use down_payment_type to specify the type
            of down payment, either percent or amount. If down_payment_type is
            set to percent, this field should be a percentage of the home price,
            e.g. 5.0. If down_payment_type is set to amount, this field should
            be the actual amount, e.g. 20000.
          examples:
            - 5
            - 20000
        down_payment_type:
          $ref: '#/components/schemas/DownPaymentTypeEnum'
          title: Down Payment Type
          description: The type of down payment - percent or amount.
          examples:
            - percent
            - amount
        state:
          type: string
          maxLength: 2
          minLength: 2
          title: State
          description: >-
            The state in which the home is located. Used to determine the
            average interest rate.
          examples:
            - CA
            - NY
        loan_term:
          type: integer
          enum:
            - 15
            - 20
            - 30
            - 40
          title: Loan Term
          description: The term length of the loan in years.
          default: 30
          examples:
            - 15
            - 20
            - 30
            - 40
        interest_rate:
          type: number
          exclusiveMinimum: 0
          title: Interest Rate
          description: >-
            The annual interest rate of the loan expressed as a percentage. Will
            return the current average rate of the given state if not provided.
          examples:
            - 6.375
        yearly_insurance:
          type: number
          exclusiveMinimum: 0
          title: Yearly Insurance
          description: The yearly cost of homeowner's insurance.
          examples:
            - 1200
        yearly_property_tax:
          type: number
          exclusiveMinimum: 0
          title: Yearly Property Tax
          description: The yearly cost of property tax.
          examples:
            - 2500
        monthly_pmi:
          type: number
          title: Monthly PMI
          description: The monthly cost of private mortgage insurance.
          examples:
            - 100
        monthly_hoa:
          type: number
          exclusiveMinimum: 0
          title: Monthly HOA
          description: The monthly cost of homeowner's association fees.
          examples:
            - 50
      type: object
      required:
        - home_price
        - down_payment_amt
        - down_payment_type
        - state
      title: CalculateMortgageReqDto
    CalculateMortgageResDto:
      properties:
        total_monthly_payment:
          type: number
          exclusiveMinimum: 0
          title: Total Monthly Payment
          description: >-
            The total monthly payment, including principal, interest, taxes,
            insurance, PMI, and HOA fees.
          examples:
            - 3500
        principal_and_interest:
          type: number
          exclusiveMinimum: 0
          title: Principal and Interest
          description: >-
            The monthly payment for principal and interest only. Does not
            include taxes, insurance, PMI, or HOA fees.
          examples:
            - 2500
        monthly_tax:
          type: number
          exclusiveMinimum: 0
          title: Monthly Tax
          description: The monthly cost of property tax.
          examples:
            - 200
        monthly_insurance:
          type: number
          exclusiveMinimum: 0
          title: Monthly Insurance
          description: The monthly cost of homeowner's insurance.
          examples:
            - 100
        monthly_pmi:
          type: number
          title: Monthly PMI
          description: >-
            The monthly cost of private mortgage insurance. Not applied if the
            down payment is 20% or more.
          examples:
            - 100
        monthly_hoa:
          type: number
          title: Monthly HOA
          description: >-
            The monthly cost of homeowner's association fees. This value will be
            the exact same as the input if provided.
          examples:
            - 50
        interest_rate:
          type: number
          exclusiveMinimum: 0
          title: Interest Rate
          description: >-
            The annual interest rate of the loan expressed as a percentage. This
            value will be the exact same as the input if provided.
          examples:
            - 6.375
        home_price:
          type: number
          exclusiveMinimum: 0
          title: Home Price
          description: >-
            The total price of the home. This value will be the exact same as
            the input if provided.
          examples:
            - 300000
        down_payment_amount:
          type: number
          exclusiveMinimum: 0
          title: Down Payment Amount
          description: The total dollar amount of the down payment.
          examples:
            - 60000
        down_payment_percent:
          type: number
          exclusiveMinimum: 0
          title: Down Payment Percent
          description: >-
            The percentage of the home price that is paid as a down payment
            expressed as a percentage.
          examples:
            - 5
        loan_amount:
          type: number
          exclusiveMinimum: 0
          title: Loan Amount
          description: The total amount of the loan.
          examples:
            - 240000
        monthly_income_needed:
          type: number
          exclusiveMinimum: 0
          title: Monthly Income Needed
          description: >-
            The monthly income needed to afford the home. This is based on a
            debt-to-income ratio of 45%.
          examples:
            - 8750
        state:
          type: string
          maxLength: 2
          minLength: 2
          title: State
          description: >-
            The state in which the home is located. Used to determine the
            average interest rate.
          examples:
            - CA
            - NY
        yearly_income_needed:
          type: number
          exclusiveMinimum: 0
          title: Yearly Income Needed
          description: >-
            The yearly income needed to afford the home. This is based on a
            debt-to-income ratio of 45%.
          examples:
            - 105000
      type: object
      required:
        - total_monthly_payment
        - principal_and_interest
        - monthly_tax
        - monthly_insurance
        - monthly_pmi
        - monthly_hoa
        - interest_rate
        - home_price
        - down_payment_amount
        - down_payment_percent
        - loan_amount
        - monthly_income_needed
        - state
        - yearly_income_needed
      title: CalculateMortgageResDto
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    DownPaymentTypeEnum:
      type: string
      enum:
        - percent
        - amount
      title: DownPaymentTypeEnum
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: x-api-key
    APIKeyQuery:
      type: apiKey
      in: query
      name: api_key

````