Replicate Python API Library

The Replicate Python library provides convenient access to the Replicate REST API from any Python 3.9+ application. The library includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients powered by httpx.

Documentation

The REST API documentation can be found on replicate.com.

Installation

pip install replicate

Usage

import os
from replicate import Replicate

replicate = Replicate(
    bearer_token=os.environ.get("REPLICATE_API_TOKEN"),  # This is the default and can be omitted
)

prediction = replicate.predictions.get(
    prediction_id="gm3qorzdhgbfurvjtvhg6dckhu",
)
print(prediction.id)

While you can provide a bearer_token keyword argument, we recommend using python-dotenv to add REPLICATE_API_TOKEN="My Bearer Token" to your .env file so that your Bearer Token is not stored in source control.