start raise AnamException( livekit.plugins.ana...
# ask-ai
c
start raise AnamException( livekit.plugins.anam.errors.AnamException: livekit_url, livekit_api_key, and livekit_api_secret must be set by arguments or environment variables i have connections variables
t
Thanks for reaching out, ZaidKaraymeh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like the error is happening because the LiveKit credentials (livekit_url, livekit_api_key, and livekit_api_secret) aren’t set up quite right. No worries though—here’s a simple way to fix it: 1. Set Environment Variables: Make sure you’ve set these environment variables with your LiveKit details:
Copy code
export LIVEKIT_URL=<your-livekit-server-url>
export LIVEKIT_API_KEY=<your-api-key>
export LIVEKIT_API_SECRET=<your-api-secret>
2. Pass as Arguments: Or, if you prefer, you can pass these directly when you create the AnamAvatarSession:
Copy code
avatar_session = AnamAvatarSession(
    livekit_url="your-livekit-url",
    livekit_api_key="your-api-key",
    livekit_api_secret="your-api-secret"
)
3. Verify Environment Variables: Just double-check that these variables are set and accessible in your environment by running:
Copy code
echo $LIVEKIT_URL
echo $LIVEKIT_API_KEY
echo $LIVEKIT_API_SECRET
4. Troubleshooting: Here are a few quick things to look out for: ◦ Make sure the environment variable names are spelled exactly right (they’re case-sensitive). ◦ Confirm your LiveKit server URL is correct and reachable. ◦ Check that your API key and secret are valid and have the right permissions. If you hit any snags or want me to walk you through it, just let me know—I’m here to help! Sources: examples/.env.example
c
anam_avatar = anam.AvatarSession( TypeError: AvatarSession.__init__() got an unexpected keyword argument 'livekit_url'
t
Hey! The error you're seeing happens because the
AvatarSession
constructor doesn’t take a
livekit_url
parameter. Instead, you’ll want to pass
livekit_url
,
livekit_api_key
, and
livekit_api_secret
to the
start()
method. Here’s how you can do it:
Copy code
async def entrypoint(ctx: JobContext):
    session = AgentSession(
        # ... stt, llm, tts, etc.
    )

    anam_avatar = anam.AvatarSession(
        persona_config=anam.PersonaConfig(
            name="avatar",
            avatarId="your-avatar-id",  # Just swap this with your avatar ID
        ),
        api_key="your-api-key",  # And your Anam API key here
    )

    await anam_avatar.start(
        session, 
        room=ctx.room,
        livekit_url="your-livekit-url",  # Put the livekit_url here
        livekit_api_key="your-livekit-api-key",
        livekit_api_secret="your-livekit-api-secret"
    )
So, just be sure to take
livekit_url
out of the constructor and add it to the
start()
method instead. If you hit any snags or want me to walk you through it, just give me a shout! Sources: livekit-plugins/livekit-plugins-tavus/livekit/plugins/tavus/__init__.py
c
how to connect anam virtual avatar to a frontend of nextjs?
t
Hey there! To get your Anam virtual avatar connected to a Next.js frontend, here’s a friendly step-by-step guide to help you out: 1. Set Up the Anam Avatar in Your Agent:
pip install "livekit-agents[anam]~=1.2"
Next, pop your Anam API key into the
.env
file like this:
ANAM_API_KEY=your_anam_api_key
Then, create an Avatar Session in your agent code:
Copy code
from livekit.plugins import anam

async def entrypoint(ctx: JobContext):
    session = AgentSession(...)  # Initialize your agent session

    anam_avatar = anam.AvatarSession(
        persona_config=anam.PersonaConfig(
            name="your-avatar-name",
            avatarId="your-avatar-id",
        ),
    )
    
    await anam_avatar.start(session, room=ctx.room)
    await session.start(...)
2. Set Up the Next.js Frontend: Grab the Next.js Voice Agent starter app and set up your environment variables in
.env.local
like so:
Copy code
LIVEKIT_URL=your_livekit_url
LIVEKIT_API_KEY=your_livekit_api_key
LIVEKIT_API_SECRET=your_livekit_api_secret
3. Render the Avatar in the Frontend: Use LiveKit React components to show your avatar’s video and audio:
Copy code
import { useVoiceAssistant } from "@livekit/components-react";

function VoiceAssistant() {
    const {
        agent,
        audioTrack,
        videoTrack,
    } = useVoiceAssistant();

    return (
        <div>
            {videoTrack?.state === "publishing" && (
                <video ref={(video) => {
                    if (video) {
                        videoTrack?.attach(video);
                    }
                }} />
            )}
        </div>
    );
}
4. Run Your Application: Start up your Next.js dev server with:
Copy code
pnpm install
pnpm dev
Don’t forget to make sure your agent worker and LiveKit server are up and running too! If you hit any bumps or want me to walk you through anything, just give me a shout—I’m here to help!