Skip to content

Conversation

@renemrhfr
Copy link

This PR adds support for Replicate.com as described in #4728
Replicate is a provider for various AI Models for text generation, image/video/audio, embeddings and more.

As the models differ in their input and output parameters, the challenge was to provide generalized Classes to be flexible but still abstract the details.

My idea was to provide four main models: Chat, Classifier, Media and Structured Output (like Embeddings) for easy usage.

Key Changes

  • New Model Module: spring-ai-replicate
  • Implementation:
    • ReplicateApi: For interaction with Replicate.com. Handles blocking or streaming chat responses and replicates way of retrieving the "Prediction Status"
    • ReplicateChatModel.java implements ChatModel and is used for LLMs like Claude, GPT, Grok etc.
    • ReplicateMediaModel.java for models that generate Media (Images, Video and Audio). Replicate responds with an url, so instead of implementing ImageModel i provided a more general implementation here.
    • ReplicateStringModel.java For Models that respond with a String, for example Image Classifiers.
    • ReplicateStructuredModel.java For Models that respond with structured output, like Embedding Models.
    • ReplicateChatOptions.java Implements ChatOptions
    • ReplicateOptions.java Flexible Parameters to interact with all kinds of Models on Replicate.
    • ReplicateOptionsUtils.java Helper Class to Convert String values from application.properties to their correct type. As Replicate accepts various different types in the "input" Parameter, it is not possible to provide a type in the "input" Map, instead we convert it in this class.
  • New Enum in AiProvider.java
  • Added Auto-Configuration
    • ReplicateChatAutoConfiguration.java for configuring the ChatModel
    • ReplicateChatProperties.java
    • ReplicateConnectionProperties.java for configuring the Connection, with BASE_URL and API-Token
    • ReplicateMediaProperties.java Properties for setting up a media model
    • ReplicateStringProperties.java Properties for setting up a String Model
    • ReplicateStructuredProperties.java Properties for setting up a Structured Output Model

Why this Implementation

The structure differs from provider-specific model interfaces due to replicate being a host of hundreds of different models with varying input/output schemas.
So instead of having hundreds of implementations i provided four flexible adapters.

I am more than happy to iterate on this based on feedback and would be excited to contribute this to Spring AI

I use this a lot in my personal projects and think this would be a great addition.

Closes #4728

Signed-off-by: renemrhfr <rene.maierhofer@gmail.com>
@renemrhfr renemrhfr changed the title Implements ReplicateApi Feature: Support for Replicate.com Nov 1, 2025
@renemrhfr renemrhfr changed the title Feature: Support for Replicate.com feat: Support for Replicate.com Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Replicate.com

1 participant