```lkapi = api.LiveKitAPI() await lkapi.egress.sto...
# ask-ai
e
Copy code
lkapi = api.LiveKitAPI()
await lkapi.egress.stop_egress(
    api.StopEgressRequest(egress_id=self.egress_id)
)
await lkapi.aclose()
Is this correct way to close the egress ? I get this error 2025-12-17 022240,821 - ERROR - Failed to stop egress recording: TwirpError(code=failed_precondition, message=egress with status EGRESS_COMPLETE cannot be stopped, status=412)
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're calling the API correctly, but the error shows the egress has already finished so it cannot be stopped. What to do next: • Check egress status before calling stop. Only call stop when status is
EGRESS_ACTIVE
or
EGRESS_STARTING
.
Copy code
list_resp = await lkapi.egress.list_egress()
  for e in list_resp.items:
      if e.egress_id == self.egress_id:
          if e.status in ["EGRESS_ACTIVE", "EGRESS_STARTING"]:
              await lkapi.egress.stop_egress(api.StopEgressRequest(egress_id=self.egress_id))
          else:
              print(f"Egress already ended with status: {e.status}")
          break
• Or catch the failed_precondition error and ignore it when the message indicates `EGRESS_COMPLETE`:
Copy code
try:
      await lkapi.egress.stop_egress(api.StopEgressRequest(egress_id=self.egress_id))
  except Exception as err:
      if "EGRESS_COMPLETE" in str(err) and "failed_precondition" in str(err):
          print("Egress already completed; nothing to stop.")
      else:
          raise
• Best practice: stop egress proactively (for agent sessions) when the participant leaves or delete the room, or trigger stop via the
participant_left
webhook so you don't attempt stopping after completion. If you want, share the egress status you see from
list_egress()
and I can suggest the exact next step. Sources: Egress API | LiveKit docs | Quotas and limits | LiveKit docs | Webhooks | LiveKit docs
e
how many recording options are available like grid, speaker etc
t
You're asking about available recording layout options for Room Composite egress. Default layouts: • grid — tiled view of all participants • speaker — highlights the current speaker with others in a carousel • single-speaker — focuses on one speaker with smaller views for others You can append -light (e.g.,
grid-light
) to use a white background. You can also build fully custom layouts by supplying a custom recording template (
custom_base_url
) and modifying the default templates. Would you like examples of the layout names to pass in your egress request or guidance on creating a custom template? Sources: RoomComposite Egress | LiveKit Docs | Custom recording templates | LiveKit docs
e
i used speaker, but it only shows the currently speaking speaker not others in carousel
t
You're right to expect the speaker layout to show other participants in a carousel. If you're only seeing the current speaker, the most likely causes and fixes are: • Participants must be publishing video. The layout only shows participants with active video tracks—confirm others have their camera on. • Verify the egress uses the default
speaker
template (not a custom template that omits the carousel). If you use a custom
custom_base_url
, ensure it includes the non-speaker carousel logic (e.g.,
CarouselLayout
). • Confirm the egress/headless browser is seeing new participants. Start egress while multiple publishers are active, or test with multiple simulated publishers to verify dynamic updates. • Inspect template logs/DOM in headless Chrome (add console logs in your template) to confirm non-speaking participant tracks are rendered. Quick checks you can run now: 1. Use
list_egress()
or your app's view to confirm other participants are in the room and publishing video. 2. Start a test egress with the default
speaker
layout and multiple cameras to see expected behavior. 3. If using a custom template, share the template code for the participant rendering section and I can point out what to change. Which of these would you like to try first, or do you want to paste your template's participant-rendering code? Sources: RoomComposite Egress | LiveKit Docs | Custom recording templates | LiveKit docs
e
only one is publishing the video, rest is just using audio
t
Because only one participant is publishing video, the default
speaker
layout will show only that video feed. The speaker template displays participants that have active video tracks; audio‑only participants are not rendered in the video carousel. Options to get the view you want: • Enable video for other participants so they appear in the carousel. • Use a custom template that renders audio‑only participants as avatars/placeholders (or shows their names) and include them in the carousel. You can modify the default template to add placeholder tiles for participants with no video. • Use the
grid
layout (or
grid-light
) if you prefer a tiled view — it still requires video to show real video tiles, but a custom grid template can show placeholders for audio-only users. If you want, I can: • Show the specific part of the default template to modify to include audio-only placeholders, or • Provide a small snippet that renders a placeholder tile when a participant has no video. Which would you like?
c
@enough-match-43171 did you figure this out?
t
Thanks — quick check-in: did you (Aditya) want me to send a snippet to render placeholders for audio-only participants, or would you prefer I show the exact part of the default template to modify? I can: • Provide a small template snippet that renders avatar/name tiles for audio-only users, or • Point out where to add that logic in the default speaker template. Which would you like?
e
Which one, the placeholder one or the recording egress closing error ? For the error, i am trusting the livekit room lifecycle to shut down the egress recording for me, and it working so far, and for the speaker layout, since my product has only audio communication with a screen share, so speaker layout is not possible, so sticking to grid only.
t
Thanks — quick confirmation and a couple of brief suggestions. Regarding the stop‑egress error: that error happens because the egress has already completed (EGRESS_COMPLETE) and therefore cannot be stopped. It’s safe to rely on the room lifecycle to end egress if that’s working for you. If you ever want to call stop programmatically, first check the egress status (only call stop when status is EGRESS_ACTIVE or EGRESS_STARTING) or handle the failed_precondition/EGRESS_COMPLETE error and ignore it. Regarding layout for audio-only + screen share: the speaker layout requires other participants to publish video, so it’s not suitable for audio-only participants. Using the grid layout is the right choice. If you want placeholders for audio-only participants in the recording, you can either: • Modify the default template to render avatar/name tiles for participants without video, or • Use a custom template (via
custom_base_url
) that shows screen share plus placeholder tiles. If you’d like, I can send a small snippet that renders placeholder tiles for audio-only users in the template — would you like that?