dev-tools 6 min read

Replicate: Run Open-Source ML Models With One API Call

Replicate is a cloud API for running thousands of open-source machine learning models — image, video, audio, and LLM — billed by compute time, no infra to manage.

By
Share: X in
Replicate cloud API for running open-source machine learning models

TL;DR: Replicate hosts thousands of open-source ML models behind a single HTTP API. You send a model identifier and an input, you get back the output — image, audio, video, text. Pricing is per-second of GPU time, no cluster to babysit. If you want to call Stable Diffusion, Whisper, Llama, or any of the long tail of community models without standing up your own inference stack, this is the shortest path.

What it is

Replicate is a cloud API for running open-source machine learning models. The homepage describes it as “Run open-source machine learning models with a cloud API,” and the company page frames the mission as “bringing AI to every software developer.” The catalog covers image generation, video synthesis, speech recognition, music generation, embeddings, and a wide selection of LLMs, plus a long tail of specialized models uploaded by the community. Every model is reachable through the same uniform interface: a model identifier in the form owner/name, an input dictionary, and a JSON or file response.

The platform launched as a YC W20 company in November 2020 with positioning as “version control for machine learning.” The current product is closer to a hosted inference layer than a model registry: you do not upload weights to get predictions, you call existing models with your own inputs. That pivot is the reason the API is the headline feature today. Replicate handles GPU provisioning, scaling, model versioning, and per-request billing. You bring the prompt, the audio file, or the input image.

The model catalog is large. Replicate exposes thousands of community-contributed models, and the same API works for the popular ones (Stable Diffusion variants, Whisper, Llama, Flux, MusicGen) and the long tail of niche fine-tunes. The Python and TypeScript clients follow the same shape: install the package, set the API token, call replicate.run("owner/name", input={...}).

Why it matters

Self-hosting an open-source model is a real engineering project. You need a GPU box, the right driver stack, a serving runtime such as vLLM, TEXT generation inference, or TensorRT, a queue for bursty traffic, a way to handle cold starts, and a plan for what happens when the model is too big to fit in one GPU’s memory. The reason companies reach for Replicate is that none of that is the actual product — the actual product is the output of the model, and the model is a tool the developer is trying to use.

The economic model is pay-per-use on GPU time. Image models are billed by the second, audio models by the second, and language models by token. There is no monthly minimum for the API itself; the entry point is the API token, and the bill scales with what you actually run. For prototypes, side projects, and small production workloads, that pricing math usually beats running a GPU server that sits idle most of the time.

The API also gives you a stable contract. A model on Replicate has a versioned identifier, a typed input schema, and a typed output schema. If a model maintainer pushes a new version, the old one stays addressable until you migrate, which matters for production traffic. Replicate exposes webhooks for async runs, streaming for models that produce token-by-token output, and a predictions endpoint that returns intermediate logs.

Getting it running

The Python path is the fastest way to try the API. Install the official client and call any model by its owner/name identifier.

pip install replicate
export REPLICATE_API_TOKEN=r8_...

The token comes from the account settings page. Once the environment variable is set, calling a model is one function.

import replicate

output = replicate.run(
    "black-forest-labs/flux-schnell",
    input={
        "prompt": "a tiny wooden cabin on a snowfield at dusk, watercolor",
        "num_outputs": 1,
    },
)

print(output[0])

That call spins up a GPU, runs Flux Schnell on your prompt, returns the image URL, and tears the worker down. The same pattern works for audio, video, and LLM models — only the input dictionary changes. The TypeScript client follows the same shape for Next.js and other Node environments.

npm install replicate
import Replicate from "replicate";

const replicate = new Replicate({
  auth: process.env.REPLICATE_API_TOKEN!,
});

const output = await replicate.run(
  "black-forest-labs/flux-schnell",
  { input: { prompt: "a lighthouse on a rocky coast at sunrise" } }
);

console.log(output);

For longer-running jobs such as video synthesis, the API returns a prediction object with a polling URL or a webhook. The official docs at replicate.com/docs walk through the async flow, the streaming flow, and the webhook flow for each major client.

What to watch for

The token is a billing credential. Treat it like any other API key — keep it in an environment variable, rotate it on personnel changes, and never commit it. Replicate offers per-token usage limits in the dashboard if you need a guardrail for an internal tool.

Latency depends on the model and the queue. Image generation is usually a few seconds, video models can run for minutes, and large LLMs may have cold-start delay on the first call after a quiet period. For production user-facing traffic, plan for warm-up and consider pinning to a specific model version rather than the default @latest pointer.

A few practical tradeoffs are worth keeping in mind. The catalog is community-curated, so model quality varies and the maintainer of any given model can pull it or replace it with a different version. Pricing is per-second on the GPU the model needs, so the same call is cheaper on a smaller model and more expensive on a multi-GPU LLM. Data goes through Replicate’s infrastructure — if your workload has data-residency or compliance constraints, run the model behind your own deployment instead.

If you only need one model at production scale, self-hosting is often cheaper past a few thousand requests per month. Replicate is the right answer when you want many models available through one API, when your traffic is bursty, or when the engineering time to stand up inference is more expensive than the bill.

Source and Accuracy Notes