High severity HTTP 403 beginner · Fix: 2-5 min

PermissionDeniedError

replicate.client.exceptions.PermissionDeniedError

What this error means
Replicate API returns a permission denied error when trying to access a private model without proper authorization.

Stack trace

traceback
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.")
QUICK FIX
Set the REPLICATE_API_TOKEN environment variable with a valid token authorized for the private model before calling the API.

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

1

No API token or environment variable REPLICATE_API_TOKEN is not set

✓ Fix

Set the REPLICATE_API_TOKEN environment variable with a valid token that has access to the private model.

2

API token does not have permission to access the requested private model

✓ Fix

Use an API token from a user or organization that owns or has been granted access to the private model.

3

Incorrect model identifier or owner name in the model path

✓ Fix

Verify the model path string matches exactly the private model's owner and name as registered on Replicate.

Code: broken vs fixed

Broken - triggers the error
python
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)
Fixed - works correctly
python
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)
Added REPLICATE_API_TOKEN environment variable with a valid token to authorize access to the private model, preventing permission denied errors.

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.

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

Community Notes

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