The KV Store API allows your Functions to interact with Azion’s distributed key-value storage directly from the runtime. This enables low-latency data persistence and retrieval without external API calls.

Initializing the KV client

You can initialize the KV client using the constructor or the open method:

// Using the default namespace
const kv = new Azion.KV();
// Using a specific namespace
const kv = new Azion.KV("my-namespace");
// Using the open method (async)
const kv = await Azion.KV.open("my-namespace");

Available methods

The Azion.KV class provides the following methods for data operations:

MethodDescriptionReference
put(key, value, options?)Store a key-value pairWrite key-value pairs
get(key, type?, options?)Retrieve a value by keyRead key-value pairs
getWithMetadata(key, type?, options?)Retrieve a value with its metadataRead key-value pairs
delete(key)Delete a key-value pairDelete key-value pairs

Namespace management

MethodDescription
new Azion.KV()Creates a KV instance using the default namespace
new Azion.KV(name)Creates a KV instance for the specified namespace
Azion.KV.open(name)Opens a namespace asynchronously
Azion.KV.delete(name)Deletes a namespace

Supported value types

KV Store supports the following value types:

TypeDescription
stringText data (UTF-8 encoded)
objectJSON-serializable objects (automatically stringified)
ArrayBufferBinary data
ReadableStreamStreaming data for large values

Limits

LimitValue
Key sizeUp to 512 bytes (UTF-8)
Value sizeUp to 25 MB per item
Metadata sizeUp to 1024 bytes (JSON-serialized)
Per-key write rateUp to 1 write per second to the same key
Minimum expirationTtl60 seconds
Minimum cacheTtl60 seconds

Eventual consistency

KV Store uses eventual consistency. Writes are immediately visible to other requests in the same global network location, but can take up to 60 seconds (or the value of the cacheTtl parameter) to be visible in other locations.