SDK basic usage: Node.js
List projects, create sessions, mint tokens, and check usage with the Node.js SDK.
An API key belongs to one project. The sessions in this example are created in
that project. createProject(name, environment) adds another project to your
organisation, but to create sessions in it you need an API key for that project.
Setup
mkdir synento-sdk-demo && cd synento-sdk-demo
npm init -y
echo '{"type":"module"}' > package.jsonInstall the Node SDK:
npm install @synento/nodeComplete example: index.mjs
import { createSynentoClient } from "@synento/node";
const synento = createSynentoClient({
apiKey: process.env.SYNENTO_API_KEY, // sk_live_xxxxx
});
async function main() {
console.log("Synento SDK Demo");
console.log("==================\n");
// 1. Health check
const healthy = await synento.healthCheck();
console.log(`Server reachable: ${healthy}`);
// 2. List the projects in your organisation
const projects = await synento.listProjects();
console.log(`Found ${projects.length} project(s):`);
for (const p of projects) {
console.log(` - ${p.name} (${p.id}) [${p.environment}]`);
}
// 3. Create two sessions (in the project the API key belongs to)
const session1 = await synento.createSession({ name: "Team Meeting" });
console.log(`\nCreated session: ${session1.name} (${session1.id})`);
const session2 = await synento.createSession({ name: "Q&A Session" });
console.log(`Created session: ${session2.name} (${session2.id})`);
// 4. List all sessions
const sessions = await synento.listSessions();
console.log(`\nTotal sessions: ${sessions.length}`);
// 5. Make a session public, then read it back
await synento.setSessionVisibility(session1.id, true);
const updated = await synento.getSession(session1.id);
console.log(`Session visibility: ${updated?.isPublic ? "public" : "private"}`);
// 6. Get connection tokens
const token1 = await synento.createConnectionToken(session1.id, { userId: "alice" });
console.log(`\nAlice's token expires in ${token1.expiresIn}s`);
const token2 = await synento.createConnectionToken(session1.id, {
userId: "bob",
replay: true, // bob is watching a recording
fromTs: 0, // start from the beginning
});
console.log(`Bob's replay token expires in ${token2.expiresIn}s`);
// 7. WebSocket URLs. The browser SDK sends the token separately, as a
// WebSocket subprotocol, so it never appears in the URL.
console.log(`\nAlice WS: ${synento.resolveWsUrl({ sessionId: session1.id, userId: "alice" })}`);
console.log(`Bob WS: ${synento.resolveWsUrl({ sessionId: session1.id, userId: "bob" })}`);
// 8. Usage against your plan's allowance
const limits = await synento.getBillingLimits();
console.log(`\n${limits.statusMessage}`);
console.log(`Streaming minutes this period: ${limits.streamingMinutesUsed}`);
console.log(`Within included allowance: ${limits.withinIncludedAllowance}`);
}
main().catch(console.error);Run it
export SYNENTO_API_KEY=sk_live_xxxxx
node index.mjsExpected output
IDs are 32-character hex strings; yours will differ. The project list shows every project in your organisation.
Synento SDK Demo
==================
Server reachable: true
Found 1 project(s):
- My App (5e286c87114834912fd972164fc171b2) [dev]
Created session: Team Meeting (5421c976103e58451491c7743c04f6da)
Created session: Q&A Session (a488f48b27e80176959ff5ca155642b1)
Total sessions: 2
Session visibility: public
Alice's token expires in 3600s
Bob's replay token expires in 3600s
Alice WS: wss://api.synento.com/ws?session=5421c976103e58451491c7743c04f6da&user_id=alice
Bob WS: wss://api.synento.com/ws?session=5421c976103e58451491c7743c04f6da&user_id=bob
Within Free plan allowance
Streaming minutes this period: 0
Within included allowance: trueSDK advanced patterns: replay, exports and webhooks
Replay recordings, verify webhooks, respect billing limits, and share expiring replay links with the Synento SDK.
Web quickstart: live video in a web page
Join a live Synento session from the browser with two-way audio and video, using a short-lived connection token minted by your server.