with C# and Azure OpenAI

🎥 Check out the 6-minute demo on YouTube
📦 Sample code on GitHub


The new gpt-image-1 model (aka DALL·E 3) is now available in Azure OpenAI, and YES—you can use it from your .NET app! 🔥

In this post, I’ll show you how to integrate this magic into your C# application using the OpenAI .NET SDK. You’ll learn how to:

  • Connect to Azure OpenAI
  • Send image generation prompts
  • Get beautiful images as URLs
  • And yes… all with just a few lines of C#!

🔧 Prerequisites

  • A working Azure OpenAI resource with image generation enabled
  • Your Azure OpenAI endpoint and key
  • .NET 8+ SDK
  • Install the OpenAI SDK

📸 Let’s Code: Generate an Image with C#

Here’s a small snippet of the actual code from the video:

AzureOpenAIClient azureClient = new(new Uri(url), new System.ClientModel.ApiKeyCredential(apiKey));
var client = azureClient.GetImageClient(model);

string prompt = "A kitten playing soccer in the moon. Use a comic style";

// generate an image using the prompt
ImageGenerationOptions options = new()
{
    Size = GeneratedImageSize.W1024xH1024,
    Quality = "medium"
};
GeneratedImage image = await client.GenerateImageAsync(prompt, options);

And voilà! 🧙‍♂️ You’ll get a URL back pointing to your freshly generated image, ready to display, download, or print on a t-shirt 😆

Check the full code sample here.


📚 Helpful Resources


🎁 What’s Next?

You could easily extend this into:

  • An ASP.NET app that takes user prompts
  • A Blazor dashboard to create art from chat
  • Or even… generate storyboards using GPT-4 + GPT-IMAGE-1 combo!

🤖 Final Thoughts

With just a few lines of C#, you can now access the incredible power of GPT-IMAGE-1 to create visuals like never before. And thanks to Azure OpenAI and the OpenAI .NET SDK, it’s super simple to get started.

If you’re building anything fun with this—tag me on LinkedIn or Twitter. I’d love to see what your apps create 💙


🧵 Don’t forget to check out the full demo on YouTube:
📺 https://www.youtube.com/watch?v=itqnCPew2tk

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.

More info in https://beacons.ai/elbruno


Leave a comment

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading