red-dentist-96118
12/12/2025, 3:15 PMtall-airline-16756
12/12/2025, 3:15 PMtall-airline-16756
12/12/2025, 3:16 PMred-dentist-96118
12/12/2025, 9:13 PMtall-airline-16756
12/12/2025, 9:13 PMroomRecord token) setup.red-dentist-96118
12/12/2025, 9:13 PMtall-airline-16756
12/12/2025, 9:14 PMroom_create. Admin API key/secret includes egress permissions so auto egress will run.
2) Minimal Python example (CreateRoom with auto egress to S3)
import os
import time
import jwt
import requests
import json
LIVEKIT_HOST = "https://your-livekit-host.com" # Replace
API_KEY = os.getenv("LIVEKIT_API_KEY")
API_SECRET = os.getenv("LIVEKIT_API_SECRET")
ROOM_UUID = "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8" # use your UUID
S3_BUCKET = os.getenv("AWS_BUCKET_NAME")
S3_REGION = os.getenv("AWS_REGION")
S3_ACCESS = os.getenv("AWS_ACCESS_KEY_ID")
S3_SECRET = os.getenv("AWS_SECRET_ACCESS_KEY")
def create_jwt(api_key, api_secret, ttl=600):
now = int(time.time())
payload = {"iss": api_key, "sub": api_key, "nbf": now, "exp": now + ttl, "room_create": True}
return jwt.encode(payload, api_secret, algorithm="HS256")
token = create_jwt(API_KEY, API_SECRET)
payload = {
"name": ROOM_UUID,
"egress": {
"room": {
"audio_only": True,
"file": {
"filepath": f"recordings/{ROOM_UUID}.ogg",
"s3": {
"access_key": S3_ACCESS,
"secret": S3_SECRET,
"bucket": S3_BUCKET,
"region": S3_REGION
}
}
}
}
}
resp = requests.post(
f"{LIVEKIT_HOST}/twirp/livekit.RoomService/CreateRoom",
headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
data=json.dumps(payload),
timeout=15
)
if resp.status_code == 200:
print(f"Room {ROOM_UUID} created with auto audio recording to S3.")
else:
print("CreateRoom failed:", resp.status_code, resp.text)
Notes:
• audio_only: true produces a single mixed audio file (typically OGG/Opus) saved to the specified S3 path.
• Filename uses the room UUID in the example; change filepath if you prefer a different path/extension.
• Ensure your LiveKit host URL and AWS creds/bucket are correct and that the LiveKit key/secret used can create rooms.
• If you prefer a different audio format or filename extension, adjust filepath and confirm LiveKit supports the desired format for audio-only egress.
Would you like this example adapted to use the LiveKit Python client library instead of the HTTP/Twirp call, or help generating the JWT token with a specific library?
Sources: RoomComposite Egress | LiveKit Docs | Auto egress | LiveKit docs | Egress API | LiveKit docsred-dentist-96118
12/12/2025, 9:15 PMtall-airline-16756
12/12/2025, 9:15 PM{
"room_name": "your-room-uuid",
"audio_only": true,
"file_outputs": [
{
"filepath": "recordings/{room_name}-{time}.ogg",
"s3": {
"access_key": "YOUR_AWS_ACCESS_KEY_ID",
"secret": "YOUR_AWS_SECRET_ACCESS_KEY",
"region": "YOUR_AWS_REGION",
"bucket": "YOUR_S3_BUCKET"
}
}
]
}
• Start egress:
lk egress start --type room-composite audio-record.json
This will mix all participant audio into one OGG file and upload to S3. The egress stops automatically when the room ends.
2) Auto-start on room creation (agent or CLI can POST CreateRoom)
• Use this CreateRoom payload so recording begins as soon as the room is created:
{
"name": "your-room-uuid",
"egress": {
"room": {
"audio_only": true,
"file_outputs": [
{
"filepath": "recordings/{room_name}.ogg",
"s3": {
"access_key": "YOUR_AWS_ACCESS_KEY_ID",
"secret": "YOUR_AWS_SECRET_ACCESS_KEY",
"region": "YOUR_AWS_REGION",
"bucket": "YOUR_S3_BUCKET"
}
}
]
}
}
}
• POST to the RoomService CreateRoom endpoint with an admin token:
curl -X POST https://<LIVEKIT_HOST>/twirp/livekit.RoomService/CreateRoom \
-H "Authorization: Bearer <ADMIN_TOKEN>" \
-H "Content-Type: application/json" \
--data-binary @create-room.json
This creates the room and immediately starts the audio-only composite egress that uploads to S3.
Notes and reminders
• Use an admin API key/secret (or a token that has room_create and egress privileges) for CreateRoom/auto-egress.
• audio_only: true produces a single mixed audio track (commonly OGG/Opus); change filepath extension if you need a different container.
• If you want this entirely driven by your agent runner, have the agent call CreateRoom with the payload above when provisioning the room.
Would you like:
• a templated shell script that your agent runner can call, or
• the same example converted to a small agent-runner Python snippet that posts CreateRoom? Sources: Egress output types | LiveKit docs | Composite and web recordings | LiveKit docs | Egress API | LiveKit docs | server-sdk-js | livekit/livekit_composite | DeepWiki | Observability data hooks | LiveKit docsred-dentist-96118
12/12/2025, 9:16 PMlkapi = api.LiveKitAPI()
await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name=call_id,
room=call_id,
metadata=f'{{"phone_numbers": {json.dumps(phone_numbers)}}}',
)
)
await lkapi.aclose()tall-airline-16756
12/12/2025, 9:17 PMcreate_dispatch. Below is a minimal Python example that integrates into your agent flow: it first creates the room with audio-only auto egress to S3, then creates the dispatch.
import json
import asyncio
from livekit import api
async def create_room_and_dispatch(call_id: str, phone_numbers: list):
lkapi = api.LiveKitAPI(url="https://your-livekit-host", api_key="API_KEY", api_secret="API_SECRET")
s3 = api.S3Upload(
bucket="YOUR_S3_BUCKET",
region="YOUR_AWS_REGION",
access_key="YOUR_AWS_ACCESS_KEY_ID",
secret="YOUR_AWS_SECRET_ACCESS_KEY",
)
# Auto egress: mixed audio-only file to S3
room_egress = api.RoomEgress(
audio_only=True,
file_outputs=[
api.EncodedFileOutput(
filepath=f"recordings/{call_id}.m4a",
s3=s3,
)
],
)
# Create room with auto egress so recording starts immediately
await lkapi.room.create_room(name=call_id, egress=room_egress)
# Now create the agent dispatch (room already exists / egress started)
await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name=call_id,
room=call_id,
metadata=json.dumps({"phone_numbers": phone_numbers}),
)
)
await lkapi.aclose()
# usage
# asyncio.run(create_room_and_dispatch("your-room-uuid", ["+1555..."]))
If you prefer to keep your current dispatch-first flow, instead call the Egress API after dispatch to start recording:
• Use lkapi.egress.start_room_composite_egress(...) with audio_only=True and an S3 EncodedFileOutput.
• That approach works but can race with room creation/joins — creating the room with egress avoids that.
Do you want the post-dispatch example (start egress after create_dispatch) or a shell/CLI variant?
Sources: Auto egress | LiveKit docs | RoomComposite Egress | LiveKit Docs | Composite and web recordings | LiveKit docs | Egress API | LiveKit docsred-dentist-96118
12/12/2025, 9:18 PMtall-airline-16756
12/12/2025, 9:19 PMcli.run_app(...), the room is usually created by dispatch. To ensure audio-only recording to S3 starts immediately, create the room with Auto Egress before you call create_dispatch (so recording begins at room creation). Minimal change to your flow:
1) Create room with audio-only auto egress to S3, then 2) Create the dispatch (agent joins the already-created room).
Example (matches your agent usage):
from livekit import api
import json
import asyncio
async def prepare_and_dispatch(call_id: str, phone_numbers: list):
lkapi = api.LiveKitAPI(url="https://your-livekit-host", api_key="API_KEY", api_secret="API_SECRET")
s3 = api.S3Upload(
bucket="YOUR_S3_BUCKET",
region="YOUR_AWS_REGION",
access_key="YOUR_AWS_ACCESS_KEY_ID",
secret="YOUR_AWS_SECRET_ACCESS_KEY",
)
# Auto egress: mixed audio-only to S3
room_egress = api.RoomEgress(
audio_only=True,
file_outputs=[
api.EncodedFileOutput(
filepath=f"recordings/{call_id}.m4a",
s3=s3,
)
],
)
# 1) Create room with auto egress so recording starts immediately
await lkapi.room.create_room(name=call_id, egress=room_egress)
# 2) Create the agent dispatch (agent will join the room)
await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name=call_id,
room=call_id,
metadata=json.dumps({"phone_numbers": phone_numbers}),
)
)
await lkapi.aclose()
If you prefer to keep dispatch-first, start egress after dispatch with:
• lkapi.egress.start_room_composite_egress(..., audio_only=True, file_outputs=[...s3...])
but expect a small gap before recording starts.
Do you want the post-dispatch egress snippet or a ready-to-run shell/CLI command for your pipeline?
Sources: Auto egress | LiveKit docs