diff --git a/sdk/openai/azure-openai/samples/images_aoai_quickstart.py b/sdk/openai/azure-openai/samples/images_aoai_quickstart.py index 73558748b313..d2bf9e9eed5a 100644 --- a/sdk/openai/azure-openai/samples/images_aoai_quickstart.py +++ b/sdk/openai/azure-openai/samples/images_aoai_quickstart.py @@ -62,16 +62,19 @@ def images_aoai_quickstart() -> None: image_path = os.path.join(image_dir, 'generated_image.png') # Retrieve the generated image - image_url = result.data[0].url # extract image URL from response - if image_url: - generated_image = httpx.get(image_url).content # download the image - - with open(image_path, "wb") as image_file: - image_file.write(generated_image) - - # Display the image in the default image viewer - image = Image.open(image_path) - image.show() + if result.data and len(result.data) > 0: + image_url = result.data[0].url # extract image URL from response + if image_url: + generated_image = httpx.get(image_url).content # download the image + + with open(image_path, "wb") as image_file: + image_file.write(generated_image) + + # Display the image in the default image viewer + image = Image.open(image_path) + image.show() + else: + print("No image data received from the API.") if __name__ == "__main__": images_aoai_quickstart() \ No newline at end of file