Agent Session Quickstart
Stream real-time conversations with your agent
Connect to your agent and have real-time video conversations using the D-ID Client SDK. The SDK handles WebRTC streaming and provides a simple interface for chat.
Create a client key
Generate a client key for your agents. This key is used by the SDK to authenticate frontend connections.
curl -X POST "https://api.d-id.com/agents/client-key" \
-H "Authorization: Basic <YOUR KEY>" \
-H "Content-Type: application/json" \
-d '{
"allowed_domains": ["http://localhost:3000", "https://yourdomain.com"]
}'{
"client_key": "Y2xpZW50X2tleV9hYmMxMjM0NTY3ODk...",
}Save the client_key — you'll use this in your frontend code. The key only works from the allowed origins you specified.
Install the SDK
Add the D-ID Client SDK to your frontend project.
npm install @d-id/client-sdkInitialize the agent manager
Import the SDK and create an agent manager with your credentials. Connect the HTML video element to the returned video object returned from the SDK
import * as did from "@d-id/client-sdk";
const agentId = "agt_abc123";
const auth = { type: "key", clientKey: "<YOUR CLIENT KEY>" };
// HTML video element to display the agent
const videoElement = document.getElementById("agent-video");
let srcObject;
const callbacks = {
onSrcObjectReady(value) {
videoElement.srcObject = value;
srcObject = value;
},
onConnectionStateChange(state) {
console.log("Connection state:", state);
},
onNewMessage(messages, type) {
console.log("Messages:", messages);
}
};
const agentManager = await did.createAgentManager(agentId, { auth, callbacks });Connect and chat
Establish the WebRTC connection and send messages to your agent.
// Connect to the agent
await agentManager.connect();
// Send a chat message - the agent will respond with streaming video
await agentManager.chat("Hello! What can you help me with?");
// When done, disconnect
await agentManager.disconnect();The video element in the HTML
<video id="agent-video" autoplay playsinline></video>The agent responds with real-time streaming video. Use agentManager.chat() for conversational messages or agentManager.speak() to make the agent say specific text.
Updated about 10 hours ago
