Llm4sHttpClient

org.llm4s.http.Llm4sHttpClient
See theLlm4sHttpClient companion object
@Stable

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

send is the one method an implementation writes. Everything else is a final convenience built on it: sendText and sendRaw read the whole body, and get, post, postBytes, postMultipart, put, delete, postRaw and postStream build the HttpRequest for the common calls. A request they do not cover - a PATCH, a HEAD, a GET of bytes or of a stream - is an HttpRequest passed to one of the three.

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.toError with the response headers).

'''Timeouts.''' The timeout of a convenience method is both of HttpRequest's: the longest wait for the response's status line and headers, and separately the longest any read of the body waits for more bytes. It is not a deadline for the whole call. Pass an HttpRequest to set the two apart.

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: a test double implements send alone.

Attributes

Companion
object
Source
Llm4sHttpClient.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

Sends request and returns the response with its body still open.

Sends request and returns the response with its body still open.

An implementation:

The caller closes the body, on a non-2xx status too. A failure while reading it surfaces as an IOException from the stream itself, not through the returned Result.

Attributes

Source
Llm4sHttpClient.scala

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
Source
Llm4sHttpClient.scala
final def delete(url: String, headers: Map[String, String], timeout: FiniteDuration): Result[HttpResponse]

DELETE url.

DELETE url.

Attributes

Source
Llm4sHttpClient.scala
final def get(url: String, headers: Map[String, String], params: Map[String, String], timeout: FiniteDuration): Result[HttpResponse]

GET url with params appended as its query.

GET url with params appended as its query.

Attributes

Source
Llm4sHttpClient.scala
final def post(url: String, headers: Map[String, String], body: String, timeout: FiniteDuration): Result[HttpResponse]

POST a text body.

POST a text body.

Attributes

Source
Llm4sHttpClient.scala
final def postBytes(url: String, headers: Map[String, String], data: Array[Byte], timeout: FiniteDuration): Result[HttpResponse]

POST a body of bytes.

POST a body of bytes.

Attributes

Source
Llm4sHttpClient.scala
final def postMultipart(url: String, headers: Map[String, String], parts: Seq[MultipartPart], timeout: FiniteDuration): Result[HttpResponse]

POST parts as multipart/form-data.

POST parts as multipart/form-data.

Attributes

Source
Llm4sHttpClient.scala
final 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

Source
Llm4sHttpClient.scala
final 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.

The default timeout is 10 minutes, because a model may pause that long between events: it bounds the wait for the response head and each wait for the next bytes, never the length of the stream.

Attributes

Source
Llm4sHttpClient.scala
final def put(url: String, headers: Map[String, String], body: String, timeout: FiniteDuration): Result[HttpResponse]

PUT a text body.

PUT a text body.

Attributes

Source
Llm4sHttpClient.scala
final def sendRaw(request: HttpRequest): Result[HttpRawResponse]

send, then the whole body as bytes; a failure while reading it is a Left. The body is closed.

send, then the whole body as bytes; a failure while reading it is a Left. The body is closed.

Attributes

Source
Llm4sHttpClient.scala
final def sendText(request: HttpRequest): Result[HttpResponse]

send, then the whole body as text in the charset its Content-Type names, UTF-8 when it names none; a failure while reading it is a Left. The body is closed.

send, then the whole body as text in the charset its Content-Type names, UTF-8 when it names none; a failure while reading it is a Left. The body is closed.

Attributes

Source
Llm4sHttpClient.scala