How to calculate or get the response time of an API?

using cypress i’m intercepting an API call and want to get how much the response time it took

cy.intercept("PATCH", "https://api.website.com/b2b2/**").as("myAPP")
cy.wait("@myAPP").then(({ request, response }) => {
    expect(response.duration).to.be.lessThan(2000)// => expected undefined to be a number or a date
    expect(response.statusCode).to.equal(200)
})