I want to upload the agent’s conversation transcri...
# ask-ai
h
I want to upload the agent’s conversation transcripts to S3. It works fine locally, but after deploying to LiveKit Cloud, the files are not being uploaded. I just want to understand if there are any restrictions on uploading transcript files to S3 from the LiveKit Cloud environment.
t
Thanks for reaching out, Pavan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! When you're uploading files to S3 from LiveKit Cloud, there are a few important things to keep in mind: • AssumeRole Feature: The
assume_role_arn
field in the S3 configuration works only if this feature is turned on for your LiveKit Cloud account. If it’s not enabled, uploads using this method won’t go through. • Security Enforcement: For your safety, sensitive info like the
secret
key can’t be included in egress requests. Instead, it’s best to use IAM roles or set up credentials on the server side. • S3-Compatible Storage: LiveKit plays nicely with S3-compatible providers like MinIO or Oracle Cloud. Just a heads-up—if you’re using a non-AWS provider, make sure to set
force_path_style
to
true
in your config. Double-check that your account has the right features enabled and your setup follows these guidelines. If you run into any hiccups or want help with specific settings or error messages, just give me a shout—I’m here to help! Sources: pkg/config/storage.go | Egress output types | LiveKit Docs | livekit/livekit_egress.pb.go
h
Below is my agent code
Copy code
from dotenv import load_dotenv
from prompts import SESSION_INSTRUCTION, AGENT_INSTRUCTION
from datetime import datetime
import json
import os
import io
import boto3

from livekit import agents, api
from livekit.agents import AgentSession, Agent, RoomInputOptions, JobContext
from livekit.plugins import (
    openai,
    noise_cancellation,
)

# Load environment variables
load_dotenv(".env.local", override=True)

# --- Define your custom assistant ---
class Assistant(Agent):
    def __init__(self) -> None:
        super().__init__(instructions=AGENT_INSTRUCTION)


# --- Entrypoint for LiveKit Agent ---
async def entrypoint(ctx: JobContext):

    # --- Agent session setup ---
    session = AgentSession(
        llm=openai.realtime.RealtimeModel(
            voice="coral"
        )
    )

    # --- Shutdown tasks: upload transcript and notify frontend ---
    async def shutdown_tasks():
        # Convert session history to JSON bytes
        transcript_data = json.dumps(
            session.history.to_dict(),
            indent=2,
            ensure_ascii=False
        ).encode("utf-8")

        # Setup S3 client
        s3 = boto3.client(
            "s3",
            aws_access_key_id=os.getenv("S3_ACCESS_KEY"),
            aws_secret_access_key=os.getenv("S3_SECRET_KEY"),
            region_name=os.getenv("S3_REGION"),
        )

        # Generate S3 key
        current_date = datetime.now().strftime("%Y%m%d_%H%M%S")
        s3_key = f"AIAssistant/transcript_{ctx.room.name}_{current_date}.json"

        # Upload transcript directly from memory
        s3.upload_fileobj(io.BytesIO(transcript_data), os.getenv("S3_BUCKET"), s3_key)
        print(f"Transcript uploaded to S3: s3://{os.getenv('S3_BUCKET')}/{s3_key}")

        # Generate presigned URL
        presigned_url = s3.generate_presigned_url(
            "get_object",
            Params={"Bucket": os.getenv("S3_BUCKET"), "Key": s3_key},
            ExpiresIn=3600,  # URL valid for 1 hour
        )

        # Notify frontend via LiveKit data channel
        ctx.room.local_participant.publish_data(
            f"TRANSCRIPT_READY:{presigned_url}".encode("utf-8"),
            reliable=True,
        )
        print(f"Frontend notified with transcript URL: {presigned_url}")

    # Add shutdown callback
    ctx.add_shutdown_callback(shutdown_tasks)

    # Start the agent session
    await session.start(
        room=ctx.room,
        agent=Assistant(),
        room_input_options=RoomInputOptions(
            noise_cancellation=noise_cancellation.BVC(),
        ),
    )

    # Generate initial instructions/reply
    await session.generate_reply(
        instructions=SESSION_INSTRUCTION
    )


# --- Run locally if executed as main ---
if __name__ == "__main__":
    agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))
t
Hey there! I noticed your code uses
boto3
to upload transcripts to S3, which is great, but LiveKit Cloud has some specific requirements and restrictions for S3 uploads that are good to keep in mind: • LiveKit Cloud supports S3 uploads using access keys and secrets, but usually, this is handled through LiveKit’s egress system rather than directly with
boto3
. • Including sensitive credentials like
aws_secret_access_key
directly in your code might cause issues with LiveKit’s security validation. • For a safer and smoother experience, it’s best to use IAM roles (like
assume_role_arn
, if your account has it enabled) or manage secrets through your environment. If you want to dig deeper, it’s a good idea to check whether your LiveKit Cloud account has the right features enabled (such as IAM role assumption) and make sure your setup matches LiveKit’s egress system. Feel free to reach out if you’d like a hand tweaking your code to fit LiveKit’s supported methods—I’m here to help! Sources: egress/redact_test.go | Egress API | LiveKit Docs | cmd/lk/examples/web-egress.json | RoomComposite Egress | LiveKit Docs | Web Egress | LiveKit Docs
h
egree seems to be uploading only the mp4 files. i want the transcriptions
t
Hey there! Just a quick heads-up: LiveKit egress is great for uploading media files like MP4s, but it doesn’t directly support uploading transcription files. No worries though! You can use the LiveKit AI Agents framework to capture and process transcription data during your session. Here’s a simple way to make it work: 1. Capture Transcriptions: Use AI agent callbacks to grab the transcription text in real time. You can keep this text in memory or save it to an external service while the session is happening. 2. Upload Transcriptions: Once the session wraps up, you can upload the transcription file programmatically to your preferred storage (like S3 or GCP) using cloud SDKs such as
boto3
or
google-cloud-storage
. 3. Custom Logic: Add some custom logic in your agent to handle storing and uploading the transcription as part of shutting down the session. Since the egress service focuses on media exports, uploading transcriptions will need a bit of custom post-processing. If you’d like, I’m here to help you set this up or tweak your agent code—just let me know! Sources: Egress & Media Processing | livekit/livekit_composite | DeepWiki | Egress & Storage | livekit/livekit_composite | DeepWiki | Recording agent sessions | LiveKit Docs
h
do i need to do it in front end or backend?
t
Hey! Uploading transcription files is something you'd want to take care of on the backend. What you can do is add this logic right inside your LiveKit AI Agent's backend code. The agent can grab the transcription data while the session is happening and then upload it to your storage (like S3) once the session wraps up. If you'd like, I’m here to help you figure out how to set this up in your backend or tweak what you already have going on.
h
yes please tweak my code
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!