> ## AI Agent Context > Get the complete documentation index at: https://aistudio.google.com/llms.txt > Use this file to discover all available pages. > For the full documentation in a single file, fetch: https://aistudio.google.com/llms-full.txt # Starting a Live Music session {% callout type="note" %} **Preview:** The Live Music API is in preview. {% /callout %} {% mark class="http-wss" %}{% icon name="sync_alt" /%}`WSS`{% /mark %} `wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateMusic` A WebSocket connection establishes a session to keep a real-time communication with the model. After a client initiates a new connection the session can exchange messages with the server to: * Send prompts and controls to steer music generation. * Send music playback controls. * Receive audio chunks. {% callout type="note" %} The URL is for version `v1beta`. {% /callout %} ## Session configuration {% id="session-configuration" %} The initial message after connection sets the model to use during the session. See the following example configuration. Note that the name casing in SDKs may vary. You can look up the [Python SDK configuration options here](https://github.com/googleapis/python-genai/blob/main/google/genai/live_music.py). ```json { "model": string } ``` ## Send messages {% id="send-messages" %} To exchange messages over the WebSocket connection, the client must send a JSON object over an open WebSocket connection. The JSON object must have **exactly one** of the fields from the following object set: ```json { "setup": BidiGenerateMusicSetup, "client_content": BidiGenerateMusicClientContent, "music_generation_config": BidiGenerateMusicGenerationConfig, "playback_control": BidiGenerateMusicPlaybackControl } ``` ### Supported client messages {% id="client-messages" %} See the supported client messages in the following table: | Message | Description | | --- | --- | | [`BidiGenerateMusicSetup`](/api-reference/live-music#BidiGenerateMusicSetup) | Session configuration to be sent only in the first message | | [`BidiGenerateMusicClientContent`](/api-reference/live-music#BidiGenerateMusicClientContent) | Weighted prompts as the model input | | [`BidiGenerateMusicGenerationConfig`](/api-reference/live-music#BidiGenerateMusicGenerationConfig) | Configuration for music generation | | [`BidiGenerateMusicPlaybackControl`](/api-reference/live-music#BidiGenerateMusicPlaybackControl) | Playback control signals for model generation | ## Receive messages {% id="receive-messages" %} To receive messages from the server, listen for the WebSocket 'message' event, and then parse the result according to the definition of the supported server messages. See the following: ```python async def receive_audio(session): """Example background task to process incoming audio.""" while True: async for message in session.receive(): audio_data = message.server_content.audio_chunks[0].data # Process audio... await asyncio.sleep(10**-12) async with ( client.aio.live.music.connect(model='models/lyria-realtime-exp') as session, asyncio.TaskGroup() as tg, ): # Set up task to receive server messages. tg.create_task(receive_audio(session)) # Send initial prompts and config await session.set_weighted_prompts( prompts=[ types.WeightedPrompt(text='minimal techno', weight=1.0), ] ) await session.set_music_generation_config( config=types.LiveMusicGenerationConfig(bpm=90, temperature=1.0) ) # Start streaming music await session.play() ``` Server messages include **exactly one** of the other fields from the [`BidiGenerateMusicServerMessage`](/api-reference/live-music#BidiGenerateMusicServerMessage) message. (The `messageType` union is not expressed in JSON so the field will appear at the top-level of the message.)