Create kv

Creates a KV bucket and returns it.

POST /v1/kv/{bucket}

Addresshttps://api.hanzo.ai/v1/kv/{bucket}
MethodPOST
Operationpost_kv_by_bucket
AuthAuthorization: Bearer $HANZO_API_KEY

Creates a KV bucket and returns it. A bucket is keyed state on the same durable plane as the streams: each key holds up to History revisions, entries can expire by TTL, and watchers on the NATS port see every write. 409 when the org already has a bucket of that name.

Request

5 fields, body application/json (required).

FieldInTypeRequiredDescription
bucketpathstringyesBucket is the bucket's name within the org, from the path: 1–64 of [A-Za-z0-9_], no dash.
bucketbodystring—Bucket is the bucket's name within the org, from the path: 1–64 of [A-Za-z0-9_], no dash.
historybodyinteger (int64)—History is how many revisions each key keeps, 1–64.
maxValuebodyinteger (int64)—MaxValue caps one value's size in bytes.
ttlbodyinteger (int64)—TTL expires entries after this many SECONDS.

Response

StatusBodyMeaning
201kv.bucketRecordcreated
defaultproblem-detailsrefused

201 body — 4 fields.

FieldInTypeAlwaysDescription
bucketbodystring—Bucket is the bucket's name within the org.
historybodyinteger (int64)—History is how many revisions each key keeps.
ttlbodyinteger (int64)—TTL is the entry expiry in seconds; 0 means none.
valuesbodyinteger (uint64)—Values is how many values the bucket holds right now.

Failure carries the platform error shape — see Errors.

Examples

hanzo kv add <bucket>
import { Configuration, KvApi } from 'hanzoai';

const api = new KvApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.postKvByBucket({ bucket: 'bucket', bucket: "<bucket>", history: 0 });
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import KvApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = KvApi(client).post_kv_by_bucket(bucket='bucket', bucket="<bucket>", history=0)
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.KvAPI.PostKvByBucket(context.Background()).Execute()
if err != nil {
	return err
}
use hanzo_client::apis::{configuration::Configuration, kv_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = kv_api::post_kv_by_bucket(&cfg, Default::default()).await?;
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.KvApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new KvApi(client).postKvByBucket();
curl -X POST https://api.hanzo.ai/v1/kv/<bucket> \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "bucket": "<bucket>",
       "history": 0
     }'

MCP reaches kv through the kv tool, which names its 6 operations with its own verbs — this one among them, under a name only MCP declares. describe explains any of them:

curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "describe",
         "arguments": {
           "op": "get_kv"
         }
       }
     }'

KV API · All Hanzo APIs · Interactive reference

Was this page useful?