Class ReplicateImageProvider

Implements

Constructors

Methods

  • Edits an image using a Replicate model that supports image-to-image input.

    Uses black-forest-labs/flux-fill for inpainting (when a mask is provided) or falls back to stability-ai/sdxl for generic img2img transforms. The source image goes in the model input as a data URL of its type, or, from 1 MB, as a file uploaded to Replicate's Files API.

    Parameters

    • request: ImageEditRequest

      Edit request with source image, prompt, and optional mask.

    Returns Promise<ImageGenerationResult>

    Generation result with the edited image(s).

    Throws

    When the provider is not initialised or the API fails.

  • The model a style transfer runs on for modelId, or a refusal. An empty id takes the configured default when it is one of REPLICATE_STYLE_TRANSFER_MODELS, else FLUX.2 Pro. A named model must be one of them, unless the provider's base URL is not Replicate's; it is run by its name on the model endpoint, so a pinned version (owner/name:version) is refused.

    Parameters

    • modelId: string

      The model the call names, or an empty string.

    Returns string

    Throws

    For a model the style transfer does not run.

  • Restyles an image after a style reference on a FLUX.2 model, which takes both as input_images, the source first, with an instruction that names them by index ("point to other reference images by their index number", https://replicate.com/black-forest-labs/flux-2-pro). FLUX.2 takes no strength and no negative prompt: strength picks the instruction (see styleTransfer.ts), and the output keeps the source's aspect ratio (match_input_image) unless providerOptions.input sets another.

    The call's prompt and its two images are what it sends, so a providerOptions.input naming prompt, input_images, image or input_image is refused, and so is providerOptions.extraBody, which could pin another version or replace the input. The prediction must end succeeded; a failed, canceled or unfinished one throws.

    Parameters

    Returns Promise<ImageGenerationResult>

    Generation result with the restyled image(s).

    Throws

    When the provider is not initialised, the model, an image or an option is refused, the API fails, the prediction does not succeed, or its output holds no image.

Properties

providerId: "replicate" = 'replicate'
isInitialized: boolean = false
defaultModelId?: string