DALL-E 3 API Calls Returning 403 Errors Intermittently

Kalle Gerarts 20 Reputation points
2025-04-01T06:59:46.6566667+00:00

Hello,

The REST API calls for DALL-E 3 deployments intermittently return a 403 error. Initially, calling the deployment's endpoint successfully returns the URL for the generated image. However, when attempting to download the image using the returned URL, there are two or three successful attempts followed by a 403 error, which indicates an authorization issue. After a brief period, one or two attempts succeed again, and this pattern continues. What could be causing this intermittent authorization problem? My first idea was a rate limit, but in this case the REST API call should return a 429 Error, if the documentation is correct. My second idea was that it is a timing problem, but the running URLs are still running after a day.

The code is written in C# and I do NOT use the Azure Open API but calling the endpoint on my own:

"https://{0}.openai.azure.com/openai/deployments/{1}/images/generations?api-version={2}"

I copied the returned URL to the browser and it returned as well with an error. It contains bit more information than only "AuthenticationFailed":

https://dalleprodsec.blob.core.windows.net/private/images/67934f20-1848-4470-974b-6eebd1eaf1c5/generated_00.png?se=2025-04-02T06:10:27Z&sig=fDuyzsL+d3Ci3lK/PxOryOLTaj1FG0jAAi8u6fAv27g=&ske=2025-04-02T19:48:02Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2025-03-26T19:48:02Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02

This XML file does not appear to have any style information associated with it. The document tree is shown below.

``

Thank you for taking time to help.

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,081 questions
{count} votes

Accepted answer
  1. Manas Mohanty 5,620 Reputation points Microsoft External Staff Moderator
    2025-04-01T15:39:59.96+00:00

    Hi Kalle Gerarts

    Could you share sample code for replicating the issue.

    I was able to download 5 images iteratively from same image source using below source code with .NET SDK 8 (without 403 or 429 issue)

    //dalle image generation
    using System;
    using System.IO;
    using System.Net.Http;
    using System.Threading.Tasks;
    using Azure;
    using Azure.AI.OpenAI;
    using Azure.Identity;
    
    using OpenAI.Images;
    using static System.Environment;
    
    class Program
    {
        static async Task Main(string[] args)
        {
            string endpoint = "https://<sourcename>.openai.azure.com/";
            string key = "<apikey>";
    
        
            // Use the recommended keyless credential instead of the AzureKeyCredential credential.
            //AzureOpenAIClient openAIClient = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential());
            AzureOpenAIClient openAIClient = new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(key));
    
            // This must match the custom deployment name you chose for your model
            ImageClient chatClient = openAIClient.GetImageClient("dall-e-3");
    
            var imageGeneration = await chatClient.GenerateImageAsync(
                "a happy monkey sitting in a tree, in watercolor",
                new ImageGenerationOptions()
                {
                    Size = GeneratedImageSize.W1024xH1024
                }
            );
    
           
            string imageUri = imageGeneration.Value.ImageUri.ToString();
            Console.WriteLine(imageUri);
    
            // Download and save the image to the local machine
            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(imageUri);
                if (response.IsSuccessStatusCode)
                {
                    byte[] imageBytes = await response.Content.ReadAsByteArrayAsync();
                    await File.WriteAllBytesAsync("downloaded_image.jpg", imageBytes);
                    await File.WriteAllBytesAsync("downloaded_image1.jpg", imageBytes);
                    await File.WriteAllBytesAsync("downloaded_image2.jpg", imageBytes);
                    await File.WriteAllBytesAsync("downloaded_image3.jpg", imageBytes);
                    await File.WriteAllBytesAsync("downloaded_image4.jpg", imageBytes);
                    await File.WriteAllBytesAsync("downloaded_image5.jpg", imageBytes);
                    Console.WriteLine("Image successfully downloaded and saved as 'downloaded_image.jpg'.");
                }
                else
                {
                    Console.WriteLine("Failed to download the image.");
                }
            }
        }
    }
    
    

    Key Changes -

            string imageUri = imageGeneration.Value.ImageUri.ToString();
    

    Are you using a virtual network protected resource by any chance (there might be intermitted network block on proxy or firewall)

    Thank you


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.