website/src/content/docs/actors/kv.mdx
Every Rivet Actor includes a lightweight key-value store on c.kv. It is useful for dynamic keys, blobs, or data that does not fit well in structured state.
If your data has a known schema, prefer state. KV is best for flexible or user-defined keys.
Keys and values default to text, so you can use strings without extra options.
You can store binary values by passing Uint8Array or ArrayBuffer. Use type on both reads and writes to get the right value type: binary for Uint8Array and arrayBuffer for ArrayBuffer.
TypeScript returns a concrete type based on the option you pass in:
<CodeSnippet file="examples/docs/actors-kv/typed-returns.ts" />Keys accept either string or Uint8Array. String keys are encoded as UTF-8 by default.
When listing by prefix, you can control how keys are decoded with keyType. Returned keys have the prefix removed.
If you use binary keys, set keyType: "binary" so the returned keys stay as Uint8Array.
Use listRange(start, end) to read an arbitrary half-open range [start, end). Use deleteRange(start, end) to clear that same range efficiently.
KV supports batch operations for efficiency. batchPut and batchGet work on raw Uint8Array keys and values, so encode strings before passing them in.
ActorContext - c.kv is available on the context