Read KV metadata/check if key exists without reading value

Sometimes I want to check if a KV key exists, or read its metadata, without retrieving the actual value. I can think of two ways to do this:

  • KV.getWithMetadata(key, {type: 'stream'}) (and then ignore the stream)
  • KV.list({prefix: key, limit: 1}) (and check if the returned list has 1 item with name == key)
    I don’t really understand the internals of KV well enough to compare the two. My assumption is that the list version might be faster if it only has to query an index?

Would it make sense to add a new method to the KV runtime API for this? I know the REST API has a /metadata/{key_name} endpoint - maybe something similar could be exposed as .getMetadata(key) or .head(key)? Otherwise, if you’d rather not add more methods, a {type: boolean} option (true if value exists) for get()/getWithMetadata(), or {equals: key} option for list()?