how to setup call recording
# ask-ai
e
how to setup call recording
t
Thanks for reaching out, Aman. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can set up call recording in three main ways — which would you like to use: auto-egress via SIP dispatch rule (recommended for SIP calls), start egress programmatically from your agent, or enable egress when creating the room? If you pick one, I’ll give the exact steps and an example for that method. Sources: examples/bank-ivr | livekit/livekit_composite | DeepWiki | Observability data hooks | LiveKit docs | Auto egress | LiveKit docs | sip | livekit/livekit_composite | DeepWiki | Agent insights in LiveKit Cloud | LiveKit docs
e
1. will it record for both my phone call and web 2. i would like to use: start egress programmatically from your agent, do i have to use any livekit cloud service for it?
t
Regarding your two questions: 1) Yes — starting egress programmatically records both phone (SIP) and web participants in the room. Recordings from a room composite include all participants’ audio/video unless you configure audio-only or select individual tracks. 2) You do not have to use LiveKit Cloud specifically — egress can run against any LiveKit deployment that supports egress (LiveKit Cloud or your self-hosted LiveKit server with egress enabled). You only need a LiveKit instance reachable by your agent code and appropriate egress configuration/credentials (S3/GCP/Azure or other supported output). If you want, I can: • show the exact agent code example for starting a room composite egress with S3 output, or • list the required fields/credentials you’ll need to provide. Which would you like?
e
give me information on the both • show the exact agent code example for starting a room composite egress with S3 output, or • list the required fields/credentials you’ll need to provide. Which would you like?
t
Responding to your request: below is an agent code example to start a Room Composite Egress that writes a recording to S3, followed by the required fields/credentials you must provide. Code example (Python, using LiveKit API client):
Copy code
import os
import asyncio
from livekit import api  # LiveKit API client

async def start_room_composite_egress():
    # LiveKit API credentials / endpoint
    LK_API_KEY = os.getenv("LK_API_KEY")
    LK_API_SECRET = os.getenv("LK_API_SECRET")
    LK_URL = os.getenv("LK_URL", "https://your-livekit-server")  # e.g., https://livekit.example.com

    # S3 destination details
    S3_BUCKET = os.getenv("S3_BUCKET")
    S3_REGION = os.getenv("S3_REGION", "us-east-1")
    S3_ACCESS_KEY = os.getenv("S3_ACCESS_KEY")
    S3_SECRET = os.getenv("S3_SECRET")
    # Path template — you can include ${room_name} or other variables
    FILEPATH = "recordings/${room_name}.mp4"

    # Build file output with S3 upload
    file_output = api.EncodedFileOutput(
        filepath=FILEPATH,
        s3=api.S3Upload(
            bucket=S3_BUCKET,
            region=S3_REGION,
            access_key=S3_ACCESS_KEY,
            secret=S3_SECRET,
        ),
    )

    req = api.RoomCompositeEgressRequest(
        room_name="my-call-room",      # room to record
        audio_only=False,              # set True for audio only
        file_outputs=[file_output],
    )

    lkapi = api.LiveKitAPI(
        base_url=LK_URL,
        api_key=LK_API_KEY,
        api_secret=LK_API_SECRET,
    )

    resp = await lkapi.egress.start_room_composite_egress(req)
    await lkapi.aclose()
    print("Egress started:", resp)
    return resp

if __name__ == "__main__":
    asyncio.run(start_room_composite_egress())
Required fields / credentials • LiveKit API ◦
LK_URL
— LiveKit server base URL (LiveKit Cloud or self-hosted endpoint). ◦
LK_API_KEY
and
LK_API_SECRET
— API credentials that authorize egress requests. • Room & egress settings ◦
room_name
— the room you want to record. ◦
audio_only
(bool) — whether to record audio-only. ◦
file_outputs
/
filepath
— output path template (can include
${room_name}
). • S3 upload credentials (for AWS S3 destination) ◦
bucket
— target S3 bucket name. ◦
region
— AWS region for the bucket. ◦
access_key
— AWS access key with write permissions to the bucket. ◦
secret
— AWS secret key. ◦ (Optional) IAM role, session token, or other AWS auth mechanism if you use temporary credentials. Other notes • Supported destinations include S3, GCP, Azure, RTMP/HLS — you’ll supply equivalent credentials for those backends. • Recordings capture all participants in the room composite unless you configure per-track egress or audio-only. • Ensure your LiveKit deployment has egress enabled and network access to S3. Would you like the same example in Node.js or a curl example for creating the egress via REST/Twirp?
e
how this will integrate with my existing agent setup in python
t
You're recording from your agent, so you'll call the Room Composite Egress API from the place where your agent has the room context and can authenticate to LiveKit. Below are concise, practical integration steps and a small example showing where to plug the egress call into a typical Python agent flow. Integration steps 1. Add LiveKit API client to your agent process (same environment that runs the agent logic). Install the SDK and export LiveKit + S3 creds as env vars. 2. Identify where your agent has the room name or room context (after creating/joining the room or when handling an inbound SIP call). 3. Start egress from that code path (optionally after agent answers) and store the returned egress ID so you can monitor or stop it later. 4. Handle lifecycle: track egress status events or poll status; stop egress when the call ends or after a timeout. 5. Log egress responses and errors, and surface S3 file paths once completed. Minimal integration example • Place the egress start call in the function that runs when your agent joins or accepts a call. • Store the response (egress id) to stop or query later. Example pattern (merge into your agent code):
Copy code
# inside your agent code that has room context
import os, asyncio
from livekit import api

