Interface LLMClient
- All Superinterfaces:
Client
- All Known Implementing Classes:
AbstractLLMClient, AbstractOpenAIChatClient, AnthropicBedrockMantleSDKClient, AnthropicBedrockSDKClient, AnthropicSDKClient, AzureFoundryOpenAIClient, BedrockConverseClient, OpenAICompatibleClient, OpenAISDKClient
Interface for LLM client implementations across different providers.
Provides unified API for text generation with structured output support.
- Since:
- 0.1 (2025-07-18)
- Author:
- Andrey Santrosyan
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()Releases resources held by this client (e.g., HTTP connection pools).<T> OutgoingMessage<T> createOutgoingMessage(ResponseHandler<T> responseHandler) Creates a new conversation message appropriate for this client.Gets the API dialect for this client.Gets the content formatter for this client.The caller-set sampling temperature, or null when none was set and the provider's own default applies.voidsetTemperature(Double temperature) Sets the sampling temperature this client's requests carry.<T> LLMResponse<T> singleResponse(LLMRequest<T> request) Gets a structured response from the LLM with retry logic and validation.default <T> LLMResponse<T> streamResponse(LLMRequest<T> request, Consumer<StreamChunk> chunkHandler) Streams response chunks from the LLM and returns the full response record.
-
Method Details
-
singleResponse
Gets a structured response from the LLM with retry logic and validation. Returns an LLMResponse with successful=false if the request fails.- Parameters:
request- The LLM request with prompt, retry settings, and optional JSON validation- Returns:
- The LLM response with metadata, tokens used, and parsed response
- Throws:
TokenEstimateExceedsLimitException- if pre-flight estimate exceeds model limits
-
getTemperature
Double getTemperature()The caller-set sampling temperature, or null when none was set and the provider's own default applies. -
setTemperature
Sets the sampling temperature this client's requests carry. Unset (null, the default), no temperature reaches the wire and the provider's own default applies - which is also what keeps the models that accept no sampling parameter callable. A temperature set on a model that rejects it comes back as the provider's own typed refusal. -
getModelIdentifier
String getModelIdentifier() -
createOutgoingMessage
Creates a new conversation message appropriate for this client. Different providers may return different message implementations (e.g., AnthropicMessage, OpenAIMessage) with provider-specific validation.- Returns:
- a new empty conversation message
-
streamResponse
default <T> LLMResponse<T> streamResponse(LLMRequest<T> request, Consumer<StreamChunk> chunkHandler) throws TokenEstimateExceedsLimitException Streams response chunks from the LLM and returns the full response record. ThechunkHandlerreceives each delta as it arrives; the returnedLLMResponsecarries token usage, cache counters, stop reason, provider, and other fields populated by the client.- Returns:
- the populated response (check
LLMResponse.isSuccessful()) - Throws:
TokenEstimateExceedsLimitException- if pre-flight estimate exceeds model limits
-
close
default void close()Releases resources held by this client (e.g., HTTP connection pools). Called during application shutdown for shared clients. -
getFormatter
ContentFormatter getFormatter()Gets the content formatter for this client. Formatters handle provider-specific content encoding.- Returns:
- the content formatter
-
getDialect
APIDialect getDialect()Gets the API dialect for this client. Used to determine encoding strategies and compatibility.- Returns:
- the API dialect
-