
Replicate allows you to run thousands of open-source AI models via a simple, pay-per-use API. It supports Stable Diffusion, Llama, Whisper, and many other models. It is suitable for developers who want to quickly prototype with AI.
Create Account and Obtain API Token
Register for a Replicate account and obtain an authentication token to call the API.
Register at replicate.com, go to Account Settings > API Tokens, copy the token and save it to the environment variable `REPLICATE_API_TOKEN`.
Do not commit the token to git, use the .env file and add .env to .gitignore.
Select the Appropriate Model on Replicate Explore
Find a suitable image generation model that meets your needs and review the specific input/output documentation for that model.
Go to replicate.com/explore, search for a model like 'stability-ai/sdxl', view the API tab to know the required parameter format.
Test the model directly on Replicate's web UI first to understand the output before writing integration code.
Install SDK and Test API Call
Install the official client library and make a test call to the model from backend code.
Run `npm install replicate`, then call `replicate.run("stability-ai/sdxl:version-id", { input: { prompt: "..." } })`.
Always pin the correct version ID of the model in code to avoid unexpected output changes when the model is updated.
Handle Asynchronous Processing and Status Checks
Manage situations where the model does not return results immediately, needing to monitor the prediction status.
Use a webhook or polling via `replicate.predictions.get(id)` to check the status 'starting', 'processing', 'succeeded'.
Prefer using webhooks instead of continuous polling to reduce load and get results faster once processing is complete.
Save Results and Limit Costs
Save the resulting images to a separate storage and set limits to control usage costs.
Download the image from the result URL to save it in S3/Supabase Storage, while setting limits on the number of calls per user per day in the application code.
Monitor the usage dashboard on Replicate weekly to detect any unusual cost increases early.
No reviews yet - be the first to share your experience.
Log in to leave a review.
Pros
Cons
A small fashion brand needs to quickly create product mockup images in various contexts without the need for studio photography.
Problem
The cost of hiring a studio and models for each new collection amounts to tens of millions of VND, while the marketing budget is limited.
Solution
Use Replicate to call APIs from open-source image generation models (like SDXL) to create product mockup images in various contexts, integrating directly into the internal product management system.
A small e-commerce platform wants sellers to automatically remove product image backgrounds when listing without needing Photoshop.
Problem
The dev team lacks expertise in computer vision and does not want to train or host a background removal model themselves.
Solution
Integrate an existing background removal model API from Replicate directly into the product listing flow, processing images as soon as sellers upload them.