Class ChatCompletionsHttpClient
java.lang.Object
com.google.adk.models.chat.ChatCompletionsHttpClient
An HTTP client for interacting with OpenAI-compatible chat completions endpoints.
Supports both non-streaming responses (single LlmResponse emission) and streaming
Server-Sent Events (SSE) responses (multiple incremental LlmResponse emissions). See the
OpenAI Chat Completions API
reference for the wire protocol.
-
Constructor Summary
ConstructorsConstructorDescriptionChatCompletionsHttpClient(com.google.genai.types.HttpOptions httpOptions) Constructs a newChatCompletionsHttpClientthat facilitates API interaction with the standard/chat/completionsREST endpoint. -
Method Summary
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Flowable<LlmResponse> complete(LlmRequest llmRequest, boolean stream) Generates a conversational response from the chat completions endpoint based on the provided messages.
-
Constructor Details
-
ChatCompletionsHttpClient
public ChatCompletionsHttpClient(com.google.genai.types.HttpOptions httpOptions) Constructs a newChatCompletionsHttpClientthat facilitates API interaction with the standard/chat/completionsREST endpoint.All configuration is sourced from the supplied
HttpOptions:HttpOptions.baseUrl()-- required. The base URL of the chat completions endpoint. Thechat/completionspath segments are appended automatically usingHttpUrl, which handles trailing slashes and percent-encoding deterministically. Set viaHttpOptions.builder().baseUrl("https://...").build().HttpOptions.headers()-- optional. Extra HTTP headers to include in outgoing requests. TheContent-Typeheader is set automatically and cannot be overridden. Set viaHttpOptions.builder().headers(Map.of("Authorization", "Bearer ...")).HttpOptions.timeout()-- optional. Per-call timeout in milliseconds. A missing timeout defaults to 5 minutes (DEFAULT_CALL_TIMEOUT). A timeout of0is respected as the explicit caller opt-in to infinite wait. Set viaHttpOptions.builder().timeout(10_000).build().
Example:
HttpOptions options = HttpOptions.builder() .baseUrl("https://example.com/v1/") .headers(ImmutableMap.of("Authorization", "Bearer my-token")) .timeout(30_000) .build(); ChatCompletionsHttpClient client = new ChatCompletionsHttpClient(options);- Parameters:
httpOptions- HTTP configuration. Must not benull, andHttpOptions.baseUrl()must be present and parseable as an HTTP(S) URL.- Throws:
IllegalArgumentException- ifhttpOptions.baseUrl()is missing or is not a valid HTTP(S) URL.
-
-
Method Details
-
complete
public io.reactivex.rxjava3.core.Flowable<LlmResponse> complete(LlmRequest llmRequest, boolean stream) Generates a conversational response from the chat completions endpoint based on the provided messages. This encapsulates building the HTTP payload, sending the request to the completions endpoint, and initiating the handling of complete calls.- Parameters:
llmRequest- The request containing the model, configuration, and sequence of messages.stream- Whether to request a streaming response.- Returns:
- A
Flowableemitting the discrete (or combined)LlmResponseobjects.
-