npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@keyframelabs/sdk

v0.1.8

Published

The universal, low-level SDK for Keyframe Labs.

Readme

@keyframelabs/sdk

The universal, low-level SDK for Keyframe Labs.

Which package should I use?

  • @keyframelabs/sdk (high control)
    • You implement the UI, state management, and agent/llm binding yourself
  • @keyframelabs/elements (custom UI)
    • You implement the UI; we handle the state and agent/llm binding (framework-agnostic)
  • @keyframelabs/react: (drop-in)
    • We handle the UI, state, and agent/llm binding

Installation

pnpm add @keyframelabs/sdk

Quick start

1. Server-side: create a session

From your backend, use your secret Keyframe API key to create a session.

// POST https://api.keyframelabs.com/v1/session
const response = await fetch('https://api.keyframelabs.com/v1/session', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${process.env.KFL_API_KEY}`,
  },
  body: JSON.stringify({
    persona_id: "6efx..." // or persona_slug
  }),
});

// Returns { serverUrl, participantToken }
const session = await response.json();

2. Client-side: connect the client

Pass the session details to the client SDK.

import { createClient } from '@keyframelabs/sdk';

const persona = createClient({
  serverUrl: "wss://...",
  participantToken: "A6gB...",
  agentIdentity: "agent",
  onVideoTrack: (track) => {
    // Some HTML video element
    videoElement.srcObject = new MediaStream([track]);
  },
  onAudioTrack: (track) => {
    // Some HTML audio element
    audioElement.srcObject = new MediaStream([track]);
  },
  onAgentStateChange: (state) => {
    console.log('Agent state:', state); // 'listening' | 'speaking'
  },
});

// Connect to the session
await client.connect();

// Send audio (e.g. from your LLM/Agent)
client.sendAudio(pcmAudioBytes);

// Signal an interruption (clears pending frames)
persona.interrupt();

// Cleanup
await client.close();

Architecture

The SDK handles the real-time transport loop between your agent or real-time LLM and the Keyframe Platform, as well as synced audio/video rendering.

+-----------------------+                         +-----------------------+
|  Browser              |                         |   Keyframe Platform   |
|                       |                         |                       |
|  +-----------------+  |                         |  +-----------------+  |
|  |   Microphone    |  |                         |  |  AvatarSession  |  |
|  +-----------------+  |                         |  +-----------------+  |
|           |           |                         |           ^           |
|           v           |                         |           |           |
|  +-----------------+  |       DataStream        |           |           |
|  |   Agent / LLM   |  |       (PCM 16kHz)       |           |           |
|  +-----------------+  | ----------------------> |           |           |
|           |           |                         |           |           |
|           v           |                         |           v           |
|  +-----------------+  |                         |  +-----------------+  |
|  | PersonaSession  |  |                         |  |    Inference    |  |
|  +-----------------+  |                         |  +-----------------+  |
|           ^           |                         |           |           |
|           |           |          WebRTC         |           |           |
|           |           |     (Audio + Video)     |           v           |
|  +-----------------+  | <---------------------- |  +-----------------+  |
|  |  Video Element  |  |                         |  |      Video      |  |
|  +-----------------+  |                         |  +-----------------+  |
|                       |                         |                       |
+-----------------------+                         +-----------------------+

Integrating a specific agent or real-time LLM

The SDK is intentionally minimal—it only handles the avatar connection. You bring your own agent or real-time LLM (e.g, Cartesia, ElevenLabs, Gemini, OpenAI).

API

createClient(options)

Initializes the WebSocket connection and media managers.

| Option | Type | Default | Description | | -------------------- | ----------------- | -------- | --------------------------------------------------------- | | serverUrl | string | Required | The WSS URL returned by the /session API endpoint. | | participantToken | string | Required | The access token returned by the /session API endpoint. | | agentIdentity | string | Required | Identity of the agent participant in the room. | | onVideoTrack | (track) => void | Required | Fired when the WebRTC video track is ready. | | onAudioTrack | (track) => void | Required | Fired when the WebRTC audio track is ready. | | onStateChange | (state) => void | — | Fired when session state changes. | | onAgentStateChange | (state) => void | — | Fired when agent playback state changes ('listening' or 'speaking'). | | onClose | (reason) => void | — | Fired when the session is closed (by server or client). | | onError | (err) => void | — | Fired on errors. |

PersonaSession

The client instance returned by createClient().

Methods

| Method | Signature | Description | | ------------ | ---------------------------------------------- | ------------------------------------------------ | | connect | () => Promise<void> | Connect to the session. | | sendAudio | (pcmData: ArrayBuffer \| Int16Array) => void | Send 24 kHz 16-bit PCM audio. | | interrupt | () => void | Signal an interruption and clear pending frames. | | setEmotion | (emotion: Emotion) => Promise<void> | Set the avatar's emotional expression. | | close | () => void | Close the session and release resources. |

Properties

| Property | Type | Description | | -------- | ---------------------------------------------------------- | ---------------------- | | state | 'disconnected' \| 'connecting' \| 'connected' \| 'error' | Current session state. |

Types

Emotion

Emotion states for avatar expression:

type Emotion = 'neutral' | 'angry' | 'sad' | 'happy';

Emotion Controls

You can dynamically change the avatar's emotional expression using the setEmotion method:

// Set the avatar to show happiness
await client.setEmotion('happy');

// React to user sentiment
await client.setEmotion('sad');

// Return to neutral
await client.setEmotion('neutral');

The avatar will blend its facial expression and demeanor to match the specified emotion. This can be triggered manually or in response to sentiment analysis, LLM output, or other signals from your application.

License

MIT