Replicate Python Client
Python client for running ML models on Replicate's cloud API. v0.x stable client is at 1.x on PyPI. A v2.0 beta (replicate-python-beta) exists as a separate package with a redesigned API. replicate.stream() is deprecated in v2. Billing changed to prepaid credit for new accounts in July 2025.
Warnings
- breaking replicate.run() output for image models is a list of FileOutput objects, not URLs or strings. Treating output[0] as a string raises AttributeError.
- breaking v2.0 alpha (replicate-python-beta) has a completely redesigned API with replicate.use() replacing replicate.run(). The two packages are incompatible — do not mix v1 and v2 patterns.
- deprecated replicate.stream() is deprecated in v2 SDK. Still available for v1 backwards compatibility but will be removed.
- gotcha Model versions are pinned by hash in many tutorials (e.g. 'owner/model:abc123'). Pinned version hashes go stale as models are updated. Unpinned calls use the latest deployment which may have different inputs/outputs.
- gotcha replicate.run() is synchronous and blocks until the prediction completes. For long-running models this can block for minutes.
- gotcha New Replicate accounts (post July 2025) use prepaid credit billing, not monthly billing. API calls will fail with 402 if credit balance is zero, unlike monthly billing which allows negative balances until invoice.
Install
-
pip install replicate -
pip install replicate==2.0.0a16
Imports
- replicate
import replicate output = replicate.run("owner/model", input={...}) - AsyncReplicate
from replicate import AsyncReplicate client = AsyncReplicate()
Quickstart
import replicate
output = replicate.run(
"black-forest-labs/flux-schnell",
input={"prompt": "an iguana on the beach"}
)
# output is a list of FileOutput objects for image models
with open('output.png', 'wb') as f:
f.write(output[0].read())