High severity intermediate · Fix: 5-10 min

ReplicatePredictionError

replicate.exceptions.ReplicatePredictionError

What this error means
Replicate prediction failed because the requested model is unavailable, input is invalid, or the API call was malformed.

Stack trace

traceback
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")
QUICK FIX
Confirm the model identifier and input parameters are correct and set a valid REPLICATE_API_TOKEN environment variable before calling predict().

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

1

The model name used in the prediction call does not exist or is misspelled.

✓ Fix

Verify the model name string matches exactly the model identifier on Replicate, including owner and version if required.

2

Input parameters to the model prediction are missing required fields or have invalid types.

✓ Fix

Check the model's input schema on Replicate and ensure all required inputs are provided with correct data types.

3

The API key used lacks permissions or is invalid, causing the prediction request to fail.

✓ Fix

Set a valid API key with proper permissions in the environment variable REPLICATE_API_TOKEN before making calls.

4

The model version specified is deprecated or removed from Replicate.

✓ Fix

Update to a current model version by checking the latest available versions on Replicate and specifying it explicitly.

Code: broken vs fixed

Broken - triggers the error
python
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)
Fixed - works correctly
python
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)
Set the REPLICATE_API_TOKEN environment variable and use a valid model identifier with correct input parameters to avoid prediction failures.

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.

Python 3.7+ · replicate >=0.7.0 · tested on 0.8.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.