Skip to the content
MenuQuickstart

Getting started

Quickstart

At the end of this page, someone on your website is talking to a Zentiq avatar. Your server starts the conversation with your API key. The browser joins with a short-lived token and never sees the key.

You need an organization on Monthly, Pay as you go or Enterprise. Free has no API access.

1. Make an API key#

In the Zentiq console, open More → API Keys and choose Create a key. Name it after where it will live ("Website", "Production server"). For this page, pick the Full access preset, or Choose scopes and tick personas:read and sessions:write.

The key starts with zq_live_, and you only see it once. Put it in an environment variable on your server and check that it works:

Shell
export ZENTIQ_API_KEY=zq_live_…
curl https://app.zentiqai.com/v1/me -H "Authorization: Bearer $ZENTIQ_API_KEY"

GET /v1/me tells you which organization the key belongs to, its plan, and what the key may do (apiKey.effectiveScopes).

2. Choose a persona#

The persona is the avatar people talk to: a face, a voice, what it knows, how it behaves. You can make one in the console under Avatars. Or make one here:

Shell
curl -X POST https://app.zentiqai.com/v1/personas \
  -H "Authorization: Bearer $ZENTIQ_API_KEY" -H "Content-Type: application/json" \
  -d '{ "name": "Ava", "systemPrompt": "You are Ava, a friendly product specialist for Acme. Keep answers short.", "greeting": "Hi, I am Ava. Ask me anything about Acme." }'

Its id comes back as data.id and starts with pa_. GET /v1/personas lists the ones you already have.

3. Start a session on your server#

Install
npm install @zentiq/node@^1
server.ts
import { Zentiq, ZentiqError } from "@zentiq/node";

const zentiq = new Zentiq({ apiKey: process.env.ZENTIQ_API_KEY });
server.ts
async function startSession(userId: string) {
  const token = await zentiq.createSessionToken(
    { personaId: process.env.ZENTIQ_PERSONA_ID ?? "", identity: userId },
    { idempotencyKey: `start-${userId}-${Date.now()}` },
  );
  // { sessionId, sessionToken, url, room, persona, disclosure, cc }: hand all of it to the browser.
  return token;
}

createSessionToken calls POST /v1/sessions/tokens. It starts the session and gives you back:

FieldWhat it is
sessionIdThe session (sess_…). Use it to end, steer or read the session later.
sessionToken, urlWhat the browser joins with. The token is short-lived and only works for this session.
personaThe persona's id, and its name as the avatar says it.
disclosureThe AI disclosure. While required is true, show text for the whole session.
ccWhether the persona shows captions by default.

The call can take up to a minute while an avatar gets ready, so give it a long timeout. The SDK already does. From here the session is live. On Monthly it takes up one of your sessions (conversations at once) until it ends; on Pay as you go it uses credits, one per minute.

4. Join in the browser#

Install
npm install @zentiq/client@^1
browser.ts
import { joinSession, type SessionToken } from "@zentiq/client";

const token = (await fetch("/zentiq/session", { method: "POST" }).then((r) => r.json())) as SessionToken;

// People must know they are talking to an AI: show the persona's words for the whole session.
const disclosure = document.querySelector<HTMLElement>("#disclosure");
if (disclosure && token.disclosure?.required) disclosure.textContent = token.disclosure.text;

const session = await joinSession(token, {
  video: document.querySelector<HTMLVideoElement>("#avatar")!,
  onTranscript: (t) => {
    if (t.final) console.log(t.role === "user" ? "You" : t.speaker ?? token.persona.name, t.text);
  },
  onSpeaking: (who) => document.body.setAttribute("data-speaking", who),
});

People have to know they're talking to an AI. Whenever disclosure.required is true, keep disclosure.text on screen for the whole session.

5. End the session#

browser.ts
document.querySelector("#end")?.addEventListener("click", async () => {
  session.end(); // leaves the room
  // …and your server ends the session, so its time stops counting now.
  await fetch("/zentiq/end", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ sessionId: token.sessionId }) });
});
server.ts
async function endSession(sessionId: string) {
  // Ending frees the session on Monthly and stops credits on Pay as you go, at once. Leaving the room in the browser
  // is not enough on its own.
  await zentiq.endSession(sessionId);
}

session.end() in the browser only leaves the room. The session itself ends when your server calls POST /v1/sessions/{id}/end: that frees the session on Monthly and stops credits on Pay as you go, straight away. If a browser just disappears, Zentiq notices the empty room and ends the session itself a few minutes later.

Next#

Trim the key down to what this integration needs: Keys and scopes.

To change the avatar's instructions mid-conversation, make it say exact words, or answer every turn from your own model, read Live sessions.

To hear when sessions end, set up webhooks.