async def start_recording_for_room(room_name):
    lkapi = api.LiveKitAPI(
        base_url=os.getenv("LK_URL"),
        api_key=os.getenv("LK_API_KEY"),
        api_secret=os.getenv("LK_API_SECRET"),
    )

    file_output = api.EncodedFileOutput(
        filepath="recordings/${room_name}.mp4",
        s3=api.S3Upload(
            bucket=os.getenv("S3_BUCKET"),
            region=os.getenv("S3_REGION"),
            access_key=os.getenv("S3_ACCESS_KEY"),
            secret=os.getenv("S3_SECRET"),
        ),
    )

    req = api.RoomCompositeEgressRequest(
        room_name=room_name,
        audio_only=False,
        file_outputs=[file_output],
    )
    resp = await lkapi.egress.start_room_composite_egress(req)
    await lkapi.aclose()
    return resp  # contains egress id and metadata

# Example usage in your agent lifecycle
async def on_agent_join(room_name):
    resp = await start_recording_for_room(room_name)
    egress_id = resp.id
    # save egress_id with the call/session record so you can stop or query later
Stopping or querying egress • Call the LiveKit egress stop/status APIs with the saved
egress_id
from your agent when the call ends or on demand. Practical tips • Start egress shortly after agent joins the room (or after answering) so the whole call is captured. • Persist
egress_id
alongside your call/session record to tie recordings back to calls. • Add retries and error handling for transient network or auth failures. • If you deploy agents scaled across processes, ensure each agent can authenticate to LiveKit and has permissions to start egress. If you share a snippet of your current agent join/answer handler, I can show exactly where to insert the egress call and return a tailored code example. Would you like that?
e
what are other ways to record
t
Below are the recording methods you can use with LiveKit, a short description of when to use each, and what they produce. This will help you pick the best approach for your agent. • Room Composite Egress ◦ What it does: Records a rendered layout of the entire room (grid/speaker) using headless Chrome. ◦ Output: MP4, HLS, or RTMP/SRT. ◦ Use when: You want a polished meeting-style recording that includes all participants (web + SIP/phone). ◦ Notes: Good for archive or playback where layout matters. • Track Composite Egress ◦ What it does: Mixes one audio track and one video track into a single synchronized output. ◦ Output: Transcoded single stream (e.g., MP4). ◦ Use when: You want a specific combination of audio+video (e.g., presenter camera + program audio). • Track Egress ◦ What it does: Exports individual raw tracks (no transcoding). ◦ Output: Raw audio/video files or streams. ◦ Use when: You need raw tracks for transcription, AI processing, or custom post-processing. • Participant Egress ◦ What it does: Records a single participant’s audio+video together. ◦ Output: Per-participant file. ◦ Use when: You only need one participant’s feed (e.g., instructor or agent). • Web Egress ◦ What it does: Records any web page (not limited to LiveKit rooms). ◦ Output: MP4/HLS/stream. ◦ Use when: You need to record UIs or third-party pages (e.g., dashboards, agent UI). • Auto Egress (Egress at Room Creation / SIP Dispatch Rule) ◦ What it does: Automatically starts recording when a room is created or via SIP dispatch rules. ◦ Output: Same outputs as other egress types (S3/GCP/Azure, RTMP/HLS). ◦ Use when: You want recordings to start automatically (always-on recording, SIP flows). Key things all methods share • They record both web and SIP/phone participants because SIP participants are bridged into the room like WebRTC peers. • Outputs can be written to S3, GCP, Azure Blob, or streamed via RTMP/HLS. • You can start/stop programmatically via the egress APIs and receive an
egress_id
to track/stop/status-check. • Choose Room Composite for full-room rendered recordings; choose Track/Participant/Track Composite when you need per-track or per-user outputs or raw tracks for downstream processing. If you want, I can: • recommend which method best fits your agent use case (IVR/compliance vs. QA vs. transcription), or • provide a Node.js/cURL example for any method listed. Which would you like? Sources: Recording and export | LiveKit docs | RoomComposite Egress | LiveKit Docs | Composite and web recordings | LiveKit docs | Auto egress | LiveKit docs | livekit/livekit_composite | DeepWiki