How to prevent dynamic library definition from being cached?
You could trigger Drupal::service('library.discovery')-&gt;clearCachedDefinitions() every time, but that seems like a painful workaround performance-wise. All library definitions for a particular theme seem to be stored in a single cache entry library_info:$activeTheme, which doesn't allow any more finely grained invalidation.

Would the range of values of "callback" allow you to loop through them and define a separate library for each one you use, and then attach the specific one you need? The JS gets loaded on demand, so only the attached library would appear on each page.

foreach (static::CALLBACKS as $name) {
  $libraries['sample.my-lib.' . $name] = [
    //...
  ];
}


Or maybe it would be possible to call the appropriate callback from a single main function (possibly setting the callback via a drupalSettings attachment), allowing you to put a fixed value in the Google Maps API URL?