Custom LLMs

Comprehensive guide for integrating your own LLM implementation with D-ID agents. Learn how to create an OpenAI-compatible endpoint, handle authentication, optimize for production, and implement streaming responses.

Note: LLMs must stream tokens to minimize latency between turns.

Overview

Custom LLM integration enables you to:

  • Use proprietary or fine-tuned models with D-ID agents
  • Route requests through your own infrastructure
  • Maintain full control over model selection and parameters

Example Code

You can start from our reference implementation on GitHub.

Responsibilities

D-ID's Responsibility
  • Securely store and encrypt your API keys/credentials
    • Send properly formatted requests to your endpoint
    • Handle streaming and non-streaming responses
    • Include metadata headers for context
Your Responsibility
  • Implement an OpenAI compatible endpoint
    • Authenticate requests via API key or OAuth2
    • Optimize for low latency (TTFT 200–500ms, under 1000ms p95)
    • Scale infrastructure for production load

Usage

Custom LLM Configuration Options

FIELDTYPEREQUIREDDESCRIPTION
typestring✓ YesAuthentication type: basic or oauth2
urlstring✓ YesYour LLM endpoint URL that receives POST requests
streamingbooleanOptionalEnable streaming for production (Default: false)
max_messagesnumberOptionalMaximum conversation history messages sent to your LLM
headersobjectOptionalAdditional custom headers to include in requests

LLM Behavior (Optional)

Custom LLMs support the same behavior configuration as OpenAI:

FIELDTYPEDESCRIPTION
instructionsstringDefines what the Agent does and how it should behave
prompt_customizationobjectAdvanced prompt control (role, personality, topics_to_avoid, etc.)

Authentication

Basic

FIELDTYPEREQUIREDDESCRIPTION
keystring✓ YesAPI key sent in x-api-key header

OAuth2

FIELDTYPEREQUIREDDESCRIPTION
token_urlstring✓ Yestoken endpoint for client credentials
client_idstring✓ Yesclient identifier
client_secretstring✓ Yesclient secret

FAQ