When you request tokens the access_token is good for 1200 seconds or 20 minutes. Once that expires you now have to use the refresh_token to request a new access_token which is then good for another 20 minutes.
Getting started I’d look over all the resources on Tips for a developer starting out with ESI!