Skip to content

Buckets

Bucket Management

Buckets are namespaced containers for key-value pairs. Each bucket has its own configuration for expiration (TTL), size limits, and history.

Creating a Bucket

import { createClient } from "@ironflow/node";
const ironflow = createClient({ apiKey: "..." });
const kv = ironflow.kv();
// Create a bucket with optional configuration
const info = await kv.createBucket({
name: "sessions",
ttlSeconds: 3600, // Keys expire after 1 hour
history: 5, // Keep last 5 revisions of each key
});

Configuration Options

OptionTypeDefaultDescription
namestringrequiredUnique bucket name.
ttlSecondsnumber0Time-to-live for keys (0 = never expire).
historynumber1Number of historical revisions to keep per key.
maxBytesnumber-Maximum total size of the bucket in bytes.

Listing and Inspecting

// List all buckets
const buckets = await kv.listBuckets();
// Get metadata for a specific bucket
const stats = await kv.getBucketInfo("sessions");
console.log(`Bucket has ${stats.values} keys and is ${stats.bytes} bytes.`);

Deleting a Bucket

Deleting a bucket permanently removes all keys and their history. This action cannot be undone.

await kv.deleteBucket("old-cache");

Reserved Bucket Prefixes

User buckets are stored internally with an APP_ prefix (e.g. APP_sessions). Internal Ironflow buckets use a SYS_ prefix and are hidden from the KV Store dashboard and from listBuckets(). You never need to type the prefix — it is applied automatically.

PrefixOwnerVisible in dashboard
APP_User-created bucketsyes
SYS_Ironflow internals (config, secrets, circuit breakers, …)no

If you inspect NATS directly (e.g. nats kv ls), you will see the prefixed names. The SDK and API always accept and return the unprefixed name.


Atomic Operations (CAS)

Key writes support optimistic concurrency control via HTTP headers:

HeaderSemantics
If-None-Match: *Create only if the key does not exist. Returns 412 on conflict.
If-Match: <revision>Update only if the current revision matches. Returns 412 on mismatch.
(none)Unconditional put — overwrites any existing value.

The SDK exposes these as bucket.create(key, value) and bucket.update(key, value, revision). See Key Operations for examples.


HTTP API Reference

MethodPathDescription
POST/api/v1/kv/bucketsCreate a bucket.
GET/api/v1/kv/bucketsList buckets.
GET/api/v1/kv/buckets/{bucket}Get bucket info.
DELETE/api/v1/kv/buckets/{bucket}Delete a bucket.
GET/api/v1/kv/buckets/{bucket}/keysList keys (supports ?filter=).
GET/api/v1/kv/buckets/{bucket}/keys/{key}Get a value (returns ETag: <revision>).
PUT/api/v1/kv/buckets/{bucket}/keys/{key}Put / create / update (supports If-Match / If-None-Match).
DELETE/api/v1/kv/buckets/{bucket}/keys/{key}Tombstone the key (?purge=true for hard delete).
GET/api/v1/kv/buckets/{bucket}/watchWebSocket stream of KVWatchEvents.