@@ -344,7 +344,7 @@ print(response.text)
344344from google.genai import types
345345
346346response = client.models.generate_content(
347- model = ' gemini-3.1-flash-image' ,
347+ model = ' gemini-3.1-flash-lite- image' ,
348348 contents = ' A cartoon infographic for flying sneakers' ,
349349 config = types.GenerateContentConfig(
350350 response_modalities = [" IMAGE" ],
@@ -360,6 +360,32 @@ for part in response.parts:
360360 generated_image.show()
361361```
362362
363+ #### with text content input (audio / speech output)
364+
365+ ``` python
366+ from google.genai import types
367+
368+ response = client.models.generate_content(
369+ model = ' gemini-3.8-flash-tts' ,
370+ contents = ' Give me a cheerful greeting.' ,
371+ config = types.GenerateContentConfig(
372+ response_modalities = [' AUDIO' ],
373+ speech_config = types.SpeechConfig(
374+ voice_config = types.VoiceConfig(
375+ prebuilt_voice_config = types.PrebuiltVoiceConfig(
376+ voice_name = ' Aoede'
377+ )
378+ )
379+ ),
380+ ),
381+ )
382+
383+ for part in response.parts:
384+ if part.inline_data:
385+ with open (' greeting.wav' , ' wb' ) as f:
386+ f.write(part.inline_data.data)
387+ ```
388+
363389#### with uploaded file (Gemini Developer API only)
364390
365391Download the file in console.
@@ -1566,7 +1592,7 @@ interaction = client.interactions.create(
15661592 model = ' gemini-flash-latest' ,
15671593 input = ' Tell me a short joke about programming.'
15681594)
1569- print (interaction.outputs[ - 1 ].text )
1595+ print (interaction.output_text )
15701596
15711597```
15721598
@@ -1580,15 +1606,15 @@ interaction1 = client.interactions.create(
15801606 model = ' gemini-flash-latest' ,
15811607 input = ' Hi, my name is Amir.'
15821608)
1583- print (f " Model: { interaction1.outputs[ - 1 ].text } " )
1609+ print (f " Model: { interaction1.output_text } " )
15841610
15851611# 2. Second turn (passing previous_interaction_id)
15861612interaction2 = client.interactions.create(
15871613 model = ' gemini-flash-latest' ,
15881614 input = ' What is my name?' ,
15891615 previous_interaction_id = interaction1.id
15901616)
1591- print (f " Model: { interaction2.outputs[ - 1 ].text } " )
1617+ print (f " Model: { interaction2.output_text } " )
15921618
15931619```
15941620
@@ -1613,7 +1639,7 @@ while True:
16131639 print (f " Status: { interaction.status} " )
16141640
16151641 if interaction.status == " completed" :
1616- print (" \n Final Report:\n " , interaction.outputs[ - 1 ].text )
1642+ print (" \n Final Report:\n " , interaction.output_text )
16171643 break
16181644 elif interaction.status in [" failed" , " cancelled" ]:
16191645 print (f " Failed with status: { interaction.status} " )
@@ -1640,7 +1666,7 @@ interaction = client.interactions.create(
16401666 {' type' : ' image' , ' data' : base64_image, ' mime_type' : ' image/png' }
16411667 ]
16421668)
1643- print (interaction.outputs[ - 1 ].text )
1669+ print (interaction.output_text )
16441670
16451671```
16461672
@@ -1675,25 +1701,25 @@ interaction = client.interactions.create(
16751701)
16761702
16771703# 3. Handle the tool call
1678- for output in interaction.outputs :
1679- if output .type == ' function_call' :
1680- print (f " Tool Call: { output .name} ( { output .arguments} ) " )
1704+ for step in ( interaction.steps or []) :
1705+ if step .type == ' function_call' :
1706+ print (f " Tool Call: { step .name} ( { step .arguments} ) " )
16811707
16821708 # Execute your actual function here
1683- result = get_weather(** output .arguments)
1709+ result = get_weather(** step .arguments)
16841710
16851711 # Send result back to the model
16861712 interaction = client.interactions.create(
16871713 model = ' gemini-flash-latest' ,
16881714 previous_interaction_id = interaction.id,
16891715 input = [{
16901716 ' type' : ' function_result' ,
1691- ' name' : output .name,
1692- ' call_id' : output .id,
1717+ ' name' : step .name,
1718+ ' call_id' : step .id,
16931719 ' result' : result
16941720 }]
16951721 )
1696- print (f " Response: { interaction.outputs[ - 1 ].text } " )
1722+ print (f " Response: { interaction.output_text } " )
16971723
16981724```
16991725
@@ -1708,11 +1734,7 @@ interaction = client.interactions.create(
17081734 input = ' Who won the last Super Bowl?' ,
17091735 tools = [{' type' : ' google_search' }]
17101736)
1711-
1712- # Find the text output (not the GoogleSearchResultContent)
1713- text_output = next ((o for o in interaction.outputs if o.type == ' text' ), None )
1714- if text_output:
1715- print (text_output.text)
1737+ print (interaction.output_text)
17161738
17171739```
17181740
@@ -1724,30 +1746,47 @@ interaction = client.interactions.create(
17241746 input = ' Calculate the 50th Fibonacci number.' ,
17251747 tools = [{' type' : ' code_execution' }]
17261748)
1727- print (interaction.outputs[ - 1 ].text )
1749+ print (interaction.output_text )
17281750
17291751```
17301752
17311753### Multimodal Output
17321754
1733- The Interactions API can generate multimodal outputs, such as images. You must specify the ` response_modalities ` .
1755+ The Interactions API can generate multimodal outputs, such as images or audio. You must specify the ` response_modalities ` .
1756+
1757+ #### Image Output
17341758
17351759``` python
17361760import base64
17371761
17381762interaction = client.interactions.create(
1739- model = ' gemini-3-pro-image-preview ' ,
1763+ model = ' gemini-3.1-flash-lite-image ' ,
17401764 input = ' Generate an image of a futuristic city.' ,
17411765 response_modalities = [' IMAGE' ]
17421766)
17431767
1744- for output in interaction.outputs:
1745- if output.type == ' image' :
1746- print (f " Generated image with mime_type: { output.mime_type} " )
1747- # Save the image
1748- with open (" generated_city.png" , " wb" ) as f:
1749- f.write(base64.b64decode(output.data))
1768+ if interaction.output_image:
1769+ print (f " Generated image with mime_type: { interaction.output_image.mime_type} " )
1770+ with open (" generated_city.png" , " wb" ) as f:
1771+ f.write(base64.b64decode(interaction.output_image.data))
1772+
1773+ ```
1774+
1775+ #### Audio Output
17501776
1777+ ``` python
1778+ import base64
1779+
1780+ interaction = client.interactions.create(
1781+ model = ' gemini-3.8-flash-tts' ,
1782+ input = ' Say hello and give a one sentence motivational quote.' ,
1783+ response_modalities = [' AUDIO' ]
1784+ )
1785+
1786+ if interaction.output_audio:
1787+ print (f " Generated audio with mime_type: { interaction.output_audio.mime_type} " )
1788+ with open (" greeting.wav" , " wb" ) as f:
1789+ f.write(base64.b64decode(interaction.output_audio.data))
17511790```
17521791
17531792## Tunings
@@ -2066,7 +2105,7 @@ The structure of the dictionary must match the backend API's request structure.
20662105
20672106``` python
20682107response = client.models.generate_content(
2069- model = " gemini-2.5-pro " ,
2108+ model = " gemini-flash-latest " ,
20702109 contents = " What is the weather in Boston? and how about Sunnyvale?" ,
20712110 config = types.GenerateContentConfig(
20722111 tools = [get_current_weather],
0 commit comments