Examples
SDK Basic Usage — Node.js
Full working example of creating a project, sessions, and managing them via the SDK.
Full working example of creating a project, sessions, and managing them via the SDK.
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. Create a project (or list existing ones)
let projects = await synento.listProjects();
if (projects.length === 0) {
console.log("No projects found. Creating 'Demo Project'...");
const project = await synento.createProject("Demo Project", "development");
console.log(`Created: ${project.name} (${project.id})`);
} else {
console.log(`Found ${projects.length} project(s):`);
for (const p of projects) {
console.log(` - ${p.name} (${p.id}) [${p.environment || "no env"}]`);
}
}
// 3. Create two sessions
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. Toggle visibility
const isPublic = await synento.setSessionVisibility(session1.id, true);
console.log(`Session visibility: ${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
console.log(`\nAlice WS: ${synento.getWebSocketUrl(session1.id, token1.accessToken, "alice")}`);
console.log(`Bob WS: ${synento.getWebSocketUrl(session1.id, token2.accessToken, "bob")}`);
// 8. Usage & billing
try {
const usage = await synento.getUsage();
console.log(`\nUsage records: ${usage.length}`);
const billing = await synento.getBillingSummary();
console.log(`Streaming minutes: ${billing.streamingMinutesUsed}`);
const limits = await synento.getBillingLimits();
console.log(`Within free tier: ${limits.withinFreeTier}`);
} catch (err) {
console.log("Usage info:", err.message);
}
}
main().catch(console.error);Run It
export SYNENTO_API_KEY=sk_live_xxxxx
node index.mjsExpected Output
Synento SDK Demo
==================
Server reachable: true
No projects found. Creating 'Demo Project'...
Created: Demo Project (proj_abc123)
Created session: Team Meeting (sess_def456)
Created session: Q&A Session (sess_ghi789)
Total sessions: 2
Session visibility: true
Alice's token expires in 300s
Bob's replay token expires in 300s
Alice WS: wss://api.synento.com/ws?session=sess_abc123&access_token=...&user_id=alice
Bob WS: wss://api.synento.com/ws?session=sess_abc123&access_token=...&user_id=bob
Usage records: 0
Streaming minutes: 0
Within free tier: trueSDK Advanced Patterns — Replay, Exports & Webhooks
Intermediate patterns for building robust applications on top of Synento's 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.