Package org.mockserver.llm.client
Interface LlmClient
- All Known Implementing Classes:
AbstractLlmClient,AnthropicLlmClient,AzureOpenAiLlmClient,BedrockLlmClient,GeminiLlmClient,OllamaLlmClient,OpenAiLlmClient,OpenAiResponsesLlmClient
public interface LlmClient
Per-provider knowledge for calling a real LLM as a client. Mirrors
ProviderCodec (which goes the other way —
decoding inbound requests / encoding mock responses): an LlmClient
builds an outbound request and parses the inbound response
into a Completion.
Deliberately split from transport: implementations are pure functions of
their inputs (no network, no shared state), so they unit-test offline. The
actual HTTP call, timeouts, fail-closed handling, and caching live in
LlmCompletionService. Adding a provider = implement this interface
and register it in LlmClientRegistry — the same one-line story as
codecs.
-
Method Summary
Modifier and TypeMethodDescriptionbuildCompletionRequest(LlmBackend backend, ParsedConversation prompt) Build the outbound completion request (URL path, auth headers, request body) for the given backend and prompt.parseCompletionResponse(HttpResponse response) Parse a successful provider response body into aCompletion.provider()The provider this client handles — the registry key.
-
Method Details
-
provider
Provider provider()The provider this client handles — the registry key. -
buildCompletionRequest
Build the outbound completion request (URL path, auth headers, request body) for the given backend and prompt. The returned request carries the socket address resolved from the backend's base URL (or the provider default). Implementations pintemperature=0and a seed where the provider supports it, for reproducibility. -
parseCompletionResponse
Parse a successful provider response body into aCompletion. Implementations should tolerate missing optional fields and never throw for a well-formed-but-sparse response; malformed bodies may throw and are handled (fail-closed) byLlmCompletionService.
-