Low-Level KV Storage
Use the built-in key-value store on ActorContext for durable string and binary data alongside actor state.
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.
Basic Usage
Keys and values default to text, so you can use strings without extra options.
Value Types
You can store binary values by passing Uint8Array or ArrayBuffer directly. Use type when reading to get the right return type.
TypeScript returns a concrete type based on the option you pass in:
Key Types
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.
Batch Operations
KV supports batch operations for efficiency. Defaults are still text for both keys and values.
API Reference
ActorContext-c.kvis available on the context