Yes, you can. How should this API key be considered? If you need unique cache entries for each user, the cache is used only if a particular user requests the same data more than once. You can go a long way without using a caching proxy server, such as varnish, by setting the correct Cache-Control HTTP response headers (although data freshness is not checked).
There are at least two approaches to varnish:
Let your application return the HTTP-Response Vary: apikey header. It instructs any HTTP level cache (e.g. varnish) to only reuse the result of the cache if the headers of the apikey request match.
Or, more efficiently, modify the vcl_hash function in your vcl configuration to take into account the apikey header.
sub vcl_hash {set req.hash + = req.http.apikey; }
source
share