Store key/value state
A disk can hold several KV namespaces. Namespaces are created on first use and separate their keys from other namespaces and file paths. Namespace names use 1-128 ASCII letters, digits, underscores or hyphens.
Read and write in JavaScript
Section titled “Read and write in JavaScript”const app = kv.namespace('app');await app.put('theme', 'dark');await app.put('retries', 3);await app.put('feature', {enabled:true});await app.put('binary', new Uint8Array([0, 255]));
const theme = await app.get('theme');const missing = await app.get('missing'); // undefinedconst present = await app.exists('feature');await app.delete('theme');Strings store text, Uint8Array stores bytes, and other JSON-compatible values store JSON. Stored JSON null differs from a missing key. Keys accept strings or Uint8Array; numeric identifiers need explicit encoding such as String(id).
Use HTTP
Section titled “Use HTTP”curl --fail-with-body "https://api.wabe.sh/v1/disks/demo/kv/app" \ -H "Authorization: Bearer YOUR_PROJECT_API_KEY" \ --json '{"op":"put","key":"feature","value":{"type":"json","value":{"enabled":true}}}'Every operation uses the same endpoint and an op field. The KV HTTP reference defines typed values, binary keys and responses.
Scan a prefix
Section titled “Scan a prefix”const users = kv.namespace('users');let after;for await (const entry of users.scan({prefix:'team:', limit:100})) { print(entry.key, JSON.stringify(entry.value)); after = entry.key;}return {after};Use the last returned key as the exclusive after cursor on the next request. Keys sort by bytes. reverse:true reverses the order. The cursor must share the prefix. Separate paginated requests can observe intervening writes; they do not share a pinned snapshot.
A scan stays inside its namespace. Filtering its output searches the selected namespace’s values; the current API has no value index or full-text query operator.
Publish related changes together
Section titled “Publish related changes together”const jobs = kv.namespace('jobs');await jobs.batch([ {op:'put', key:'42:result', value:{files:3}}, {op:'put', key:'42:status', value:'done'}, {op:'delete', key:'42:pending'},]);A batch publishes all its put/delete mutations atomically in one namespace. It cannot include files, other namespaces, conditional reads or a transaction callback. Repeated mutations of one key apply in order.
Limits and persistence
Section titled “Limits and persistence”Keys are limited to 16 KiB, and values to 1 MiB of stored payload. Atomic batches have an 8 MiB encoded mutation limit. JS invocations also share an 8 MiB budget across retained KV values, incoming KV buffers and open batches. A quota error aborts the high-level batch; it does not publish part of it.
Default writes acknowledge RAM publication. Background or explicit flush persists them. KV operations never request a flush themselves. The optional remote durability mode waits for persistence. Typed KV does not expose TTL, counters, sets, indexes or CAS. The separate Redis keyspace provides counters, logical expiration, conditional writes, lists, hashes, sets and sorted sets.