ReplicatePredictionError
replicate.exceptions.ReplicatePredictionError
Stack trace
replicate.exceptions.ReplicatePredictionError: Prediction failed: model not found or invalid input
File "/app/main.py", line 42, in run_prediction
prediction = client.models.get("nonexistent-model").predict(input_data)
File "/usr/local/lib/python3.9/site-packages/replicate/client.py", line 120, in predict
raise ReplicatePredictionError("Prediction failed: model not found or invalid input") Why it happens
This error occurs when the Replicate API cannot run the prediction because the specified model does not exist, is deprecated, or the input parameters do not meet the model's requirements. It can also happen if the API key is invalid or lacks permissions.
Detection
Catch ReplicatePredictionError exceptions around prediction calls and log the model name and input parameters to identify invalid models or inputs before crashing.
Causes & fixes
The model name used in the prediction call does not exist or is misspelled.
Verify the model name string matches exactly the model identifier on Replicate, including owner and version if required.
Input parameters to the model prediction are missing required fields or have invalid types.
Check the model's input schema on Replicate and ensure all required inputs are provided with correct data types.
The API key used lacks permissions or is invalid, causing the prediction request to fail.
Set a valid API key with proper permissions in the environment variable REPLICATE_API_TOKEN before making calls.
The model version specified is deprecated or removed from Replicate.
Update to a current model version by checking the latest available versions on Replicate and specifying it explicitly.
Code: broken vs fixed
import replicate
client = replicate.Client()
# This line triggers ReplicatePredictionError due to invalid model name
prediction = client.models.get("nonexistent-model").predict({"image": "data"})
print(prediction) import os
import replicate
os.environ["REPLICATE_API_TOKEN"] = "your_api_token_here" # Set your API token securely
client = replicate.Client()
# Fixed: Use correct model identifier and valid input
model = client.models.get("stability-ai/stable-diffusion")
prediction = model.predict(prompt="a scenic landscape")
print(prediction) Workaround
Wrap the prediction call in try/except ReplicatePredictionError, then log the error and fallback to a default model or cached output to maintain service availability.
Prevention
Always validate model identifiers and input schemas against Replicate's API documentation and keep API tokens current and properly scoped to prevent prediction failures.