Please give me the syntax for setting up egress to...
# ask-ai
m
Please give me the syntax for setting up egress to a GCP bucket in node js.
t
Thanks for reaching out, Alexander. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you want the Node.js syntax for starting egress to a GCP bucket. Below is a concise example using LiveKit’s EgressClient and the
startRoomCompositeEgress
call with a
file.gcp
output.
Copy code
const { EgressClient } = require('livekit-server-sdk');

const egressClient = new EgressClient({
  apiKey: process.env.LIVEKIT_API_KEY,
  apiSecret: process.env.LIVEKIT_API_SECRET,
  // optional: wsUrl if self-hosted, otherwise defaults to LiveKit cloud
  wsUrl: process.env.LIVEKIT_WS_URL,
});

async function startGcpEgress() {
  const resp = await egressClient.startRoomCompositeEgress({
    roomName: 'my-room',
    output: {
      file: {
        // template variables like ${room_name} and ${timestamp} are supported
        filepath: 'recordings/${room_name}/${timestamp}.mp4',
        gcp: {
          bucket: 'your-gcp-bucket-name',
          // optional: prefix within the bucket
          pathPrefix: 'recordings/',
          // optional: base64-encoded service account key if not using ADC
          // serviceAccountKey: process.env.GCP_SERVICE_ACCOUNT_KEY_BASE64,
        },
      },
    },
    // optional settings
    layout: 'speaker-dark',
    audioOnly: false,
  });

  console.log('Egress started, id:', resp.egressId);
  return resp;
}

startGcpEgress().catch(console.error);
Notes: •
output.file.gcp.bucket
is required. • If you don't use Application Default Credentials, include
serviceAccountKey
(base64) in
gcp
. • Template variables in
filepath
(e.g.,
${room_name}
,
${timestamp}
) are supported. If you want an example for a different egress type (track-level, single-stream, or SRT/HLS outputs) or need help encoding the service account key, tell me which one and I’ll provide that snippet. Sources: Universal Egress | server-sdk-js | livekit/livekit_composite | DeepWiki | Python SDKs | livekit/livekit_composite | DeepWiki