SDK reference for @zindexzero/sdk
The complete API for building on Zero — chat, your own private knowledge base, browser/mobile clients, the React hook, and the account control plane. Zero dependencies, fully typed. Every signature below matches the shipped package.
Install
Node 18+ or any modern browser. It's pure ESM with no dependencies.
npm i @zindexzero/sdkIn the browser you can skip the install and import from a CDN — https://esm.sh/@zindexzero/sdk (see Browser & mobile).
Get a key
There is no anonymous access — the SDK does nothing without a key, and keys come only from us. Sign up at zindexzero.org/start, and once approved you issue keys from your account. New keys start disabled.
| Field | Type | Description |
|---|---|---|
| ziz_live_… | secret | Server only. Full surface: chat + knowledge base + premium routing. |
| ziz_pub_… | publishable | Safe to ship in a browser/mobile bundle. Chat only, origin-locked, quota-fenced. |
| ZizHosted | proxy | Full surface in an untrusted app — we hold your secret server-side (see Browser & mobile). |
chat()
The core call. Pass a string, or a turn with inline attachments, plus optional prior turns. Returns the reply and metadata.
import { Ziz } from "@zindexzero/sdk";
const ziz = new Ziz({ apiKey: process.env.ZIZ_KEY! }); // ziz_live_…
// simplest form
const { text } = await ziz.chat("Summarize this contract");
// full turn: media (vision keys) + prior turns
const res = await ziz.chat(
{ text: "What's in this?", attachments: [{ type: "image", format: "png", data: b64 }] },
[{ role: "user", text: "earlier message" }],
);
console.log(res.modelId, res.escalated, res.usage);Response
| Field | Type | Description |
|---|---|---|
| text | string | The assistant's reply, as markdown. |
| modelId | string | The Bedrock model actually used for this turn. |
| escalated | boolean | True when the turn ran on a premium brain (Sonnet/Opus). |
| usage | { inputTokens, outputTokens } | Token counts for this call — never a dollar figure. |
| retrieved? | number | Count of your own KB chunks used. Present only on RAG-enabled keys. |
| searched? | true | Present only when the web-search tool ran (first-party keys). |
| sources? | { title, url }[] | Deduped https-only web sources, when a search returned results. |
usage is token counts only — never cost. Your dollar figure (already +20% marked up) comes from account.usage().
Knowledge base (RAG)
On a secret, RAG-enabled key, upload your own documents; chat then answers only from your tenant's content. Everything is credential-isolated — retrieval can never cross into another tenant's data.
// add text or a base64 file (pdf/docx/csv/xlsx/html/txt/md)
await ziz.docs.add({ text: "Internal policy…", title: "Policy" });
await ziz.docs.add({ file: { data: b64, format: "pdf", name: "handbook.pdf" } });
// list + delete
const { documents } = await ziz.docs.list(); // [{ docId, title, format, createdAt, chunks }]
await ziz.docs.delete(documents[0].docId);Browser & mobile
An untrusted app must never hold a ziz_live_ secret. Two safe options:
1 · Publishable key (chat only)
import { Ziz } from "@zindexzero/sdk";
const ziz = new Ziz({ apiKey: "ziz_pub_…" }); // safe to ship; locked to your origins
const { text } = await ziz.chat("Hello");2 · Hosted proxy (full surface)
ZiZ holds your secret server-side; your app calls the proxy by its registered slug. The browser's Origin is the gate; native apps add an app-token.
import { ZizHosted } from "@zindexzero/sdk";
const zh = new ZizHosted({ client: "acme" }); // browser: Origin is the gate
// const zh = new ZizHosted({ client: "acme", appToken: "hat_…" }); // native
const { text } = await zh.chat("Summarize my docs");
await zh.docs.add({ text: "Internal note…", title: "note" });From a CDN
<script type="module">
import { ZizHosted } from "https://esm.sh/@zindexzero/sdk";
const zh = new ZizHosted({ client: "acme" });
console.log(await zh.chat("hi"));
</script>React & React Native
useZero manages chat state — messages, send, status — for any client (Ziz, ZizHosted). React is a peer dependency.
import { useMemo } from "react";
import { ZizHosted } from "@zindexzero/sdk";
import { useZero } from "@zindexzero/sdk/react";
function Chat() {
const client = useMemo(() => new ZizHosted({ client: "acme" }), []);
const { messages, send, status, error, reset } = useZero(client);
// render messages; call send(text) on submit; status: "idle" | "sending"
}Control plane (server only)
Sign in with your ZiZ account to manage keys, features, personas, caps, usage, and your style profile — no dashboard required. This holds account credentials; never ship it in a browser bundle.
import { signIn } from "@zindexzero/sdk";
const account = await signIn({ email: process.env.ZIZ_EMAIL!, password: process.env.ZIZ_PW! });
const { keys } = await account.keys.list();
const { key } = await account.keys.create({ kind: "secret", label: "prod server" });
await account.keys.setFeature(key, { smart: true, vision: true });
await account.keys.setPersona(key, "You are Acme's warm, concise support agent.");
const { totalCostUsd } = await account.usage(); // +20% marked up server-side| Field | Type | Description |
|---|---|---|
| keys.list() | → { keys, provisioned? } | All your keys. First call may include raw starter keys, shown once. |
| keys.create(opts) | → { key, view } | Mint a key. Raw key returned once — store it now. { kind: "secret" | "public", origins?, label? }. |
| keys.enable / disable / revoke | (keyId) | Flip a key on/off, or permanently kill it. |
| keys.addOrigin / removeOrigin | (keyId, origin) | Manage a public key's locked origins. |
| keys.setFeature(keyId, flags) | { smart, vision, max, learn } | Toggle premium routing per secret key. |
| keys.setPersona / clearPersona | (keyId, persona) | Set the assistant role/voice ("" clears). Fenced as data — can't override safety. |
| caps.request(keyId, n, reason?) | → request | Ask an admin to raise a cap (clients can't self-raise). |
| usage() | → { totalCostUsd, keys[] } | This month's cost, already +20% marked up server-side. |
| profile.get / set / clear | (style) | Read/edit/clear the tenant's learned style guide. |
Type reference
ZizKeyView
A key as the control plane exposes it — never the raw key or its hash.
| Field | Type | Description |
|---|---|---|
| keyId | string | Stable id used to manage the key. Never the raw key or its hash. |
| kind | "secret" | "public" | Secret = server; public = origin-locked browser widget. |
| status | "active" | "disabled" | Disabled keys return 403 on every call. |
| allowedOrigins | string[] | Origins a public key is locked to (empty for secret keys). |
| quota / quotaUsed | number | null | Monthly request cap and current usage. null = unlimited. |
| smartEnabled | boolean | Sonnet on hard turns (secret keys only). |
| visionEnabled | boolean | Nova on image/document turns (secret keys only). |
| maxEnabled | boolean | Tier-3 Opus when Sonnet self-flags (secret keys, pricier). |
| learnEnabled | boolean | Per-key style learning (adds metered cost). |
| persona | string | The assistant role/voice for this key ("" if none). |
| createdAt | string | ISO-8601 creation timestamp. |
Errors
Both error types carry .url so your app can route the user to sign up or re-authenticate.
| Field | Type | Description |
|---|---|---|
| ZizNoKeyError | .url | No/invalid key at construction. .url points to the signup page so your app can route the user. |
| ZizApiError | .status, .url? | 401/403/4xx from the API (expired, disabled, over quota, wrong tier, blocked origin). .url present on auth failures. |
Limits & cost
Server-enforced (the server is the source of truth; ZIZ_LIMITS mirrors them for convenience).
| Field | Type | Description |
|---|---|---|
| maxAttachmentsPerTurn | 4 | Images/documents allowed per turn. |
| maxAttachmentBytes | 4,500,000 | Decoded size cap per attachment (~4.5 MB). |
| maxHistoryTurns | 20 | Prior turns accepted (sent text-only). |
| maxMessageChars | 8,000 | Characters per message. |
Cost: chat().usage is token counts only. Dollar amounts come solely from account.usage() / GET /v1/portal/usage, already including the +20% service fee — the SDK ships no pricing table.
Start building
Install is one command; a key takes a minute. The design rationale and security model live in the package README.