Class MistralAiApi
java.lang.Object
org.springframework.ai.mistralai.api.MistralAiApi
Single-class, Java Client library for Mistral AI platform. Provides implementation for
the Embeddings
and the Chat
Completion APIs.
Implements Synchronous and Streaming chat completion and supports latest Function Calling features.
- Since:
- 1.0.0
- Author:
- Ricken Bazolo, Christian Tzolov, Thomas Vitale, Jason Smith
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final recordRepresents a chat completion response returned by model, based on the provided input.static final recordRepresents a streamed chunk of a chat completion response returned by model, based on the provided input.static enumThe reason the model stopped generating tokens.static final recordMessage comprising the conversation.static final recordCreates a model request for chat conversation.static enumList of well-known Mistral chat models.static final recordRepresents an embedding vector returned by embedding endpoint.static final recordList of multiple embedding responses.static enumList of well-known Mistral embedding models.static final recordCreates an embedding vector representing the input text.static classRepresents a tool the model may call.static final recordLog probability information for the choice.static final recordUsage statistics. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMistralAiApi(String apiKey) Deprecated.MistralAiApi(String baseUrl, String apiKey) Deprecated.MistralAiApi(String baseUrl, String apiKey, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler) Deprecated.MistralAiApi(String baseUrl, String apiKey, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler) Create a new client api. -
Method Summary
Modifier and TypeMethodDescriptionstatic MistralAiApi.Builderbuilder()org.springframework.http.ResponseEntity<MistralAiApi.ChatCompletion>chatCompletionEntity(MistralAiApi.ChatCompletionRequest chatRequest) Creates a model response for the given chat conversation.reactor.core.publisher.Flux<MistralAiApi.ChatCompletionChunk>chatCompletionStream(MistralAiApi.ChatCompletionRequest chatRequest) Creates a streaming chat response for the given chat conversation.<T> org.springframework.http.ResponseEntity<MistralAiApi.EmbeddingList<MistralAiApi.Embedding>>embeddings(MistralAiApi.EmbeddingRequest<T> embeddingRequest) Creates an embedding vector representing the input text or token array.
-
Field Details
-
PROVIDER_NAME
-
-
Constructor Details
-
MistralAiApi
Deprecated.Create a new client api with DEFAULT_BASE_URL- Parameters:
apiKey- Mistral api Key.
-
MistralAiApi
Deprecated.Create a new client api.- Parameters:
baseUrl- api base URL.apiKey- Mistral api Key.
-
MistralAiApi
@Deprecated public MistralAiApi(String baseUrl, String apiKey, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler) Deprecated.Create a new client api.- Parameters:
baseUrl- api base URL.apiKey- Mistral api Key.restClientBuilder- RestClient builder.responseErrorHandler- Response error handler.
-
MistralAiApi
public MistralAiApi(String baseUrl, String apiKey, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler) Create a new client api.- Parameters:
baseUrl- api base URL.apiKey- Mistral api Key.restClientBuilder- RestClient builder.responseErrorHandler- Response error handler.
-
-
Method Details
-
builder
-
embeddings
public <T> org.springframework.http.ResponseEntity<MistralAiApi.EmbeddingList<MistralAiApi.Embedding>> embeddings(MistralAiApi.EmbeddingRequest<T> embeddingRequest) Creates an embedding vector representing the input text or token array.- Type Parameters:
T- Type of the entity in the data list. Can be aStringorListof tokens (e.g. Integers). For embedding multiple inputs in a single request, You can pass aListofStringorListofListof tokens. For example:List.of("text1", "text2", "text3") or List.of(List.of(1, 2, 3), List.of(3, 4, 5))- Parameters:
embeddingRequest- The embedding request.- Returns:
- Returns list of
MistralAiApi.Embeddingwrapped inMistralAiApi.EmbeddingList.
-
chatCompletionEntity
public org.springframework.http.ResponseEntity<MistralAiApi.ChatCompletion> chatCompletionEntity(MistralAiApi.ChatCompletionRequest chatRequest) Creates a model response for the given chat conversation.- Parameters:
chatRequest- The chat completion request.- Returns:
- Entity response with
MistralAiApi.ChatCompletionas a body and HTTP status code and headers.
-
chatCompletionStream
public reactor.core.publisher.Flux<MistralAiApi.ChatCompletionChunk> chatCompletionStream(MistralAiApi.ChatCompletionRequest chatRequest) Creates a streaming chat response for the given chat conversation.- Parameters:
chatRequest- The chat completion request. Must have the stream property set to true.- Returns:
- Returns a
Fluxstream from chat completion chunks.
-