Library and versions that I am using :
Retrofit
version : 2.1.0
okhttp
version : 3.3.1
logging-interceptor
version : 3.3.1
This method only works within onResponse()
.
If you debug the onResponse()
, you will see the sentRequestAtMillis
& receivedResponseAtMillis
in the rawResponse
part as in the image below.
These are the parameters which hold the time in milliseconds when the request was made and when the response was received respectively.

The following example illustrates how to get the values in those parameters programmatically after response is received.
retrofitRequest.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody>
// time when the request was made to server, which you get from ```sentRequestAtMillis```
long requestTime = response.raw().sentRequestAtMillis();
// time when the response was received, which you get from ```receivedResponseAtMillis```
long responseTime = response.raw().receivedResponseAtMillis();
//time taken to receive the response after the request was sent
long apiTime = responseTime - requestTime;
}
@Override public void onFailure(Call<ResponseBody> call, Throwable t) {
}
});
Note that you may need to handle the code for any exceptions that may occur.