SttpLlm4sHttpClient

org.llm4s.sttp.SttpLlm4sHttpClient
@Experimental
final class SttpLlm4sHttpClient(backend: SyncBackend) extends Llm4sHttpClient

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

Attributes

Source
SttpLlm4sHttpClient.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def delete(url: String, headers: Map[String, String], timeout: FiniteDuration): Result[HttpResponse]

Attributes

Definition Classes
Source
SttpLlm4sHttpClient.scala
override def get(url: String, headers: Map[String, String], params: Map[String, String], timeout: FiniteDuration): Result[HttpResponse]

Attributes

Definition Classes
Source
SttpLlm4sHttpClient.scala
override def post(url: String, headers: Map[String, String], body: String, timeout: FiniteDuration): Result[HttpResponse]

Attributes

Definition Classes
Source
SttpLlm4sHttpClient.scala
override def postBytes(url: String, headers: Map[String, String], data: Array[Byte], timeout: FiniteDuration): Result[HttpResponse]

Attributes

Definition Classes
Source
SttpLlm4sHttpClient.scala
override def postMultipart(url: String, headers: Map[String, String], parts: Seq[MultipartPart], timeout: FiniteDuration): Result[HttpResponse]

Attributes

Definition Classes
Source
SttpLlm4sHttpClient.scala
override 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

Definition Classes
Source
SttpLlm4sHttpClient.scala
override 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

Definition Classes
Source
SttpLlm4sHttpClient.scala
override def put(url: String, headers: Map[String, String], body: String, timeout: FiniteDuration): Result[HttpResponse]

Attributes

Definition Classes
Source
SttpLlm4sHttpClient.scala

Inherited 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
Inherited from:
Llm4sHttpClient
Source
Llm4sHttpClient.scala