How to handle the cache per user in REST Resource?
@Leigh is right and user does exist. Cache contexts are hierarchical (see change record https://www.drupal.org/node/2451661) and user is a top level context.

So this should work (note the plural form of contexts):

  '#cache' =&gt; [
    'contexts' =&gt; ['user'],


You can also add the cache context by IDE autocompleting:

$response-&gt;getCacheableMetadata()-&gt;addCacheContexts(['user']);