ExpiredDownloadUrlError
replicate.exceptions.ExpiredDownloadUrlError
Stack trace
replicate.exceptions.ExpiredDownloadUrlError: The output URL has expired and can no longer be used to download the result.
Why it happens
Replicate generates temporary URLs for model outputs that expire quickly (usually within minutes) for security and resource management. Attempting to download the output after this expiration window causes this error.
Detection
Monitor the time elapsed between output creation and download attempt; log and check for ExpiredDownloadUrlError exceptions to catch expired URLs before retrying.
Causes & fixes
Downloading output after the replicate output URL's short expiration time (usually a few minutes).
Download the output immediately after the model run completes or cache the output locally before the URL expires.
Storing the output URL and reusing it later instead of fetching a fresh URL from the model output object.
Always access the output URL directly from the latest model output object instead of reusing old URLs.
Network delays or retries causing the download attempt to happen after the URL expiration.
Implement retry logic that refreshes the output URL by re-fetching the model output or rerunning the prediction if the URL expired.
Code: broken vs fixed
import replicate
client = replicate.Client(api_token=os.environ['REPLICATE_API_TOKEN'])
model = client.models.get('stability-ai/stable-diffusion')
version = model.versions.get('some-version-id')
prediction = client.predictions.create(version=version.id, input={'prompt': 'a cat'})
# Waiting too long before accessing output URL
output_url = prediction.output[0] # This URL may expire
import requests
response = requests.get(output_url) # This line triggers ExpiredDownloadUrlError
print(response.content) import os
import replicate
import requests
client = replicate.Client(api_token=os.environ['REPLICATE_API_TOKEN'])
model = client.models.get('stability-ai/stable-diffusion')
version = model.versions.get('some-version-id')
prediction = client.predictions.create(version=version.id, input={'prompt': 'a cat'})
# Access output URL immediately from prediction object
output_url = prediction.output[0] # Fresh URL
response = requests.get(output_url) # Download immediately to avoid expiration
print(response.content) # Fixed: download done before URL expires Workaround
Catch ExpiredDownloadUrlError, then re-fetch the prediction output object or rerun the prediction to get a fresh output URL before retrying the download.
Prevention
Design your system to download or cache outputs immediately after prediction completes, and avoid storing or reusing output URLs beyond their short expiration window.