Getting started with a public model

Back to API documentation

This is a beta release and will likely change! Please share your feedback in our Discord server or email us at 🙌

Replicate's API lets you run machine learning models on Replicate in the cloud from your own code, without having to set up any servers. You can run models from apps, notebooks, evaluation scripts, or anywhere else you want to use machine learning.

Only certain models have opted-in to use the API. Here are the models you can run:

We're working with model authors to get more added.

Subscribe to Replicate

Before using the API, you'll need to sign up to Replicate and subscribe for $10/mo to cover the cost of the GPUs.

Install the Python library

First, install the Python library from pip:

pip install replicate


Authenticate by setting your token in an environment variable:

export REPLICATE_API_TOKEN=<token>

Run predictions

Then, you can run models on Replicate from your Python code:

$ python
>>> import replicate
>>> model = replicate.models.get("replicate/hello-world")
>>> model.predict(text="python")
"hello python"

To pass files as input, use a file handle or URL:

>>> model = replicate.models.get("replicate/resnet")
>>> model.predict(image=open("mystery.jpg", "rb"))
# or...
>>> model.predict(image="")

URLs are more efficient if your file is already in the cloud somewhere, or it is a large file. Files are output as URLs.

Some models output progressively, as the model is running. They will return an iterator and you can iterate over that output:

>>> model = replicate.models.get("pixray/text2image")
>>> for image in model.predict(prompts="robots talking to robots"):
...    print(image)

For more details, see the full documentation on GitHub.

You can also run models with the raw HTTP API. See the HTTP API reference for more details.

Next steps

Back to API documentation

Replicate Reproducible machine learning