fresh-hospital-14455
08/18/2025, 8:41 PM# Recording the call & saving it to Google Cloud Storage.
file_contents = ""
with open("credentials.json", "r") as f:
file_contents = f.read()
random_string = "".join(random.choices(string.ascii_letters + string.digits, k=12))
unique_time = datetime.now().strftime("%Y-%m-%dT%H%M%S") + f"-{random_string}"
# Set up recording
req = api.RoomCompositeEgressRequest(
room_name=ctx.room.name,#"my-room",
layout="speaker",
audio_only=True,
file=api.EncodedFileOutput(
filepath=f"{ctx.room.name}/agent-{unique_time}.ogg",
gcp=api.GCPUpload(
credentials=file_contents,
bucket="livekit-agent-recorder",
),
),
)
res = await ctx.api.egress.start_room_composite_egress(req)
The above code saves the user<>agent interaction into Cloud storage. I have tested and it works fine. But the issue I'm having is that it requires me to give it the GCP Service account credentials file which is risky (security).
I have recently learned about Google Workload Identity Federation (WIF) and I'm interested to see how I can use the Google WIF instead of downloading the service account json file.
I'm keen to get your guidance on this. Thanks!