{"id":23905600,"url":"https://github.com/ppiova/azureopenai-dall-e-consoleapp","last_synced_at":"2026-06-08T16:05:09.986Z","repository":{"id":269250480,"uuid":"906833696","full_name":"ppiova/AzureOpenAI-DALL-E-ConsoleApp","owner":"ppiova","description":"This console application demonstrates how to generate images using Azure OpenAI’s DALL-E 3 API from a .NET 9 console project.","archived":false,"fork":false,"pushed_at":"2024-12-22T13:38:22.000Z","size":13947,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-27T10:39:15.294Z","etag":null,"topics":["azureopenai","dalle-3","dotnet"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ppiova.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-22T03:29:14.000Z","updated_at":"2024-12-22T13:39:05.000Z","dependencies_parsed_at":"2025-06-10T03:47:12.848Z","dependency_job_id":null,"html_url":"https://github.com/ppiova/AzureOpenAI-DALL-E-ConsoleApp","commit_stats":null,"previous_names":["ppiova/azureopenai-dall-e-consoleapp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ppiova/AzureOpenAI-DALL-E-ConsoleApp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppiova%2FAzureOpenAI-DALL-E-ConsoleApp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppiova%2FAzureOpenAI-DALL-E-ConsoleApp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppiova%2FAzureOpenAI-DALL-E-ConsoleApp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppiova%2FAzureOpenAI-DALL-E-ConsoleApp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ppiova","download_url":"https://codeload.github.com/ppiova/AzureOpenAI-DALL-E-ConsoleApp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ppiova%2FAzureOpenAI-DALL-E-ConsoleApp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34069509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azureopenai","dalle-3","dotnet"],"created_at":"2025-01-05T01:15:29.483Z","updated_at":"2026-06-08T16:05:09.968Z","avatar_url":"https://github.com/ppiova.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Azure OpenAI-DALL-E3-ConsoleApp\n\nThis entry is part of the **[AI Advent Calendar 2024](https://dev.to/roberto_navarro_mate/calendario-de-adviento-de-inteligencia-artificial-2024-en-espanol-bdb)**.\n\nThis console application demonstrates how to generate images using [Azure OpenAI’s DALL-E 3](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/concepts/models#dall%C3%A9) API from a .NET 9 console project.\n\n## Table of Contents\n1. [Prerequisites](#prerequisites)  \n2. [Clone the Repository](#clone-the-repository)  \n3. [Configure Environment Variables](#configure-environment-variables)  \n4. [Install Dependencies](#install-dependencies)  \n5. [Run the Application](#run-the-application)  \n6. [Project Structure](#project-structure)  \n7. [How the Code Works](#how-the-code-works)  \n8. [Additional Resources](#additional-resources)  \n\n---\n\n## Prerequisites\n\n1. **.NET 9** (or a compatible .NET version) installed on your machine.  \n   - You can download it from [https://dotnet.microsoft.com/en-us/download](https://dotnet.microsoft.com/en-us/download).\n2. An **Azure OpenAI Resource** that has a **DALL-E 3** deployment.  \n   - You must have your resource name, deployment name, and API key from the Azure Portal.  \n3. **Git** installed (to clone the repository).\n\n---\n\n## Clone the Repository\n\n1. Open your terminal (or command prompt).\n2. Navigate to the directory where you want to store the project.\n3. Run the following command to clone the repo:\n\n   ```bash\n   git clone https://github.com/ppiova/AzureOpenAI-DALL-E-ConsoleApp.git\n3. Navigate into the newly created folder:\n```bash\ncd AzureOpenAI-DALL-E-ConsoleApp\n```\n\n## Configure Environment Variables\nThis project uses a .env file to load your credentials (environment variables) at runtime. This approach helps keep secret data out of source control.\n\n1. In the root of the project, create a file named .env.\n\n2. Add the following lines, replacing the placeholder values with your actual Azure resource details:\n```bash\nAZURE_OPENAI_RESOURCE_NAME=myResourceName\nAZURE_OPENAI_DEPLOYMENT_NAME=myDeploymentName\nAZURE_OPENAI_API_KEY=mySuperSecretKey\n```\n3.Check the .gitignore file to confirm that the .env file is listed. This ensures it won’t be committed to the repo.\n\n## Install Dependencies\nFrom within the project folder, install dependencies (like DotNetEnv) and restore any NuGet packages:\n```bash\ndotnet restore\n```\nIf you want to install DotNetEnv manually (in case it’s not already in the .csproj), run:\n```bash\ndotnet add package DotNetEnv\n```\n## Run the Application\n\nAfter setting up your .env file and restoring packages:\n```bash\ndotnet run\n```\n\n## Console Prompts\n1. Image prompt: A descriptive text prompt for the image you want to generate.\n2. Image size: Choose from 1024x1024, 1792x1024, or 1024x1792.\n3. Style: Choose between natural or vivid.\n4. Quality: Choose between standard (faster) or hd (higher detail).\n5. Response format:\n    - url – returns a URL link to the generated image.\n    - b64_json – returns a Base64-encoded image in JSON format.\n\nThe console will show either a URL to your generated image or the Base64-encoded output.\n\n## Project Structure\nA simplified view of the most important files and folders:\n```bash\nAzureOpenAI-DALL-E-ConsoleApp/\n│\n├─ .gitignore\n├─ .env           (excluded from Git; contains your secrets)\n├─ Program.cs     (main entry point of the console app)\n├─ AzureOpenAI-DALL-E-ConsoleApp.csproj\n└─ README.md\n\n```\n- .env: Local file to store environment variables (like resource name, deployment name, and API key).\n- Program.cs: Main C# file that loads environment variables, prompts the user, builds the request, and sends it to Azure OpenAI’s DALL-E endpoint.\n- .gitignore: Ensures .env is excluded from version control.\n\n## How the Code Works\n\n1. Load environment variables:\n\n   - At the top of Main, we use DotNetEnv.Env.Load() to read key-value pairs from the .env file.\n   - Environment.GetEnvironmentVariable(...) retrieves these values later in the code.\n\n2. Prompt the user for image details:\n\n   - We ask for a descriptive prompt, image size, style, quality, and response format.\n   - Each choice sets the respective property in our DalleRequestBody.\n\n3. Build the request:\n\n   - A DalleRequestBody object is serialized to JSON and sent to the Azure OpenAI Image Generation endpoint.\n   - We include the environment variable apiKey in the api-key header of the request.\n\n4. Handle the response:\n\n   - On success, we deserialize the JSON to a DalleResponse object, which contains an array of generated images (DalleResponseData).\n   - On failure, we deserialize the error to DalleErrorResponse and display relevant messages in the console.\n\n5. Display results:\n\n   - If response_format is url, we print the URL for the generated image.\n   - If response_format is b64_json, we print the Base64-encoded output returned.\n\n![DALL-E 3 Generate Images](assets/DALL-E-3-Generate-Images.gif)\n\n![DALL-E 3 Generate_00](assets/generated_00-dall-e3.png)\n\n## Additional Resources\n\n   - [How to work with the DALL-E models](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/dall-e?tabs=dalle3\u0026WT.mc_id=AI-MVP-5004753)\n   - [Quickstart: Generate images with Azure OpenAI Service](https://learn.microsoft.com/azure/ai-services/openai/dall-e-quickstart?tabs=dalle3%2Ccommand-line%2Cjavascript-keyless%2Ctypescript-keyless\u0026pivots=programming-language-studio\u0026WT.mc_id=AI-MVP-5004753)\n\n## Contributing\nIf you wish to contribute to the project, please fork the repository and create a pull request with your changes.\n\n## License\nThis project is licensed under the MIT License.\n\n## Contact\nFor any questions or inquiries, please contact the repository owner.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppiova%2Fazureopenai-dall-e-consoleapp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fppiova%2Fazureopenai-dall-e-consoleapp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fppiova%2Fazureopenai-dall-e-consoleapp/lists"}