DALL-E API Image URL lifetime

Hello there,

I am using the https://api.openai.com/v1/images/generations to generate DALL-E images via API.
The response could be either image URL, or base64 image.

I chose the Image URL, and I was able to download it with:
wget -O image.png <API_RESPONSE_URL>
to my local disk.

This is al fine, but I am wondering, if someone knows, how long will be the image URL valid. I mean how long is his lifetime on the OpenAI server.

Reason why I am asking, that I want to store these URLs in my database (instead of keeping the 4+MB base64 images) , so if there is no expiration on these URLs, I can simply store that URL in my database and save a TON of disk space on my server.

Thanks in advance for your answers :slight_smile:

1 Like

I think it’s about an hour?

Would be nice if they stored them permanently (for a fee, maybe?), but alas, they do not.

You can do things like save it as JPG instead of PNG to save on space, but it’s still up to you to save and store it.

Hope this helps… and welcome to the community hope you stick around!

1 Like

If it’s like you telling, then I will save few cents, and generate the 512x512 size images, fetch them as a base64 image, then convert it to webp or even avif format with lower compression directly on my server and it will also save my disk space :slight_smile:
I have a dedicated server with approx 800GB free space, which is enough to store ~180k images at 1024x1024 resolution, which will cost me around 3000$ . These images are really fantastic and I want to create a web-gallery of them.
Of course I will not type manually all of 180k crazy ideas, I’ve created a really cool randomizer which is asking AI-like request directly to DALL-E API :slight_smile: . So it will be like: “My AI is asking DALL-E API” , they are having a chat, and I am just watching the output haha.

Thanks @PaulBellow for your quick answer! Have a nice day!

1 Like

I have an app which prompts Dall-E for images @Fanta and had the same problem you encountered with (rapidly) expiring OpenAI links to these images.

So, what I do when I make this API call is to immediately download the image to the filesystem (where it is also available via the web, naturally) as follows:

module DalleBot
    
    # saves a url genereated by dalle to a file
    def self.save_dalle_image(url)
        timestamp=Time.now.to_i
        dalle_file="dalle_#{timestamp}.png"
        file="#{DALLE_DOWNLOAD_DIR}/#{dalle_file}"
        URI.open(url) {|f|
            File.open(file,"wb") do |file|
                file.puts f.read
            end
        }
        dalle_file
    end

    # ...
    # ...
end

I also have a bit of code to take the locally stored image file URL and convert it to a short url, but that’s just a bit of coding window dressing and not really necessary.

Hope this helps!

:slight_smile:

I think it is (or at least it was a month ago) two hours. When coding this, I checked the error message and it showed the expiration was two hours, as mentioned here around a month ago:

Not sure if anything has changed since that time, since Beta apps like this change daily.

Hope this helps.

1 Like