from google import genaifrom google.genai import typesfrom PIL import Imageimport osclient = genai.Client( http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"}, api_key=os.environ.get("COMETAPI_KEY"),)response = client.models.generate_content( model="gemini-3.1-flash-image-preview", contents="Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme", config=types.GenerateContentConfig( response_modalities=["TEXT", "IMAGE"], ),)for part in response.parts: if part.text is not None: print(part.text) elif part.inline_data is not None: image = part.as_image() image.save("generated_image.png") print("Image saved to generated_image.png")
from google import genaifrom google.genai import typesfrom PIL import Imageimport osclient = genai.Client( http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"}, api_key=os.environ.get("COMETAPI_KEY"),)# Load the source imagesource_image = Image.open("source.jpg")response = client.models.generate_content( model="gemini-3.1-flash-image-preview", contents=["Transform this into a watercolor painting", source_image], config=types.GenerateContentConfig( response_modalities=["TEXT", "IMAGE"], ),)for part in response.parts: if part.text is not None: print(part.text) elif part.inline_data is not None: image = part.as_image() image.save("watercolor_output.png")
from google import genaifrom google.genai import typesfrom PIL import Imageimport osclient = genai.Client( http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"}, api_key=os.environ.get("COMETAPI_KEY"),)collage = Image.open("collage.jpg")response = client.models.generate_content( model="gemini-3.1-flash-image-preview", contents=[ "A model is posing and leaning against a pink BMW with a green alien keychain attached to a pink handbag, a pink parrot on her shoulder, and a pug wearing a pink collar and gold headphones", collage, ], config=types.GenerateContentConfig( response_modalities=["TEXT", "IMAGE"], ),)for part in response.parts: if part.inline_data is not None: part.as_image().save("composition_output.png")
from google import genaifrom google.genai import typesimport osclient = genai.Client( http_options={"api_version": "v1beta", "base_url": "https://api.cometapi.com"}, api_key=os.environ.get("COMETAPI_KEY"),)chat = client.chats.create( model="gemini-3.1-flash-image-preview", config=types.GenerateContentConfig( response_modalities=["TEXT", "IMAGE"], ),)## First turn: Generateresponse = chat.send_message( "Create a vibrant infographic explaining photosynthesis as a recipe, styled like a colorful kids cookbook")for part in response.parts: if part.text is not None: print(part.text) elif image := part.as_image(): image.save("photosynthesis.png")