This page is an example of how to use the Tooltip module in Drupal.
To add a tooltip programmatically is basically the same as to add a tooltip in Twig directly but using of Drupal's Render API in PHP.
Cache contexts = (request) context dependencies
Cache contexts are analogous to HTTP's Vary header.
Vary