Llm4sHttpClient

org.llm4s.http.Llm4sHttpClient
See theLlm4sHttpClient companion object
@Stable
trait Llm4sHttpClient extends AutoCloseable

The HTTP client provider modules and built-in tools use, abstracted so it can be injected and replaced by a test double.

Every request method returns a Result and never throws for a transport failure:

A non-2xx status is '''not''' an error at this layer: it is a Right response, which the caller inspects (HttpResponse.ensureSuccess, or org.llm4s.llmconnect.provider.HttpErrorMapper.mapHttpError with the response headers).

Headers are passed as single-valued maps. Response headers are multi-valued, keyed in lower case; look one up with header(name).

The trait is deliberately not sealed, so tests can implement it. Methods added to it after 1.0 will have default implementations, so a test double keeps compiling.

Attributes

Companion
object
Graph
Supertypes
trait AutoCloseable
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def delete(url: String, headers: Map[String, String], timeout: FiniteDuration): Result[HttpResponse]
def get(url: String, headers: Map[String, String], params: Map[String, String], timeout: FiniteDuration): Result[HttpResponse]
def post(url: String, headers: Map[String, String], body: String, timeout: FiniteDuration): Result[HttpResponse]
def postBytes(url: String, headers: Map[String, String], data: Array[Byte], timeout: FiniteDuration): Result[HttpResponse]
def postMultipart(url: String, headers: Map[String, String], parts: Seq[MultipartPart], timeout: FiniteDuration): Result[HttpResponse]
def postRaw(url: String, headers: Map[String, String], body: String, timeout: FiniteDuration): Result[HttpRawResponse]

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.

Attributes

def postStream(url: String, headers: Map[String, String], body: String, timeout: FiniteDuration): Result[StreamingHttpResponse]

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.

Attributes

def put(url: String, headers: Map[String, String], body: String, timeout: FiniteDuration): Result[HttpResponse]

Concrete methods

override def close(): Unit

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.

Attributes

Definition Classes
AutoCloseable