Generally, a connection is created when a user visits and that connection is maintained for the lifetime of their visit within a live session. It is not used for API calls AFAIK, as they’re plain old boring HTTP requests.
See these two pages of the docs which explain the lifecycle and different types of navigation and their affect on the connection.