how can I record the call in livekit room and stor...
# ask-ai
r
how can I record the call in livekit room and store directly in aws bucket
t
Thanks for reaching out, Rahul. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’ll help you record a LiveKit room and store the recording directly in an AWS S3 bucket. Quick confirmation: Do you want a full-room recording (composited MP4 of the room) or individual participant track exports? If you want the whole room, choose Room Composite. For single-participant or raw-track exports, choose Track Composite or Track Egress. Steps to record to S3 (Room Composite — full-room MP4): 1. Ensure LiveKit Egress service is running (egress must be enabled on your LiveKit deployment). 2. From your server (use a server SDK — Go, Node, Python, etc.) call the StartRoomCompositeEgress API and set the output to S3. Provide: ◦
Bucket
name ◦
Region
◦ AWS
AccessKey
and
Secret
(or use injected/instance credentials for production) ◦
Filepath
(path/name to write, you can include variables like
${room_name}_${time}
) Example fields:
FileType: MP4
,
Filepath: recordings/${room_name}_${time}
,
S3: {AccessKey, Secret, Bucket, Region}
1. (Optional) Automate: listen for
room_started
webhook and trigger StartRoomCompositeEgress; handle
egress_ended
webhook to get final S3 location/metadata. Notes and best practices: • Egress is started from the server side only (not from client JS). • For single participant recordings, use Track Composite (synchronized A/V) or Track Egress for raw track files; both support S3 outputs similarly. • Don’t hardcode AWS keys in code—use environment variables, IAM roles, or secret management for production. • Ensure the credentials you provide have S3 write permissions for the target bucket. If you’d like, tell me: • Which SDK/language you use (Go, Node, Python), • Whether you want Room Composite or Track Egress, and I’ll provide a concrete code example and the exact request payload. Sources: Universal Egress | server-sdk-js | livekit/livekit_composite | DeepWiki
r
python so there will be two participants one agent and other caller so telephony agent is my use case, so I need to store both of the tracks and I have hosted the livekit server
t
Thanks — I’ll walk you through recording both participants’ tracks in Python and saving them to S3. A couple quick clarifying questions before I give code samples: • Do you want one combined file with both participants synced (single MP4) or separate files per participant (one file per track)? • Do you need video recorded, or audio only? If you want both tracks separately, use Track Egress (one request per track) or Track Composite for synchronized A/V per participant. If you want a single combined recording of the whole room, use Room Composite. Once you confirm those two points I’ll provide a concise Python example showing: • how to start egress from your hosted LiveKit server, • the exact request payload for S3 output (bucket, region, credentials), • how to map participant track IDs to egress requests, • recommended credential handling for production.
r
both recorded in single file and audio only
t
Thanks — I’ll give a concise Python example and the exact steps to record both participants as a single audio-only file (mixed) and upload it directly to your S3 bucket using Room Composite egress. Confirming what you asked: record a hosted LiveKit room (agent + caller) into one audio-only file and store to AWS S3. Pre‑reqs • LiveKit Egress service running on your hosted LiveKit server. • LiveKit server API key & secret that can start egress. • S3 bucket and credentials (use IAM role or environment secrets in production). Minimal Python example (async, using LiveKit API client)
Copy code
# install: pip install livekit-api-client  # or your project's LiveKit Python SDK package

import asyncio
from livekit import LiveKitAPI
from livekit import RoomCompositeEgressRequest, EncodedFileOutput, S3Upload

async def start_audio_room_recording():
    api = LiveKitAPI(
        url="<https://YOUR_LIVEKIT_HOST>",     # your LiveKit host (https)
        api_key="YOUR_API_KEY",
        api_secret="YOUR_API_SECRET",
    )

    req = RoomCompositeEgressRequest(
        room_name="your-room-name",
        audio_only=True,   # mix all participant audio into one stream
        file_outputs=[
            EncodedFileOutput(
                file_type="OGG",   # Opus in OGG container (good for audio/voice)
                filepath="recordings/call_${room_name}_${time}.ogg",
                s3=S3Upload(
                    access_key="YOUR_S3_ACCESS_KEY",
                    secret="YOUR_S3_SECRET",
                    region="us-east-1",
                    bucket="your-s3-bucket-name",
                ),
            )
        ],
    )

    resp = await api.egress.start_room_composite(request=req)
    print("egress_id:", resp.egress_id)

    # optional: poll status
    status = await api.egress.get_egress(egress_id=resp.egress_id)
    print("state:", status.state)

if __name__ == "__main__":
    asyncio.run(start_audio_room_recording())
Notes and best practices • Set
audio_only=True
to get a mixed single audio file of the room. •
OGG
with Opus is recommended for voice; you can choose other formats supported by the SDK. • Provide S3 credentials in the egress request, or prefer environment/instance credentials or an IAM role instead of hardcoding. • Start egress from your server (not client-side). • Use webhooks: start recording on
room_started
and check
egress_ended
for final metadata (S3 path). • Ensure the IAM credentials used have S3 PutObject permission for the target bucket. If you want, I can: • Provide the exact pip package name and imports if your project uses a specific LiveKit Python SDK version. • Show how to trigger this automatically from a
room_started
webhook and parse the
egress_ended
webhook to get the final S3 URL. Which would you prefer? Sources: Universal Egress | sip | livekit/livekit_composite | DeepWiki | Python SDKs | livekit/livekit_composite | DeepWiki