Can use models/gemini-2.5-flash-native-audio-previ...
# ask-ai
d
Can use models/gemini-2.5-flash-native-audio-preview-09-2025 in livekit?
t
Thanks for reaching out, pradana. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Yes — you can use
models/gemini-2.5-flash-native-audio-preview-09-2025
in LiveKit via the Gemini Live API plugin. It’s supported as a realtime speech-to-speech model for LiveKit Agents. Example usage: Python
Copy code
from livekit.plugins import google

session = AgentSession(
    llm=google.realtime.RealtimeModel(
        model="gemini-2.5-flash-native-audio-preview-09-2025",
        voice="Puck",
    ),
)
Node.js
Copy code
import * as google from '@livekit/agents-plugin-google';

const session = new voice.AgentSession({
  llm: new google.realtime.RealtimeModel({
    model: "gemini-2.5-flash-native-audio-preview-09-2025",
    voice: "Puck",
  }),
});
The model supports features like thinking mode via
thinking_config
for low-latency two-way voice interactions. Would you like an example showing
thinking_config
or guidance on voice/encoding settings? Sources: Gemini Live API plugin | LiveKit docs
d
using gemini from ai studio insead of vertex?
t
Yes — you can use Gemini from AI Studio (the Gemini API) instead of Vertex AI with LiveKit. To do this: 1. Set
GOOGLE_API_KEY
to your AI Studio API key. 2. Ensure
vertexai
is false (or omit it). 3. Configure your AgentSession to use the Gemini model (for example
gemini-2.5-flash-native-audio-preview-09-2025
). Example (Python):
Copy code
from livekit.plugins import google

session = AgentSession(
  llm=google.realtime.RealtimeModel(
    model="gemini-2.5-flash-native-audio-preview-09-2025",
    voice="Puck",
  ),
)
This works for realtime speech-to-speech models and the same approach applies for
google.LLM
(non-realtime) usage. Would you like a sample showing
thinking_config
, or help setting the
GOOGLE_API_KEY
and auth flow for your environment? Sources: Google Gemini LLM plugin guide | LiveKit Docs | Gemini Live API plugin | LiveKit docs | Google AI and LiveKit | LiveKit Docs
d
setting the
GOOGLE_API_KEY
and auth flow for your environment
t
You're asking how to set
GOOGLE_API_KEY
and the auth flow to use Gemini from AI Studio with LiveKit. Below are concise steps and examples. 1) Obtain an API key from AI Studio • Generate an API key in AI Studio (Gemini API) and copy the key. 2) Set
GOOGLE_API_KEY
in your environment • Local development (macOS/Linux): ◦ Run:
export GOOGLE_API_KEY="YOUR_API_KEY"
• Local development (Windows PowerShell): ◦ Run:
$Env:GOOGLE_API_KEY = "YOUR_API_KEY"
• In a container or deployment: ◦ Add
GOOGLE_API_KEY
to your container environment variables, deployment manifest, or secret store used by your platform. 3) Configure LiveKit Google plugin to use Gemini API • Do not enable Vertex AI (leave
vertexai
false or omit it). With
GOOGLE_API_KEY
set, the plugin will call the Gemini API (AI Studio). • Example (Python realtime model):
Copy code
from livekit.plugins import google

session = AgentSession(
  llm=google.realtime.RealtimeModel(
    model="gemini-2.5-flash-native-audio-preview-09-2025",
    voice="Puck",
  ),
)
4) Auth flow and deployment notes • The API key in
GOOGLE_API_KEY
authenticates requests to the Gemini API (AI Studio). Ensure the key has the necessary Gemini API access enabled in your Google account/project. • Keep the API key secret: ◦ Store it in your cloud provider’s secret manager or environment-specific secret store. ◦ Do not commit the key to source control. • For production, use a secrets manager and restrict key usage (IP, referrer, or service restrictions) per your security needs. Would you like a short example showing how to load
GOOGLE_API_KEY
from a secrets manager for a specific platform (AWS, GCP Secret Manager, or Kubernetes)?
d
how to add tools for llm or
t
You're asking how to add tools for an LLM in LiveKit — do you mean custom function-style tools (server-side), built-in Gemini tools (like Google Search), or forwarding tool calls to a frontend via RPC? Tell me which of the following matches your goal: • Add server-side tools (custom functions) that the agent can call (show Python or Node example) • Enable Gemini built-in tools via the Gemini API • Dynamically load tools from an MCP server • Forward tool calls to a client/frontend (RPC) • Something else (briefly describe) Which language do you want examples for: Python or Node.js? Sources: Tool definition and use | LiveKit docs | Google Gemini LLM plugin guide | LiveKit Docs | Gemini Live API plugin | LiveKit docs
d
• Enable Gemini built-in tools via the Gemini API • Dynamically load tools from an MCP server • Forward tool calls to a client/frontend (RPC)
t
Responding about enabling Gemini built-in tools, MCP dynamic tools, and RPC forwarding — here are concise, actionable steps and examples. 1) Enable Gemini built-in tools (Gemini API / AI Studio) • Set
GOOGLE_API_KEY
to your AI Studio API key and ensure
vertexai
is false or omitted. • Pass tool instances to the LLM: ◦ Python (realtime):
Copy code
from livekit.plugins import google
    from google.genai import types

    session = AgentSession(
      llm=google.realtime.RealtimeModel(
        model="gemini-2.5-flash-native-audio-preview-09-2025",
        _gemini_tools=[types.GoogleSearch(), types.ToolCodeExecution()],
      ),
    )
• Node.js (realtime):
Copy code
import * as google from '@livekit/agents-plugin-google';

    const session = new voice.AgentSession({
      llm: new google.realtime.RealtimeModel({
        model: "gemini-2.5-flash-native-audio-preview-09-2025",
        geminiTools: [new google.types.GoogleSearch(), new google.types.ToolCodeExecution()],
      }),
    });
• Supported built-in tools include GoogleSearch, GoogleSearchRetrieval, ToolCodeExecution, UrlContext, GoogleMaps. • You can also enable these for non-realtime
google.LLM
via
gemini_tools
. 2) Dynamically load tools from an MCP server (Python only) • Install MCP extras: uv add livekit-agents[mcp]~=1.2 • Provide MCP server(s) to your session; tools are fetched automatically:
Copy code
from livekit.agents import mcp, AgentSession

  session = AgentSession(
    mcp_servers=[mcp.MCPServerHTTP("https://your-mcp-server.com")],
    # llm, stt, tts...
  )
• MCP integration is available in Python only; tools returned by the MCP server become available to the agent at runtime. 3) Forward tool calls to client/frontend via RPC • Implement a tool that calls
perform_rpc()
from the agent to the participant, then register an RPC handler on the client. ◦ Backend tool (Python example):
Copy code
from livekit.agents import function_tool, get_job_context, RunContext, ToolError
    import json

    @function_tool()
    async def get_user_location(context: RunContext, high_accuracy: bool = False):
        try:
            room = get_job_context().room
            participant = next(iter(room.remote_participants.values()))
            response = await room.local_participant.perform_rpc(
                destination_identity=participant.identity,
                method="getUserLocation",
                payload=json.dumps({"highAccuracy": high_accuracy}),
                response_timeout=10.0,
            )
            return response
        except Exception:
            raise ToolError("Could not retrieve user location")
• Client (browser) RPC handler:
Copy code
room.localParticipant.registerRpcMethod('getUserLocation', async (data) => {
      const { highAccuracy, responseTimeout } = JSON.parse(data.payload);
      const pos = await new Promise((res, rej) =>
        navigator.geolocation.getCurrentPosition(res, rej, { enableHighAccuracy: highAccuracy, timeout: responseTimeout })
      );
      return JSON.stringify({ latitude: pos.coords.latitude, longitude: pos.coords.longitude });
    });
• Key points: serialize payloads, handle timeouts, and select the correct destination participant identity. 4) Auth notes (quick) • AI Studio / Gemini API: set
GOOGLE_API_KEY
env var or pass
api_key
to the LLM. • Vertex AI: set
GOOGLE_APPLICATION_CREDENTIALS
to your service account JSON and use
vertexai=True
. If you want, I can: • Provide a full working Python or Node example that combines Gemini tools + MCP + an RPC tool, or • Show how to secure
GOOGLE_API_KEY
using a specific secrets manager (Kubernetes, GCP Secret Manager, or AWS Secrets Manager). Which would you like? Sources: Google Gemini LLM plugin guide | LiveKit Docs | Gemini Live API plugin | LiveKit docs | Tool definition and use | LiveKit docs