Read through this guide to set up Replicate & get familiar with how it is used in the different demo apps.

Set up Replicate

First, create an Replicate account or sign in. Next, navigate to the API key page and “Create token”. Make sure to save this somewhere safe and do not share it with anyone.

Once you have your API key, paste it in your .env file:

REPLICATE_API_TOKEN=your_replicate_api_key

Demo app

The Image Generation Studio uses Stable Diffusion XL (SDXL) via the Replicate API for image generation. You can find more information about it below:

Structure

Under app/api/replicate/sdxl/route.ts you’ll find the route used to make an API call to SDXL through Replicate.

/api/replicate/sdxl/route.ts
import { replicate } from "@/lib/replicate";

// Generate response from Replicate
const responseData = await replicate.run(toolConfig.aiModel, {
  input: {
    width: 768,
    height: 768,
    prompt: prompt,
    refine: "expert_ensemble_refiner",
    scheduler: "K_EULER",
    lora_scale: 0.6,
    num_outputs: 1,
    guidance_scale: 7.5,
    apply_watermark: false,
    high_noise_frac: 0.8,
    negative_prompt: negativePrompt,
    prompt_strength: 0.8,
    num_inference_steps: 25,
  },
});

// Get the image URL from the Replicate response
const imageUrl = responseData;

// Prepare the data for upload
const uploadData = {
  imageUrl,
  uploadPath: toolConfig.upload.path,
};

// See file for more logic

For the audio app, please check out the Voice to notes section for more info.

You’ll find the entire + documentation on what each part does in the file itself.

More information on structure of the codebase can be found here:

Structure

Understand the project structure of the codebase