Prerequisites
- Sign up for a Replicate account
- Create a Replicate API key
Setup
- Add the Replicate API key to your environment variables
.env
- The Starter-Kit already includes the necessary configuration for Replicate in
src/lib/ai/replicate.ts
, if you have selected the Replicate Provider via the CLI. This file initializes the Replicate client with your API token.
Usage
To use Replicate AI in your application, you can create an API route that interacts with the Replicate client. This route can be used to generate images, text, and more using the AI models provided by Replicate. Create a new file in your API routes directory (e.g.,app/api/replicate/route.ts
). This file will contain the logic for interacting with the Replicate client.
Here’s an example of how to set up a route that uses the Flux model: