This message was deleted.
# ask-ai
s
This message was deleted.
t
Thanks for reaching out, Phanos. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd be happy to help you with this code snippet! Could you please share a bit more about what you're experiencing? Are you running into an error, or is there something specific you'd like to understand better about how it works?
r
How can i control the thinking budget for the new gemini native model? llm_instance = google.beta.realtime.RealtimeModel( model="gemini-2.5-flash-native-audio-preview-09-2025", voice=self.voice, temperature=1.0, instructions=realtime_instructions, )
t
Thank you for reaching out! I wanted to let you know that currently, there isn’t a supported way to control a "thinking budget" for the Gemini native model when using the Google RealtimeModel in LiveKit. The parameters you can adjust include
instructions
,
voice
,
temperature
, and a few others, but none specifically relate to a "thinking budget" setting. If you have more details or a particular scenario in mind, please don’t hesitate to share. I’m here to help and would be happy to assist you further! Sources: Gemini Live API plugin | LiveKit Docs
r
why? this is an option in gemini api
t
Thanks for reaching out! I wanted to share that the Gemini API does support a thinking budget option, but this feature isn’t available in the
RealtimeModel
class used for the Gemini Live API. The thinking budget is managed through the
thinking_config
parameter in the standard Google
LLM
class (which is the non-realtime version). The
RealtimeModel
class is designed for quick, interactive voice conversations, so it doesn’t include some of the advanced settings like
thinking_config
. If controlling the thinking budget is important for your use case, you’d want to work with the standard
LLM
class instead. Please feel free to ask if you have any more questions or if you’d like help exploring other options—I’m here to help! Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py | plugins/google/README.md | Gemini Live API plugin | LiveKit Docs | realtime/gemini_realtime_api.py | agent/main.py
r
""" ## Documentation Quickstart: https://github.com/google-gemini/cookbook/blob/main/quickstarts/Get_started_LiveAPI.py ## Setup To install the dependencies for this script, run:
Copy code
pip install google-genai opencv-python pyaudio pillow mss
""" import os import asyncio import base64 import io import traceback import cv2 import pyaudio import PIL.Image import mss import argparse from google import genai from google.genai import types FORMAT = pyaudio.paInt16 CHANNELS = 1 SEND_SAMPLE_RATE = 16000 RECEIVE_SAMPLE_RATE = 24000 CHUNK_SIZE = 1024 MODEL = "models/gemini-2.5-flash-native-audio-preview-09-2025" DEFAULT_MODE = "camera" client = genai.Client( http_options={"api_version": "v1beta"}, api_key=os.environ.get("GEMINI_API_KEY"), ) CONFIG = types.LiveConnectConfig( response_modalities=[ "AUDIO", ], media_resolution="MEDIA_RESOLUTION_MEDIUM", speech_config=types.SpeechConfig( voice_config=types.VoiceConfig( prebuilt_voice_config=types.PrebuiltVoiceConfig(voice_name="Zephyr") ) ), context_window_compression=types.ContextWindowCompressionConfig( trigger_tokens=25600, sliding_window=types.SlidingWindow(target_tokens=12800), ), ) pya = pyaudio.PyAudio() class AudioLoop: def __init__(self, video_mode=DEFAULT_MODE): self.video_mode = video_mode self.audio_in_queue = None self.out_queue = None self.session = None self.send_text_task = None self.receive_audio_task = None self.play_audio_task = None async def send_text(self): while True: text = await asyncio.to_thread( input, "message > ", ) if text.lower() == "q": break await self.session.send(input=text or ".", end_of_turn=True) def _get_frame(self, cap): # Read the frameq ret, frame = cap.read() # Check if the frame was read successfully if not ret: return None # Fix: Convert BGR to RGB color space # OpenCV captures in BGR but PIL expects RGB format # This prevents the blue tint in the video feed frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) img = PIL.Image.fromarray(frame_rgb) # Now using RGB frame img.thumbnail([1024, 1024]) image_io = io.BytesIO() img.save(image_io, format="jpeg") image_io.seek(0) mime_type = "image/jpeg" image_bytes = image_io.read() return {"mime_type": mime_type, "data": base64.b64encode(image_bytes).decode()} async def get_frames(self): # This takes about a second, and will block the whole program # causing the audio pipeline to overflow if you don't to_thread it. cap = await asyncio.to_thread( cv2.VideoCapture, 0 ) # 0 represents the default camera while True: frame = await asyncio.to_thread(self._get_frame, cap) if frame is None: break await asyncio.sleep(1.0) await self.out_queue.put(frame) # Release the VideoCapture object cap.release() def _get_screen(self): sct = mss.mss() monitor = sct.monitors[0] i = sct.grab(monitor) mime_type = "image/jpeg" image_bytes = mss.tools.to_png(i.rgb, i.size) img = PIL.Image.open(io.BytesIO(image_bytes)) image_io = io.BytesIO() img.save(image_io, format="jpeg") image_io.seek(0) image_bytes = image_io.read() return {"mime_type": mime_type, "data": base64.b64encode(image_bytes).decode()} async def get_screen(self): while True: frame = await asyncio.to_thread(self._get_screen) if frame is None: break await asyncio.sleep(1.0) await self.out_queue.put(frame) async def send_realtime(self): while True: msg = await self.out_queue.get() await self.session.send(input=msg) async def listen_audio(self): mic_info = pya.get_default_input_device_info() self.audio_stream = await asyncio.to_thread( pya.open, format=FORMAT, channels=CHANNELS, rate=SEND_SAMPLE_RATE, input=True, input_device_index=mic_info["index"], frames_per_buffer=CHUNK_SIZE, ) if __debug__: kwargs = {"exception_on_overflow": False} else: kwargs = {} while True: data = await asyncio.to_thread(self.audio_stream.read, CHUNK_SIZE, **kwargs) await self.out_queue.put({"data": data, "mime_type": "audio/pcm"}) async def receive_audio(self): "Background task to reads from the websocket and write pcm chunks to the output queue" while True: turn = self.session.receive() async for response in turn: if data := response.data: self.audio_in_queue.put_nowait(data) continue if text := response.text: print(text, end="") # If you interrupt the model, it sends a turn_complete. # For interruptions to work, we need to stop playback. # So empty out the audio queue because it may have loaded # much more audio than has played yet. while not self.audio_in_queue.empty(): self.audio_in_queue.get_nowait() async def play_audio(self): stream = await asyncio.to_thread( pya.open, format=FORMAT, channels=CHANNELS, rate=RECEIVE_SAMPLE_RATE, output=True, ) while True: bytestream = await self.audio_in_queue.get() await asyncio.to_thread(stream.write, bytestream) async def run(self): try: async with ( client.aio.live.connect(model=MODEL, config=CONFIG) as session, asyncio.TaskGroup() as tg, ): self.session = session self.audio_in_queue = asyncio.Queue() self.out_queue = asyncio.Queue(maxsize=5) send_text_task = tg.create_task(self.send_text()) tg.create_task(self.send_realtime()) tg.create_task(self.listen_audio()) if self.video_mode == "camera": tg.create_task(self.get_frames()) elif self.video_mode == "screen": tg.create_task(self.get_screen()) tg.create_task(self.receive_audio()) tg.create_task(self.play_audio()) await send_text_task raise asyncio.CancelledError("User requested exit") except asyncio.CancelledError: pass except ExceptionGroup as EG: self.audio_stream.close() traceback.print_exception(EG) if name == "__main__": parser = argparse.ArgumentParser() parser.add_argument( "--mode", type=str, default=DEFAULT_MODE, help="pixels to stream from", choices=["camera", "screen", "none"], ) args = parser.parse_args() main = AudioLoop(video_mode=args.mode) asyncio.run(main.run())
t
Thank you for sharing your code snippet! I noticed that the Google Gemini LiveAPI example you provided doesn’t include a configuration for the thinking budget. The good news is that the Gemini API does support thinking budget configuration through the
thinking_config
parameter in the standard LLM class. However, this feature isn’t available in the
RealtimeModel
class you’re currently using. If managing the thinking budget is important for your project, I’d recommend switching to the standard LLM class. Please feel free to reach out if you’d like help with that or if you want to explore other configuration options—I’m here to help! Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py | plugins/google/src/beta/realtime/realtime_api.ts
r
Thinking The latest native audio output model
gemini-2.5-flash-native-audio-preview-09-2025
supports thinking capabilities, with dynamic thinking enabled by default. The
thinkingBudget
parameter guides the model on the number of thinking tokens to use when generating a response. You can disable thinking by setting
thinkingBudget
to
0
. For more info on the
thinkingBudget
configuration details of the model, see the thinking budgets documentation. Python JavaScript
Copy code
model = "gemini-2.5-flash-native-audio-preview-09-2025"

config = types.LiveConnectConfig(
    response_modalities=["AUDIO"]
    thinking_config=types.ThinkingConfig(
        thinking_budget=1024,
    )
)

async with client.aio.live.connect(model=model, config=config) as session:
    # Send audio input and receive audio
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!