@d-id/client-sdk

中文文档
3.0.9发布于 2026/11/08MITTypeScriptESM + CJS构建来源已验证近 30 天下载 3.5万

Browser SDK for D-ID Agents: connect to an agent, stream its video and audio, chat and speak.

原始使用文档
文档目录6 节
  1. Install
  2. Quick start
  3. Next steps
  4. Requirements
  5. Avatar types
  6. Support

D-ID Client SDK

npm version license docs coverage

D-ID Agents SDK

The D-ID Agents SDK embeds an agent you built in D-ID Studio or with the Agents API into a web application. Create an AgentManager for the agent, connect(), then chat() to have the agent answer with its own LLM or speak() to have it say exactly what you give it. The SDK opens the video session (WebRTC, or LiveKit for Expressive agents), keeps the chat transcript and retries a failed connection.

Please note: This SDK is designed for front-end development only. The creation of Agents and Knowledge bases should be handled through the Agents API or directly within the D-ID Studio.

Version 3.0 is a breaking release. Upgrading from 2.x? Read the migration guide.

Install

npm i @d-id/client-sdk

You need an agent id and a client key. Both come from the agent's </> Embed snippet in the D-ID Studio agents gallery, which is also where you list the domains the agent may be used from — see Getting started.

Quick start

import * as sdk from '@d-id/client-sdk';

const videoElement = document.getElementById('agent-video') as HTMLVideoElement;
const agentManager = await sdk.createAgentManager('agt_fumf1234', {
    auth: { type: 'key', clientKey: 'YOUR_CLIENT_KEY' },
    callbacks: {
        onSrcObjectReady: stream => (videoElement.srcObject = stream),
        onNewMessage: messages => console.log(messages[messages.length - 1]?.content),
    },
});

await agentManager.connect();
await agentManager.speak({ type: 'text', input: "Hi! I'm Alice!" });
await agentManager.chat('What is the distance to the moon?');

// Both resolve when the request is accepted, not when the agent has spoken.
window.addEventListener('beforeunload', () => void agentManager.disconnect());

Next steps

The full API reference — every method, callback, option and type, generated from the source on each release — is at sdk.d-id.com. Start with createAgentManager(), AgentManager, AgentManagerCallbacks and, on Talks (V2) and Clips (V3) agents, StreamOptions.

The guides:

  • Getting started — credentials, the first connection, chat() and speak(), disconnecting.
  • Chat modes — conversation, scripted speech or chat off, and what each one creates on the wire.
  • Client tools — running your own functions when the agent's LLM calls them.
  • Expressive agents — microphone, camera, speech-to-text, interrupts and data-channel messages.
  • Handling errors — which failures reject, which reach onError, and what to log.
  • Migration guide — every breaking change from 2.x.

A working sample project in Vanilla JavaScript and Vite is in the demo repository.

Requirements

  • A modern browser with WebRTC. The SDK streams the agent's video over WebRTC (Talks and Clips) or LiveKit (Expressive), and renders it into a <video> element you provide.
  • ESM and UMD builds. import resolves to the ES module; require and a <script> tag resolve to the UMD bundle.
  • TypeScript types included. They ship with the package; there is no separate @types to install.
  • Node is not a runtime target, but importing the package on a server is safe: the module graph touches no browser globals at import time, so server-rendered frameworks (Next.js, Remix, SvelteKit, Astro) can evaluate it. Everything past createAgentManager() needs a browser.

Avatar types

  • Talks (V2) — Photo-based presenters using WebRTC streaming.
  • Clips (V3) — Pre-built presenter avatars using WebRTC streaming.
  • Expressive (V4) — Next-generation avatars using LiveKit-based streaming, supporting microphone input and always-on fluent mode.

Support

Questions, bug reports and documentation issues are welcome as GitHub issues. The product documentation lives at docs.d-id.com.

版本与发布记录

@d-id/client-sdk 共发布 614 个版本,首次发布于 2023/11/19;过去 12 个月发布了 338 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.0.9latest2026/11/082 天前
3.0.8-staging.447staging2026/11/082 天前
3.0.82026/10/1823 天前
3.0.7-staging.4452026/10/1823 天前
3.0.7-staging.4442026/10/1823 天前
3.0.72026/10/1427 天前

其他发布通道:beta → 1.1.0-beta.27,staging → 3.0.8-staging.447。

关于 @d-id/client-sdk 的常见问题

@d-id/client-sdk 是什么?

Browser SDK for D-ID Agents: connect to an agent, stream its video and audio, chat and speak.

如何安装 @d-id/client-sdk?

在项目目录运行 npm install @d-id/client-sdk,或使用 pnpm add / yarn add / bun add。

@d-id/client-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@d-id/client-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@d-id/client-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@d-id/client-sdk 可以商用吗?

@d-id/client-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@d-id/client-sdk 的下载量有多少?

根据 npm 官方下载统计,@d-id/client-sdk 在 2026/10/11 – 2026/11/09 这 30 天内被下载 34,525 次,日均约 1,151 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@d-id/client-sdk 还在维护吗?

最新版本 3.0.9 发布于 2026/11/08(2 天前);至今共发布 614 个版本,其中过去 12 个月发布了 338 个;首次发布于 2023/11/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。