Conversation Callbacks

If a callback_url is provided in the Create Conversation API Request, callbacks will provide insight into the conversation’s state. These can be system-related (e.g. replica joins and room shutdowns) or application-related (e.g. final transcription parsing and recording-ready webhooks). Additional webhooks coming soon.

Structure

All Conversation callbacks share the following basic structure. Differences will occur in the properties object.

{
    "properties": {
    "replica_id": "<replica_id>"
    },
    "conversation_id": "<conversation_id>",
    "webhook_url": "<webhook_url>",
    "event_type": "<event_type>",
    "message_type": "<system/application>",
    "timestamp": "<timestamp>"
}

Types

Our callbacks are split into two main categories:

System Callbacks

These callbacks are to provide insight into system-related events in a conversation. They are:

  • system.replica_joined: This is fired when the replica becomes ready for a conversation.
  • system.shutdown: This is fired when the room shuts down, for any of the following reasons:
    • max_call_duration reached
    • participant_left_timeout reached
    • participant_absent_timeout reached
    • bot_could_not_join_meeting_it_was_probably_ended
    • daily_room_has_been_deleted
    • exception_encountered_during_conversation_startup
    • end_conversation_endpoint_hit
    • internal error occurred at step x

Examples:

{
  "properties": {
    "replica_id": "<replica_id>"
  },
  "conversation_id": "<conversation_id>",
  "webhook_url": "<webhook_url>",
  "event_type": "system.replica_joined",
  "message_type": "system",
  "timestamp": "2025-07-11T06:45:47.472000Z"
}

Application Callbacks

These callbacks are to inform developers about logical events that take place. They are:

  • application.transcription_ready: This is fired after ending a conversation, where the chat history is saved and returned.
  • application.recording_ready: This is fired if you had enabled recording on, set up a custom S3 bucket for recording and started a recording inside the room at any point. This will point to the key at which your new recording lies, useful for serving recordings through a CDN.
  • application.perception_analysis: This is fired after ending a conversation, when the replica has finished summarizing the visual artifacts that were detected throughout the call. This is a feature that is only available when the persona has raven-0 specified in the Perception Layer.

Examples:

{
  "properties": {
    "replica_id": "<replica_id>",
    "transcript": [
      {
        "role": "system",
        "content": "You are in a live video conference call with a user. You'll receive messages containing the user's speech and system messages containing visual information about the user. These system messages will contain the following visual information: - user's appearance inside the <user_appearance></user_appearance> tag - user's emotions inside the <user_emotions></user_emotions> tag If the user is sharing their screen, you will also receive a <user_screen></user_screen> tag containing the screen share. If you do use the visual information, follow these guidelines: - Do not refer to the visual information as system messages. Instead, act and respond as if you are actually seeing this live. - If the user's query is about their physical appearance, gestures, expressions, or the environment seen through the webcam, use only the content within the <user_appearance> and <user_emotions> tags. - If the query pertains to what is being displayed on the screen share, refer exclusively to the content within the <user_screen> tag. - Ensure that your answer is based solely on the information found in the appropriate tag(s) for the question at hand. DO NOT INCORPORATE ANY VISUAL INFORMATION TO YOUR RESPONSE IF IT'S NOT RELEVANT. \nTalk to the user in a casual, friendly way, trying to match their tone and style in a conversational manner. Do not include stage directions or other formatting artifacts in your response. Reply in short sentences, talk to the user in a casual way.  Respond only in english. Chill guy  You are talking to a user about AI technology."
      },
      {
        "role": "user",
        "content": "Hi."
      },
      {
        "role": "assistant",
        "content": "How's it going?"
      },
      {
        "role": "user",
        "content": "Yeah I'm good, I'm good. How about you?"
      },
      {
        "role": "assistant",
        "content": "I'm doin' great, thanks for askin'. So, you wanted to talk about AI tech, right?"
      },
      {
        "role": "user",
        "content": "Yeah, how about you? What do you think about AI?"
      },
      {
        "role": "assistant",
        "content": "I'm all about AI, it's really interesting stuff. I think it's gonna change a lot of things in the future, make our lives easier and more efficient. What about you, what got you interested in AI?"
      },
      {
        "role": "user",
        "content": "Yeah, AI is an advanced technology for me. It can do a lot of things. And yeah, I think it can be improved to do a lot of live things that we never even talk about before. Where do you think I can learn about AI?"
      },
      {
        "role": "assistant",
        "content": "You can learn about AI from lots of places, like online courses, YouTube tutorials, and even some really cool AI blogs. What area of AI are you most interested in, like machine learning or natural language processing?"
      },
      {
        "role": "user",
        "content": "I think I'm more into NLP. Thank you for the resources though. I have to go soon. So thank you for the conversation. Bye-bye."
      },
      {
        "role": "assistant",
        "content": "NLP is really cool, lots of possibilities there. No problem, it was great chatting with you, have a good one, bye."
      }
    ]
  },
  "conversation_id": "<conversation_id>",
  "webhook_url": "<webhook_url>",
  "event_type": "application.transcription_ready",
  "message_type": "application",
  "timestamp": "2025-07-11T06:48:37.566057Z"
}

