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:
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:
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#
npm install @zentiq/node@^1import { Zentiq, ZentiqError } from "@zentiq/node";
const zentiq = new Zentiq({ apiKey: process.env.ZENTIQ_API_KEY });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:
| Field | What it is |
|---|---|
sessionId | The session (sess_…). Use it to end, steer or read the session later. |
sessionToken, url | What the browser joins with. The token is short-lived and only works for this session. |
persona | The persona's id, and its name as the avatar says it. |
disclosure | The AI disclosure. While required is true, show text for the whole session. |
cc | Whether 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#
npm install @zentiq/client@^1import { 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#
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 }) });
});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.