echoing-lamp-18687
11/27/2025, 5:45 AMtall-airline-16756
11/27/2025, 5:45 AMtall-airline-16756
11/27/2025, 5:46 AMechoing-lamp-18687
11/27/2025, 5:47 AMtall-airline-16756
11/27/2025, 5:47 AMechoing-lamp-18687
11/27/2025, 5:48 AMtall-airline-16756
11/27/2025, 5:48 AMimport 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?echoing-lamp-18687
11/27/2025, 5:50 AMtall-airline-16756
11/27/2025, 5:50 AM# 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?echoing-lamp-18687
11/27/2025, 5:51 AMtall-airline-16756
11/27/2025, 5:51 AMegress_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