Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Const

Replicate

replicate is the default Replicate provider from @ai-sdk/replicate. Use replicate.image(modelId) to create an image model for AI SDK generation functions.

How it works

replicate is the default provider instance exported by @ai-sdk/replicate. Call its .image(modelId) factory to obtain a Replicate image model, then pass that model to the AI SDK image-generation function. Authentication uses the REPLICATE_API_TOKEN environment variable by default, or a custom provider can be created with createReplicate.

Syntax

replicate.image(modelId)

Parameters

NameTypeDescription
modelIdstringReplicate model identifier, such as black-forest-labs/flux-schnell.

Returns

A Replicate image model object suitable for use with AI SDK image-generation APIs.

Key points

  • Install the provider package and import the default replicate instance from @ai-sdk/replicate.
  • The exported replicate value is ready to use without constructing a provider.
  • Call replicate.image(modelId) to create the image model passed to AI SDK generation APIs.
  • Requests use Replicate's v1 API endpoint by default.
  • Use createReplicate when the default provider configuration is not sufficient.

Common mistakes

  • Image options are model-specific; check the selected Replicate model's documentation before passing size or other provider options.
  • The default provider expects the Replicate token in the REPLICATE_API_TOKEN environment variable unless you configure a custom token.

Example: Generate an image with Replicate

import { replicate } from '@ai-sdk/replicate';
import { experimental_generateImage as generateImage } from 'ai';

const { image } = await generateImage({
  model: replicate.image('black-forest-labs/flux-schnell'),
  prompt: 'A lighthouse on a snowy island at sunrise',
  aspectRatio: '16:9',
});

console.log(image.base64);

Creates an image with a Replicate model and prints the returned image as base64 data.

When to use it

Text-to-image generation

Generate images from text prompts using supported Replicate image models.

Model experimentation

Select different Replicate models by changing the model identifier.

Custom provider configuration

Route API calls through a proxy or supply a token explicitly.

  • createReplicate
  • replicate.image
  • experimental_generateImage
  • providerOptions.replicate

Source: Replicate - AI SDK. Checked 2026-10-15.