Replica Training Callbacks

If a callback_url is provided in the POST /replicas call, you will receive a callback on replica training completion or on replica training error.

{
    "replica_id": "rxxxxxxxxx",
    "status": "ready",
}

Video Generation Callbacks

If a callback_url is providing in the POST /videos call, you will receive callbacks on video generation completed and on video error.

{
    "created_at": "2024-08-28 15:27:40.824457",
    "data": {
    "script": "Hello this is a test to give examples of callbacks"
    },
    "download_url": "https://stream.mux.com/H5H029h02tY7XDpNj9JFDbLleTyUpsJr5npddO8gRsKqY/high.mp4?download=1e30440cf9",
    "generation_progress": "100/100",
    "hosted_url": "https://videos.tavus.io/video/1e30440cf9",
    "replica_id": "r79e1c033f",
    "status": "ready",
    "status_details": "Your request has processed successfully!",
    "stream_url": "https://stream.mux.com/H5H029h02tY7XDpNj9JFDbLleTyUpsJr5npddO8gRsKqY.m3u8",
    "updated_at": "2024-08-28 15:29:19.802670",
    "video_id": "1e30440cf9",
    "video_name": "replica_id: r79e1c033f - August 28, 2024 - video: 1e30440cf9"
}

Sample Webhook Setup

Create a sample webhook endpoint using Python Flask, and expose it publicly with ngrok.

Prerequisites

1

Install Python Dependencies

Install the Python dependencies needed to create the server.

pip install flask request
2

Make a Webhook Server

Set up a webhook server and save it as server.py.

import requests
from flask import Flask, request, jsonify

app = Flask(__name__)

# Store transcripts (in production, use a proper database)
transcripts = {}

@app.route('/webhook', methods=['POST'])
def handle_tavus_callback():
    data = request.json
    event_type = data.get('event_type')
    conversation_id = data.get('conversation_id')
    
    print(f"Received callback: {event_type} for conversation {conversation_id}")
    
    if event_type == 'system.replica_joined':
        print("✅ Replica has joined the conversation")
        
    elif event_type == 'system.shutdown':
        shutdown_reason = data['properties'].get('shutdown_reason')
        print(f"🔚 Conversation ended: {shutdown_reason}")
    
    elif event_type == 'application.recording_ready':
        s3_key = data['properties'].get('s3_key')
        print(f"s3_key : {s3_key}")

    elif event_type == 'application.perception_analysis':
        analysis = data['properties'].get('analysis')
        print(f"analysis : {analysis}")
        
    elif event_type == 'application.transcription_ready':
        print("📝 Transcript is ready!")
        transcript = data['properties']['transcript']
        transcripts[conversation_id] = transcript
        
        # Process the transcript
        analyze_conversation(conversation_id, transcript)
        
    return jsonify({"status": "success"}), 200

def analyze_conversation(conversation_id, transcript):
    """Analyze the conversation transcript"""
    user_turns = len([msg for msg in transcript if msg['role'] == 'user'])
    assistant_turns = len([msg for msg in transcript if msg['role'] == 'assistant'])
    
    print(f"Conversation {conversation_id} analysis:")
    print(f"- User turns: {user_turns}")
    print(f"- Assistant turns: {assistant_turns}")
    print(f"- Total messages: {len(transcript)}")

    print("Conversation : ")

    for msg in transcript:
        print(f"{msg['role']} : {msg['content']}")

if __name__ == '__main__':
    app.run(port=5000, debug=True)

The server will receive and process webhook callbacks from Tavus, handle different event types, store transcripts in memory, and analyze conversation data for each session.

3

Run the Server

Run the app using the following command in the terminal:

python server.py

The server should run on port 5000.

4

Forward the Port Using Ngrok

Open a terminal in the folder containing ngrok.exe, then use Ngrok to forward the port.

ngrok http 5000

The command will generate a forwarding link (e.g., https://1234567890.ngrok-free.app), which can be used as the callback URL.

5

Use the callback URL

Include the callback URL in your request to Tavus by appending /webhook to the forwarding link and setting it in the callback_url field.

Create conversation with callback_url
curl --request POST \
  --url https://tavusapi.com/v2/conversations \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '{
  "callback_url": "https://1234567890.ngrok-free.app/webhook",
  "replica_id": "<replica_id>",
  "persona_id": "<persona_id>",
  "properties": {
    "max_call_duration": 3600,
    "participant_left_timeout": 58,
    "enable_recording": true,
    "recording_s3_bucket_name": "<recording_s3_bucket_name>",
    "aws_assume_role_arn": "<aws_assume_role_arn>",
    "recording_s3_bucket_region": "<recording_s3_bucket_region>"
  }
}'