PermissionDeniedError
replicate.client.exceptions.PermissionDeniedError
Stack trace
replicate.client.exceptions.PermissionDeniedError: You do not have permission to access this private model. HTTP 403 Forbidden
File "app.py", line 42, in run_model
output = client.models.get("owner/private-model").predict(input=data)
File "replicate/client/models.py", line 123, in get
raise PermissionDeniedError("You do not have permission to access this private model.") Why it happens
This error occurs because the Replicate API requires authentication with an API token that has access rights to the private model. If the token is missing, invalid, or lacks permissions, the API denies access with a 403 error.
Detection
Check for PermissionDeniedError exceptions when calling replicate.Client.models.get() or .predict(), and verify the API token is set and has access to the private model.
Causes & fixes
No API token or environment variable REPLICATE_API_TOKEN is not set
Set the REPLICATE_API_TOKEN environment variable with a valid token that has access to the private model.
API token does not have permission to access the requested private model
Use an API token from a user or organization that owns or has been granted access to the private model.
Incorrect model identifier or owner name in the model path
Verify the model path string matches exactly the private model's owner and name as registered on Replicate.
Code: broken vs fixed
import replicate
client = replicate.Client()
# This line triggers PermissionDeniedError if token missing or unauthorized
output = client.models.get("owner/private-model").predict(input=data)
print(output) import os
import replicate
os.environ["REPLICATE_API_TOKEN"] = "your_valid_token_here" # Set your token securely
client = replicate.Client()
output = client.models.get("owner/private-model").predict(input=data) # Fixed: token set with access
print(output) Workaround
Catch PermissionDeniedError and prompt the user to provide a valid API token or check model access permissions before retrying the request.
Prevention
Always store and load the REPLICATE_API_TOKEN environment variable securely with a token that has explicit access to the private models you intend to use, and verify model identifiers are correct.