An org.llm4s.http.Llm4sHttpClient over an sttp 4 synchronous backend, so the provider clients send their requests through the HTTP stack a service already has: its connection pool, proxy and TLS settings, logging and tracing middleware, or a stub backend in tests. Pass it with LlmClientOptions.withHttpClient.
It behaves as Llm4sHttpClient.create() does: a non-2xx status is a Right response, response headers are keyed in lower case, postStream hands back the open body (asInputStreamAlwaysUnsafe) for the caller to close, and a transport failure is the same Left - a TimeoutError for a timeout, a NetworkError for a refused connection or an I/O failure, a ValidationError for an invalid URL or an unreadable multipart file, a CancelledError for an interrupt. Each request's timeout is its sttp readTimeout.
The caller owns backend: closing this client does not close it.
Value parameters
backend
any sttp 4 synchronous backend, such as DefaultSyncBackend() wrapped in your middleware, or a SyncBackendStub
POST with a string body and return the response as raw bytes, bypassing charset decoding.
POST with a string body and return the response as raw bytes, bypassing charset decoding.
Use this when the response body is binary (e.g. image data) where decoding to a String and back would corrupt bytes that are not valid in the chosen charset.
POST with a string body and return the response as a streaming InputStream.
POST with a string body and return the response as a streaming InputStream.
Use this for server-sent events or JSON-lines endpoints where the body must be consumed incrementally. The caller is responsible for closing the InputStream, including on a non-2xx status. A failure while reading the stream surfaces as an IOException from the stream itself, not through the returned Result.
Default timeout is 10 minutes to accommodate long-running streams.
Releases the connections and threads this client holds. A no-op unless the implementation holds any; a client that owns one of these closes it when it is itself closed.
Releases the connections and threads this client holds. A no-op unless the implementation holds any; a client that owns one of these closes it when it is itself closed.