java.lang.Object
com.agentforge4j.llm.AbstractHttpLlmClient
- All Implemented Interfaces:
LlmClient
Base
LlmClient for HTTP JSON APIs: shared validation, transport, logging, and error
wrapping.
Subclasses implement:
buildHttpRequest(LlmExecutionRequest)— vendor-specific request shape and headersvalidateAndExtractResponse(String)— parse success responses into text and optional token usage
execute(LlmExecutionRequest) orchestrates build, send, status check, and extraction.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an HTTP-backed client from configuration (provider id, default model, connect timeout). -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract HttpRequestbuildHttpRequest(LlmExecutionRequest request) Builds the outbound HTTP request for one execution.final LlmExecutionResponseexecute(LlmExecutionRequest request) Sends one LLM request for this client's provider.The retry policy this client requests, ornullif it has none.protected abstract LlmExecutionResponseParses a successful HTTP body into model output and optional provider token usage.protected final voidwarnIfApiKeyOverPlainHttp(String url, String apiKey) Logs a warning when an API key is configured together with a plainhttp://endpoint, because the key would be sent unencrypted.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.agentforge4j.llm.api.LlmClient
getProviderName
-
Constructor Details
-
AbstractHttpLlmClient
Constructs an HTTP-backed client from configuration (provider id, default model, connect timeout).- Parameters:
config- non-null provider configuration- Throws:
IllegalArgumentException- if provider id or default model is blank
-
-
Method Details
-
getRetryPolicy
Description copied from interface:LlmClientThe retry policy this client requests, ornullif it has none. Callers that need a policy either way should fall back toLlmRetryPolicy.defaults()on anullreturn.- Specified by:
getRetryPolicyin interfaceLlmClient- Returns:
- the requested retry policy, or
nullwhen this client has none
-
warnIfApiKeyOverPlainHttp
Logs a warning when an API key is configured together with a plainhttp://endpoint, because the key would be sent unencrypted. Local key-less deployments (Ollama, vLLM) never trigger this. Call from provider constructors after URL and key are resolved.- Parameters:
url- the configured endpoint URL; no warning whennullor blankapiKey- the configured API key; no warning whennullor blank
-
buildHttpRequest
Builds the outbound HTTP request for one execution.- Parameters:
request- validated execution parameters- Returns:
- request ready to send
-
validateAndExtractResponse
Parses a successful HTTP body into model output and optional provider token usage.- Parameters:
json- raw HTTP response body- Returns:
- execution response with extracted text;
LlmExecutionResponse.tokenUsage()isnullwhen the provider returned no usage block - Throws:
IOException- if the body is malformed or indicates failure
-
execute
Sends one LLM request for this client's provider.Steps:
- Validates request parameters
- Resolves model (uses request model or falls back to default)
- Builds the HTTP request via
buildHttpRequest(LlmExecutionRequest) - Sends the request and handles the response
- Validates HTTP status code is 2xx
- Extracts and returns the response via
validateAndExtractResponse(String)
- Specified by:
executein interfaceLlmClient- Parameters:
request- the LLM execution request- Returns:
- execution response with extracted model output and provider token usage when reported
- Throws:
LlmInvocationException- if the request fails due to network issues, HTTP errors, or invalid responsesIllegalArgumentException- if the request is invalid
-