straight-jelly-92105
11/01/2025, 3:57 PMtall-airline-16756
11/01/2025, 3:57 PMtall-airline-16756
11/01/2025, 3:58 PMroom_composite_egress isn’t directly available on the LiveKitAPI object. No worries—we can fix this by accessing the egress functionality through the dedicated egress service client. Let me walk you through how to do that:
Correct Usage:
from livekit import api
from livekit.protocol.egress import RoomCompositeEgressRequest
# Initialize LiveKit API
lkapi = api.LiveKitAPI(
url=os.getenv("LIVEKIT_URL"),
api_key=os.getenv("LIVEKIT_API_KEY"),
api_secret=os.getenv("LIVEKIT_API_SECRET")
)
# Access the egress service
egress_service = lkapi.egress
# Create a recording request
recording_request = RoomCompositeEgressRequest(
room_name=room_id,
layout="speaker-dark",
file=api.EncodedFileOutput(
file_type=api.EncodedFileType.MP4,
filepath=recording_path
)
)
# Start the recording
try:
egress_info = await egress_service.start_room_composite_egress(recording_request)
print(f"Started recording with ID: {egress_info.egress_id}")
except Exception as e:
print(f"Failed to start recording: {e}")
Also, just a quick reminder to make sure your SDK is up-to-date, since older versions might not support these method signatures. And don’t forget to check that your API keys have the room_record permission enabled—that’s essential for this to work smoothly.
Regarding committing data to PostgreSQL at the end of the call, you’re on the right track! Using ctx.add_shutdown_callback to finalize the session and save transcripts is exactly how it should be done. Just double-check that your finalize_session function is being called properly during the shutdown process.
Sources: cmd/lk/egress.go | livekit-protocol/livekit/protocol/egress.pyi | packages/livekit-server-sdk/src/EgressClient.ts | lib/livekit/egress_service_client.rb | Recording and export | LiveKit docsstraight-jelly-92105
11/01/2025, 4:19 PMtall-airline-16756
11/01/2025, 4:20 PMroomRecord grant in your access token. Let me walk you through how you can do this:
Example in Python:
from livekit import AccessToken, VideoGrant
# Create a video grant with recording permissions
grant = VideoGrant(room_record=True)
# Generate an access token
access_token = AccessToken(
api_key="your-api-key",
api_secret="your-api-secret",
grants=grant
)
# Add additional details if needed
access_token.identity = "user-identity"
access_token.ttl = 3600 # Token validity in seconds
token = access_token.to_jwt()
print(f"Generated token: {token}")
Just be sure to replace your-api-key and your-api-secret with your actual API credentials. This token will then have the permissions needed to start and manage recordings smoothly.
If you'd like, I’m here to help with more examples in other programming languages or any other questions you might have. Just let me know!
Sources: packages/livekit-server-sdk/README.md | Managing participants | LiveKit docs | Authentication | LiveKit Docs | src/main/kotlin/io/livekit/server/VideoGrant.kt | Sources/LiveKit/Token/JWT.swiftstraight-jelly-92105
11/01/2025, 4:26 PMtall-airline-16756
11/01/2025, 4:26 PMVideoGrants object. For instance, if you'd like to add recording permissions, you can update your code like this:
token = (
api.AccessToken(settings.livekit_api_key, settings.livekit_api_secret)
.with_identity(request.identity)
.with_grants(api.VideoGrants(
room_join=True,
room=request.room_name,
room_record=True # Add recording permission here
))
.with_room_config(
api.RoomConfiguration(
agents=[api.RoomAgentDispatch(agent_name=request.agent_id)]
)
)
)
logger.info(f"key: {settings.livekit_api_key}, secret: {settings.livekit_api_secret}")
jwt_token = token.to_jwt()
This way, the generated token will include the room_record grant, enabling it to start and manage recordings smoothly. Feel free to add any other grants you might need by including them in the VideoGrants object.
If you have any questions or need more help, just let me know—I’m here to support you!straight-jelly-92105
11/01/2025, 4:29 PMtall-airline-16756
11/01/2025, 4:30 PMuser_input_transcribed event to capture user transcripts as they happen. For example:
@session.on("user_input_transcribed")
def on_transcript(transcript):
if transcript.is_final:
print(f"Final transcript: {transcript.transcript}")
• Also, the session.history property is super helpful for getting the entire conversation history, including all user and agent messages:
history = session.history
for item in history:
print(item.text_content)
2. Ensure Final Transcript Capture:
• To make sure you’re capturing the final transcripts before ending the session, you can use commit_user_turn() to explicitly flush STT buffers like this:
session.commit_user_turn(
transcript_timeout=5.0, # Wait up to 5 seconds for final transcript
stt_flush_duration=2.0 # Duration of silence to flush STT buffer
)
• It’s also a great idea to implement a shutdown callback that captures the complete conversation state before the session closes, for example:
def capture_final_state():
final_history = session.history
current_transcript = session.current_transcript if hasattr(session, 'current_transcript') else ""
# Save to file or database
with open("final_session_data.json", "w") as f:
json.dump({
"conversation_history": final_history,
"final_transcript": current_transcript,
"timestamp": time.time()
}, f)
session.add_shutdown_callback(capture_final_state)
Using these methods will help you reliably capture both real-time and final transcripts before your session ends. If you have any questions or need a bit more guidance, please don’t hesitate to ask—I’m here to help!
Sources: Session recording and transcripts | LiveKit Docs | livekit-agents/livekit/agents/tts/tts.pystraight-jelly-92105
11/01/2025, 4:49 PMtall-airline-16756
11/01/2025, 4:50 PMRoomCompositeEgressRequest does indeed record both user and agent audio by default. It captures all participant audio tracks in the room, including those from users and AI agents, and blends them together in the recording.
If you'd like to tailor how the audio is mixed, you can use the audioMixing option. For instance, setting audioMixing to DUAL_CHANNEL_AGENT will place the agent's audio in the left channel and all other participant audio (like the user's) in the right channel.
Please feel free to reach out if you'd like any more help with setting up your recording—I’m here to support you!
Sources: Custom recording templates | LiveKit docs | Composite and web recordings | LiveKit docs | livekit/livekit_egress.pb.go | livekit-protocol/src/livekit.rs | egress/recording_agent.pystraight-jelly-92105
11/01/2025, 4:53 PMtall-airline-16756
11/01/2025, 4:53 PMstraight-jelly-92105
11/01/2025, 4:53 PM