# Class ChatCompletionsHttpClient

java.lang.Object
com.google.adk.models.chat.ChatCompletionsHttpClient

public class ChatCompletionsHttpClient extends Object
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

  Constructors
  Constructor
  Description
  `ChatCompletionsHttpClient(com.google.genai.types.HttpOptions httpOptions)`
  Constructs a new `ChatCompletionsHttpClient` that facilitates API interaction with the standard `/chat/completions` REST endpoint.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ChatCompletionsHttpClient

    public ChatCompletionsHttpClient(com.google.genai.types.HttpOptions httpOptions)
    Constructs a new `ChatCompletionsHttpClient` that facilitates API interaction with the standard `/chat/completions` REST endpoint.

    All configuration is sourced from the supplied `HttpOptions`:

    - `HttpOptions.baseUrl()` -- required. The base URL of the chat completions endpoint. The `chat/completions` path segments are appended automatically using `HttpUrl`, which handles trailing slashes and percent-encoding deterministically. Set via `HttpOptions.builder().baseUrl("https://...").build()`.
    - `HttpOptions.headers()` -- optional. Extra HTTP headers to include in outgoing requests. The `Content-Type` header is set automatically and cannot be overridden. Set via `HttpOptions.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 of `0` is respected as the explicit caller opt-in to infinite wait. Set via `HttpOptions.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 be `null`, and `HttpOptions.baseUrl()` must be present and parseable as an HTTP(S) URL.
    Throws:
      `IllegalArgumentException` - if `httpOptions.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 `Flowable` emitting the discrete (or combined) `LlmResponse` objects.