---
updatedAt: 2026-09-15T10:54:45.000Z
agentTools:
  projectIndex: https://docs.d-id.com/llms.txt
---

# Agent Sessions

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.

<CoolSteps name="agent-session-quickstart">
  <CoolStep number={1} title="Create a client key">
    Generate a client key for your agents. This key is used by the SDK to authenticate frontend connections.

    ```yaml Request
    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"]
      }'
    ```

    ```json Response
    {
      "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.
  </CoolStep>

  <CoolStep number={2} title="Install the SDK">
    Add the D-ID Client SDK to your frontend project.

    ```bash
    npm install @d-id/client-sdk
    ```
  </CoolStep>

  <CoolStep number={3} title="Initialize 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

    ```javascript client.js
    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 agent = await did.createAgentManager(agentId, { auth, callbacks });
    ```
  </CoolStep>

  <CoolStep number={4} title="Connect and chat">
    Establish the WebRTC connection and send messages to your agent.

    ```javascript client.js
    // Connect to the agent
    await agent.connect();

    // Send a chat message - the agent will respond with streaming video
    await agent.chat("Hello! What can you help me with?");

    // When done, disconnect
    await agent.disconnect();
    ```

    The video element in the HTML

    ```html HTML Video Element
    <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.

    For a code example demonstrating the entire process, you can visit the [D-ID Agents SDK Demo repository](https://github.com/de-id/agents-sdk-demo) in GitHub.

    For every method, callback and option the SDK exposes, see the [Agents SDK API reference](https://sdk.d-id.com/).
  </CoolStep>
</CoolSteps>