Select Page

This Azure OpenAI article will show you how to generate DALL-E images with .NET C# Console application using the Azure SDK for .NET.

Azure SDK for .NET allows us to build Gen-AI applications using .NET, the C# programming language. We, the SDK, can build Blazor and Console apps using C# and mobile apps.

DALL-E version 3 allows us to generate high-definition images from a text input. Currently, we can access the service from the Azure OpenAI studio using the DALL-E playground and RAST API with Postman and C#.

Azure SDK for .NET

The Azure SDK for .NET allows us to create and manage Azure resources using the .NET language. To create and manage Azure OpenAI service, we use Azure.AI, The OpenAI package library. The libraries are available in NuGet.

Generate DALL-E Images with .NET C# Console Application

To generate DALL-E images, we first need to create an Azure OpenAI resource with an OpenAI deployment. Once your service is deployed, note the endpoint and API Key.

For the application to run, we need to create two environment variables. One is for the Azure OpenAI resource endpoint, and the second is for the API Key.

Below is an example of a PowerShell code that creates the two environment variables.

If you use VS Code, run the code from the VS Code terminal window.

Install-Package

After creating a C# console application, install the Azure OpenAI NuGet library.

Program.cs

The following code will generate an Image from the Azure OpenAI DALL-E model. Make sure you set the DeploymentName to the name of your DALL-E deployment name.

In the Prompt, describe the name of the image you would like to generate and run the application.

After running the application, you will get a URL that contains the generated image. The link will be valid for 60 minutes and will be deleted after.