How to Generate a Full Song With Lyria 3.5 in Python
Lyria 3.5 turns a text prompt into a full-length song with vocals, and the Lyria 3.5 Python script below is about 25 lines. By the end you'll have a script that sends a structured prompt to the Gemini API, saves the audio as MP3 (or WAV), and prints the lyrics. Each song costs $0.08, which is cheap enough to experiment with and pricey enough that you shouldn't put it in an unguarded loop.
Before you start: a paid key and the right SDK
The model ID is lyria-3.5. It has no Free tier, so your API key must belong to a paid project. It runs through the Interactions API, which needs google-genai 2.3.0 or later in Python.
pip install --upgrade "google-genai>=2.3.0"
export GEMINI_API_KEY="<your-api-key>"
The first line installs the SDK. The second sets the key in your shell, so genai.Client() can be created with no arguments.
Step 1: Write a prompt with song structure
Lyria 3.5 follows section tags such as [Verse], [Chorus] and [Bridge]. The music generation guide also recommends naming instruments, BPM, key and mood, stating the length you want ("about two minutes"), and keeping your lyrics separate from the musical direction. Write the prompt in the language you want sung.
PROMPT = """
Create a dreamy indie pop song, about two minutes long, 92 BPM,
warm analog synths, brushed drums, breathy female vocals.
Lyrics:
[Verse 1]
The build is green, the dashboards glow,
nobody paged me, so I know.
[Chorus]
Ship it slow, ship it right,
we sleep through the deploy tonight.
[Verse 2]
The rollback plan sits in the drawer,
I hope I never need it more.
"""
The first block is direction, the second is lyrics. Don't ask for a specific artist's voice or paste copyrighted lyrics: the safety filters block those prompts.
Step 2: Generate the song and save the MP3
Call client.interactions.create with model="lyria-3.5". The docs note that the convenience properties output_audio and output_text may miss parts of interleaved output, so loop over interaction.steps instead.
import base64
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="lyria-3.5",
input=PROMPT,
)
lyrics = []
audio_data = None
for step in interaction.steps:
if step.type == "model_output":
for block in step.content:
if block.type == "audio":
audio_data = base64.b64decode(block.data)
elif block.type == "text":
lyrics.append(block.text)
if audio_data is None:
raise SystemExit("No audio returned. The prompt may have tripped a safety filter.")
with open("song.mp3", "wb") as f:
f.write(audio_data)
print("Lyrics:\n" + "\n".join(lyrics))
Audio arrives base64-encoded, so decode it before writing. The text blocks hold the lyrics and song structure. The docs don't show what a blocked request looks like, so the script treats missing audio as the signal.
Step 3: Ask for WAV instead of MP3
The default output is MP3. For Lyria 3.5 you can request WAV by setting response_format:
interaction = client.interactions.create(
model="lyria-3.5",
input=PROMPT,
response_format={"type": "audio"},
)
Run the same decode loop and write to song.wav. The docs show only this one value and no WAV-specific setting, so open the file once to confirm it plays before you build on it.
Step 4: Steer the song with images
You can send up to 10 images with your text. Pass input as a list of text and image blocks:
with open("desert_sunset.jpg", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode("utf-8")
interaction = client.interactions.create(
model="lyria-3.5",
input=[
{
"type": "text",
"text": "An atmospheric ambient track inspired by the mood and colors in this image.",
},
{
"type": "image",
"mime_type": "image/jpeg",
"data": image_b64,
},
],
)
Add more image blocks to the list, up to the limit of 10. Set mime_type to match each file.
Gotchas
- Every attempt costs $0.08. Lyria 3.5 has only a Standard tier: no Free tier, no Batch, no Flex. Put a counter or budget cap around any retry loop.
- It is single-turn. There's no "make the chorus bigger" follow-up. Edit the prompt and generate again, and pay again.
- Draft cheaply first. The docs suggest testing prompts on the faster
lyria-3-clip-previewmodel, which always returns a 30-second clip, before spending on a full song. - Outputs vary. The same prompt can give different songs, so save every file you like.
- Length is approximate. Expect a couple of minutes. Your prompt influences the exact duration.
- Everything is watermarked. All generated audio carries an imperceptible SynthID watermark that doesn't affect playback. Tell your customer's legal team before they ask.
One script, one paid key and a spending cap are enough to run Lyria 3.5 safely, and in production that cap matters because every blocked, repeated or retried prompt is billed like a real song.