Your API key is a project secret — it lives on your server and never ships to an app or browser. The server's only job for calling is to exchange that key for short-lived tokens.
Two token types
- Session token (
/v1/session) — lets a user connect to the signalling socket for call invitations + chat. Mint this at login; the client SDK’sconnect()uses it. - Room token (
/v1/token) — lets a participant join one specific media room. Use this if you skip signalling and join a room directly.
sk_live_… in an app, a mobile binary, or browser code. Anyone with it can mint tokens on your project. Keep it in a server env var.Mint a session token
Body { userId, userName } → { token, userId, userName }. A minimal endpoint your app calls:
1// Your backend — mint a SESSION token for the signalling socket.2// The app's client.connect({ sessionEndpoint }) calls this with { userId, userName }.3import express from "express";4const app = express();5app.use(express.json());67const SOCRITS = "https://api.socrits.com";8const KEY = process.env.SOCRITS_API_KEY; // sk_live_… — server-side only910app.post("/socrits/session", async (req, res) => {11 // 1) authenticate YOUR user first (session cookie / JWT / etc.)12 const { userId, userName } = req.body; // trust your own auth, not the client13 // 2) exchange your key for a Socrits user token14 const r = await fetch(SOCRITS + "/v1/session", {15 method: "POST",16 headers: { "x-api-key": KEY, "Content-Type": "application/json" },17 body: JSON.stringify({ userId, userName }),18 });19 res.json(await r.json()); // → { token, userId, userName }20});Mint a room token
Body { room, identity } → { token, url, room }. Hand the url + token to the app to join:
1// Your backend — mint a ROOM token (join a specific room directly, no signalling).2app.post("/socrits/token", async (req, res) => {3 const { room, identity } = req.body; // derive from YOUR authed user4 const r = await fetch(SOCRITS + "/v1/token", {5 method: "POST",6 headers: { "x-api-key": KEY, "Content-Type": "application/json" },7 body: JSON.stringify({ room, identity }),8 });9 res.json(await r.json()); // → { token, url, room }10});Managing keys
- Create/revoke keys per project via the Dashboard API (reference) — a raw key is shown once, then only its hash is stored.
- Use a separate key per environment (dev/staging/prod). Revoke a key the moment it leaks — revocation is instant.
- Rooms are namespaced to your project id, so your room names can never collide with another tenant's.
Room control
Manage a live room from your backend with the project key — the ZEGO KickoutUser / room-dismiss equivalent. Use remove to disconnect one participant (e.g. when their coins run out) while the others keep talking, or end to terminate the whole room.
POST /v1/rooms/:room/remove— body{ identity }; disconnects that one participant.POST /v1/rooms/:room/end— terminates the room, disconnecting everyone.GET /v1/rooms/:room/participants— who’s currently in the room.
1// Your backend — manage a live room with your project key.23// Kick ONE participant (e.g. their balance hit zero). Others stay connected.4await fetch(SOCRITS + "/v1/rooms/" + room + "/remove", {5 method: "POST",6 headers: { "x-api-key": KEY, "Content-Type": "application/json" },7 body: JSON.stringify({ identity }), // the identity you minted the token with8});910// End the WHOLE room — disconnects everyone.11await fetch(SOCRITS + "/v1/rooms/" + room + "/end", {12 method: "POST",13 headers: { "x-api-key": KEY },14});1516// Who's in the room right now.17const res = await fetch(SOCRITS + "/v1/rooms/" + room + "/participants", {18 headers: { "x-api-key": KEY },19}); // → { participants: [{ identity, joinedAt }] }:room is the same room name you pass to /v1/token (Socrits namespaces it to your project internally). For an intentional in-call hang up over hosted signalling, a client sends call:end and the peer receives call:ended (plus a call.ended webhook) — so you can tell a real hang-up from a network drop.Webhooks & metering
Socrits meters participant-minutes per project from LiveKit room events it receives internally — you don’t configure anything. Read current-month usage via GET /dashboard/projects/:id/usage.
For server push, configure per-event signed callbacks in the console (Project → Callback Setup). Each event can POST to its own HTTPS URL; every delivery is HMAC-signed with your CallbackSecret and the body is the envelope { id, type, created, projectId, data }.
Events
- Room —
room.participant_joined,room.participant_left(carries the billedseconds),room.finished. - Call —
call.invited,call.accepted,call.rejected,call.cancelled,call.timeout,call.ended. - Chat —
message.sent,group.created.
Correlating a room with your session
You don’t need to encode your own data into a room name. Pass it as data when you start the call — invite(toUserId, mode, data). That data (and the callId) comes back on every call.* and room.* callback for that call — including room.finished — so you can map a finished room straight back to your own session with no lookup table.
Prefer your own room id? Pass room on the invite — invite(…, { room }) (UIKit) — and both parties join that room instead of a generated room_…, so your existing room scheme carries straight through. The id must be ≤128 chars of letters, digits,., _ or -; anything else is ignored and Socrits mints one. (Express projects already name their own room at /v1/token.)
1POST https://you.example.com/socrits/room-events ← the URL you set for this event2X-Socrits-Event: room.finished3X-Socrits-Delivery: evt_4f1c9e…4X-Socrits-Signature: t=1730419200,v1=9ad3b7… ← HMAC-SHA256 of "<t>.<raw body>"56{7 "id": "evt_4f1c9e…",8 "type": "room.finished",9 "created": 1730419200,10 "projectId": "6710abcd…",11 "data": {12 "callId": "call_1a2b3c4d", // the call this room hosted13 "data": { "sessionId": "sess_42", "staffId": "dr_9" }, // exactly what you passed to invite(data:)14 "room": "room_9f2c7e",15 "roomSid": "RM_8xKpQ…",16 "at": "2026-10-31T09:20:00.000Z"17 }18}Verify the signature over the raw body, then read your data back:
1// Your backend — receive + verify a Socrits callback, then map it to YOUR session.2import crypto from "crypto";3const SECRET = process.env.SOCRITS_CALLBACK_SECRET; // the project's CallbackSecret45// Use the RAW body — the signature is computed over the exact bytes.6app.post("/socrits/room-events", express.raw({ type: "*/*" }), (req, res) => {7 const [t, v1] = (req.get("X-Socrits-Signature") || "").split(",").map(p => p.split("=")[1]);8 const expected = crypto.createHmac("sha256", SECRET).update(t + "." + req.body).digest("hex");9 if (!t || expected !== v1) return res.status(400).end(); // drop forgeries1011 const evt = JSON.parse(req.body);12 if (evt.type === "room.finished") {13 const { callId, data } = evt.data; // ← your session id is right here, no lookup table14 // settle billing / close your session record for data.sessionId15 }16 res.json({ ok: true });17});room.finished fires a few seconds after the last participant leaves (the room’s grace window). For an instant end-of-call signal, use call.ended (sent on an explicit hang-up) or room.participant_left; treat room.finished as the “room fully torn down” event. Billing is unaffected either way — each participant’s minutes close the moment they leave.