Step 1 · Your server
Your server makes one call.
Create a session with your org API key, and forward the body unchanged. The key never reaches the browser.
app.get("/api/session", async (req, res) => {
if (!req.user) return res.status(401).end();
const r = await fetch(
`${MINDSET_HOST}/api/v1/orgs/${ORG}/envs/${ENV}/agent-sessions`,
{
method: "POST",
headers: {
"x-api-key": process.env.MINDSET_ORG_API_KEY,
"content-type": "application/json",
},
body: JSON.stringify({
user: { email: req.user.email },
agent: "billing-help",
createUserIfNeeded: true,
}),
},
);
res.set("cache-control", "no-store").json(await r.json());
});Speaker notes
A session is an opaque credential for one agent, one user, one org and one environment, held in memory in the page; the SDK renews its own short-lived token. createUserIfNeeded creates the Mindset user on first visit, otherwise a first-time user gets a 404. no-store stops a shared cache handing one user’s session to another. Forward the body whole: it also carries the switched-on release features. Name users by email or by your own externalId.