is any method to connect vertex ai api to live kit
# ask-ai
r
is any method to connect vertex ai api to live kit
t
Thanks for reaching out, Av. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! To connect Vertex AI API to LiveKit, you can easily use the LiveKit Google plugin. Here’s a quick rundown to get you started: 1. Install the Plugin: Just run the command that fits your setup: ◦ Node.js:
npm install @livekit/agents-plugin-google
◦ Python:
pip install "livekit-agents[google]~=1.2"
1. Set Up Authentication: Make sure to set the
GOOGLE_APPLICATION_CREDENTIALS
environment variable to your service account key file. Also, double-check that the Vertex AI API is enabled in your Google Cloud project. 2. Initialize the LLM: Use the
LLM
class with
vertexai=True
to connect with Vertex AI. Here’s a quick example:
Copy code
from livekit.plugins import google

google_llm = google.LLM(
  model="gemini-1.5-pro",
  vertexai=True,
  project="your-project-id",
  location="us-central1"
)
3. Optional: If you want to have real-time voice conversations, you can use the
RealtimeModel
class with Vertex AI. If you hit any bumps or want me to walk you through any of these steps, just let me know—I’m here to help! Sources: Google integration guide | LiveKit Docs | Google AI and LiveKit | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/gemini_t... | Google Gemini integration guide | LiveKit Docs | plugins/google/src/beta/realtime/realtime_api.ts
r
print('gemini api key',os.getenv("GOOGLE_API_KEY")) class Assistant(Agent): def __init__(self) -> None: super().__init__(instructions=instructions) async def entrypoint(ctx: agents.JobContext): session = AgentSession( # llm=openai.realtime.RealtimeModel(model="gpt-4o-mini-realtime-preview",modalities=["text"]), # tts=elevenlabs.TTS( # voice_id="KU7fyKrDK75F9nWiORJr", # model="eleven_multilingual_v2", # api_key=os.getenv("ELEVENLABS_API_KEY"), # ), # tts=groq.TTS( # model="playai-tts", # voice="Calum-PlayAI", # ), # tts=deepgram.TTS( # model="aura-2-aries-en", # ), # tts=openai.TTS( # model="tts-1", # voice="alloy", # ), # tts=openai.TTS( # model="tts-1", # voice="ash", # ), llm=google.beta.realtime.RealtimeModel( # model="gemini-2.5-flash-preview-native-audio-dialog", # model="gemini-2.5-flash-exp-native-audio-thinking-dialog", model="gemini-2.5-flash-preview-native-audio-dialog", # model="gemini-2.0-flash-exp", voice="Puck", # voice="Charon", temperature=0.3, ), # llm=openai.realtime.RealtimeModel(model="gpt-4o-realtime-preview") ) # session = AgentSession( # llm=openai.realtime.RealtimeModel() # ) # session = AgentSession(`` # # llm=openai.LLM(model="gpt-4o-mini"), # llm=groq.LLM(model="openai/gpt-oss-20b"), # stt=deepgram.STT(model="nova-3", language="en"), # # tts=groq.TTS( # # model="groq/playai-tts", # # voice="Arista-PlayAI", # # api_key=os.getenv("GROQ_API_KEY"), # # ), # tts=openai.TTS( # model="tts-1", # voice="alloy", # # voice="onyx", # ), # # tts=openai.TTS( # # model="tts-1", # # voice="alloy", # # ), # # tts=elevenlabs.TTS( # # voice_id="KU7fyKrDK75F9nWiORJr", # # model="eleven_multilingual_v2", # # api_key=os.getenv("ELEVENLABS_API_KEY"), # # ), # turn_detection=MultilingualModel(), # # vad=ctx.proc.userdata["vad"], # preemptive_generation=True, # ) await session.start( room=ctx.room, agent=Assistant(), room_input_options=RoomInputOptions( # For telephony applications, use
BVCTelephony
instead for best results noise_cancellation=noise_cancellation.BVC(), ), ) # await session.generate_reply( # instructions="Greet the user and offer your assistance." # ) if name == "__main__": agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint,port=1100)) this is my current code
t
Thanks so much for sharing your code! Could you tell me a bit more about what’s going on? Are you running into an error, or maybe looking for some help with setting things up or making the code run smoother? I’m here to help!
r
give me updated code
t
Here’s an updated example of how you can integrate the Vertex AI API with LiveKit using Python. I’ve included some comments to help you follow along:
Copy code
import os
from livekit.plugins import google
from livekit.plugins.google.beta.realtime import RealtimeModel

# Setting up the LLM instance for Vertex AI
llm_instance = google.LLM(
    model="gemini-2.0-flash-exp",  # Just an example model
    vertexai=True,
    project="your-project-id",    # Swap this with your actual Google Cloud project ID
    location="us-central1"        # Default location
)

# Setting up the RealtimeModel for real-time interactions
realtime_model = RealtimeModel(
    modalities=["AUDIO", "TEXT"],  # This lets you handle both audio and text
    model="gemini-2.0-flash-exp",
    voice="Puck",
    temperature=0.8,
    instructions="You are a helpful assistant",
    vertexai=True,
    project="your-project-id",
    location="us-central1"
)

# Don’t forget to set GOOGLE_APPLICATION_CREDENTIALS to your service account key file
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/your/service-account-key.json"
Just replace
your-project-id
and
path/to/your/service-account-key.json
with your actual Google Cloud project ID and the path to your service account key file. If you have any questions or want me to walk you through anything else, just let me know—I’m here to help! Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/gemini_t... | Google AI and LiveKit | LiveKit Docs | Google Gemini integration guide | LiveKit Docs | Gemini Live API integration guide | LiveKit Docs | Google integration guide | LiveKit Docs
r
i want to use realtime model
t
Hey there! If you want to use the RealtimeModel with Vertex AI in LiveKit, here’s a fresh example to help you get started:
Copy code
import os
from livekit.plugins.google.beta.realtime import RealtimeModel

# Setting up the RealtimeModel for real-time interactions
realtime_model = RealtimeModel(
    modalities=["AUDIO", "TEXT"],  # This lets you handle both audio and text
    model="gemini-2.5-flash-preview-native-audio-dialog",  # Just an example model
    voice="Puck",
    temperature=0.3,  # Controls how creative the responses are
    instructions="You are a helpful assistant",
    vertexai=True,
    project="your-project-id",  # Swap this with your Google Cloud project ID
    location="us-central1"  # Default location
)

# Don’t forget to set GOOGLE_APPLICATION_CREDENTIALS to your service account key file
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/your/service-account-key.json"
Just replace
your-project-id
and
path/to/your/service-account-key.json
with your actual Google Cloud project ID and the path to your service account key file. If you hit any bumps or want a hand with this, just give me a shout—I’m here to help!