D-ID Client SDK - v3.0.0-0
    Preparing search index...

    Function createAgentManager

    • Creates an AgentManager for one agent: its chat, its video stream and its connections.

      Fetches the agent from the Agents API before it resolves, so the returned manager already has agent and starterMessages filled in. No stream is opened until connect() is called. Two options are checked here, and both reject with a ValidationError: an Expressive (V4) agent asked for ChatMode.Off or ChatMode.DirectPlayback, which only Talks (V2) and Clips (V3) agents support; and callbacks without onSrcObjectReady in a mode that streams video — that callback is what attaches the streamed media to a video element, and only ChatMode.TextOnly, ChatMode.Playground and ChatMode.Maintenance can do without it. Every other bad argument surfaces later, as a ValidationError rejected by the method that was called on the returned manager, such as chat() or speak().

      Parameters

      • agent: string

        Id of the agent to talk to: the data-agent-id from its Embed snippet, or the id returned by the Agents API.

      • options: AgentManagerOptions

        Credentials, callbacks and everything else the manager needs. See AgentManagerOptions.

      Returns Promise<AgentManager>

      A manager for that agent, ready to connect().

      ValidationError When an Expressive (V4) agent is created with ChatMode.Off or ChatMode.DirectPlayback, or when onSrcObjectReady is missing in a mode that streams video.

      HttpError When the agent cannot be fetched — an unknown id, or a client key that is not authorized for the agent or the calling domain.

      NetworkError When the request for the agent never reaches the server: the browser is offline, DNS or TLS fails, or the request is blocked.

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

      const agentManager = await sdk.createAgentManager('agt_fumf1234', {
      auth: { type: 'key', clientKey: 'YOUR_CLIENT_KEY' },
      callbacks: {
      // Hand the streamed media to your video element. Required in every mode that
      // streams video, which is every mode but TextOnly, Playground and Maintenance.
      onSrcObjectReady(value) {
      videoElement.srcObject = value;
      },
      },
      });

      await agentManager.connect();
      await agentManager.chat('What is the distance to the moon?');