org.llm4s.http

package org.llm4s.http

Members list

Type members

Classlikes

@Stable
sealed trait HttpBody

The body of an HttpRequest.

The body of an HttpRequest.

Attributes

Companion
object
Source
Llm4sHttpClient.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Bytes
object Empty
class Multipart
class Text
object HttpBody

Attributes

Companion
trait
Source
Llm4sHttpClient.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
HttpBody.type
@Stable
final case class HttpClientOptions

How Llm4sHttpClient.create builds the JDK-backed client.

How Llm4sHttpClient.create builds the JDK-backed client.

Build one with HttpClientOptions.apply and change it with the with* setters; the constructor and copy are private, so a new field never breaks callers.

Value parameters

connectTimeout

the limit on establishing each connection, separate from every request's own timeouts; None leaves connecting bounded by the request's responseTimeout alone

network

the proxy and TLS settings; HttpNetworkSettings.default keeps the JVM's default proxy selector and trust store

Attributes

Companion
object
Source
Llm4sHttpClient.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Source
Llm4sHttpClient.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
@Stable
object HttpHeaders

Case-insensitive lookup over a multi-valued header map, as carried by every response type in this package.

Case-insensitive lookup over a multi-valued header map, as carried by every response type in this package.

Attributes

Source
Llm4sHttpClient.scala
Supertypes
class Object
trait Matchable
class Any
Self type
@Stable
enum HttpMethod(val name: String)

The method of an HttpRequest.

The method of an HttpRequest.

Attributes

Source
Llm4sHttpClient.scala
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
@Stable
final case class HttpNetworkSettings

How llm4s's HTTP clients reach the network: an optional HttpProxy and the HttpTls material, read once from the llm4s.http block (Llm4sConfig.httpNetwork()) and honoured by every provider client - the JDK client in core, the openai-java and anthropic-java SDKs and the AWS SDK.

How llm4s's HTTP clients reach the network: an optional HttpProxy and the HttpTls material, read once from the llm4s.http block (Llm4sConfig.httpNetwork()) and honoured by every provider client - the JDK client in core, the openai-java and anthropic-java SDKs and the AWS SDK.

A named provider section can override it for one route with its own http block (llm4s.providers.<name>.http), whose keys take precedence over llm4s.http one by one.

HttpNetworkSettings.default - no proxy, no extra TLS material - leaves every client as it was before the setting existed: the JDK client keeps the JVM's default proxy selector.

Build one with HttpNetworkSettings.apply or HttpNetworkSettings.default and the with* setters; the constructor is private, so a new field never breaks a caller.

Value parameters

proxy

the proxy to route through, or None for a direct connection

tls

the extra trust and client-certificate material

Attributes

Companion
object
Source
HttpNetworkSettings.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Source
HttpNetworkSettings.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
@Stable
final case class HttpProxy

An outbound HTTP proxy every llm4s HTTP client routes through: the llm4s.http.proxy block.

An outbound HTTP proxy every llm4s HTTP client routes through: the llm4s.http.proxy block.

llm4s.http.proxy {
 url           = "http://proxy.corp:3128"
 username      = ${?LLM4S_PROXY_USER}
 password      = ${?LLM4S_PROXY_PASSWORD}
 nonProxyHosts = ["localhost", "*.internal"]
}

The proxy is an HTTP proxy: plain-http requests go to it in absolute form, https ones through a CONNECT tunnel. Proxy authentication is HTTP Basic; PAC files and Kerberos/NTLM are not supported.

nonProxyHosts lists the hosts reached directly. An entry is a host name or address matched exactly (localhost), a domain suffix (*.internal or .internal, which match internal itself too), a prefix (10.*), or * for every host; matching ignores case. A CIDR range is not supported. The default is the loopback addresses (HttpProxy.DefaultNonProxyHosts); setting the list replaces it.

The password is redacted in toString. Build one with HttpProxy.apply or HttpProxy.fromUrl and adjust it with the with* setters; the constructor is private, so a new field never breaks a caller.

Value parameters

host

the proxy's host name or address

nonProxyHosts

the hosts reached directly, not through the proxy

password

the password for proxy authentication; never printed

port

the proxy's port

username

the user name for proxy authentication, if the proxy requires it

Attributes

Companion
object
Source
HttpNetworkSettings.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object HttpProxy

Attributes

Companion
class
Source
HttpNetworkSettings.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
HttpProxy.type
@Stable
final case class HttpRawResponse

HTTP response wrapper for binary (non-text) response bodies.

HTTP response wrapper for binary (non-text) response bodies.

Use this instead of HttpResponse when the response body is binary data (e.g. image bytes) to avoid lossy charset decoding.

Value parameters

body

Raw response bytes — exact wire representation, no charset conversion

headers

Response headers as a multi-valued map (lowercase keys) Build one with HttpRawResponse.apply and change it with the with* setters; the constructor and copy are private, so a new field never breaks callers.

statusCode

HTTP status code

Attributes

Companion
object
Source
Llm4sHttpClient.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Source
Llm4sHttpClient.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
@Stable
final case class HttpRequest

One HTTP request, as Llm4sHttpClient.send takes it.

One HTTP request, as Llm4sHttpClient.send takes it.

The two timeouts bound different waits, and neither is a deadline for the whole exchange:

  • responseTimeout is the longest wait, from sending the request, for the response's status line and headers. It covers connecting too, unless the client was created with a shorter connect timeout.
  • idleTimeout is the longest a read of the response body waits for more bytes. It is not measured while the caller is busy between reads, so a slow consumer never trips it, and a stream that keeps delivering may run for any length of time.

Build one with HttpRequest.apply and change it with the with* setters; the constructor and copy are private, so a new field never breaks callers. toString leaves the headers and query out, since either may carry a credential.

Value parameters

body

the request body

headers

request headers, single-valued

idleTimeout

the longest a read of the response body waits for more bytes

method

the HTTP method

queryParams

query parameters, URL-encoded and appended to url by fullUrl

responseTimeout

the longest wait for the response's status line and headers

url

absolute http or https URL; queryParams are appended to it

Attributes

Companion
object
Source
Llm4sHttpClient.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object HttpRequest

Attributes

Companion
class
Source
Llm4sHttpClient.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
@Stable
final case class HttpResponse

HTTP response wrapper exposing status code, body, and headers.

HTTP response wrapper exposing status code, body, and headers.

Value parameters

body

Response body as a string

headers

Response headers as a multi-valued map (lowercase keys) Build one with HttpResponse.apply and change it with the with* setters; the constructor and copy are private, so a new field never breaks callers.

statusCode

HTTP status code (e.g. 200, 404)

Attributes

Companion
object
Source
Llm4sHttpClient.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object HttpResponse

Attributes

Companion
class
Source
Llm4sHttpClient.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
@Stable
final case class HttpTls

The TLS trust and client-certificate material every llm4s HTTP client uses: the llm4s.http.tls block.

The TLS trust and client-certificate material every llm4s HTTP client uses: the llm4s.http.tls block.

llm4s.http.tls {
 trustStore         = "/etc/pki/corp-ca.p12"
 trustStorePassword = ${?LLM4S_TRUSTSTORE_PASSWORD}
 keyStore           = "/etc/pki/client.p12"     # optional: a client certificate, for mTLS gateways
 keyStorePassword   = ${?LLM4S_KEYSTORE_PASSWORD}
}

The trust store's certificates are trusted '''in addition to''' the JDK's default ones, so a corporate CA that re-signs traffic is accepted without losing the public CAs. A store may be PKCS12 or JKS; the type is detected from the file. The passwords are redacted in toString.

Build one with HttpTls.default and the with* setters; the constructor is private, so a new field never breaks a caller.

Value parameters

keyStore

a store holding the client certificate and its key, for mutual TLS, if any

keyStorePassword

the key store's password, also used for the key; never printed

trustStore

a store of extra CA certificates to trust, if any

trustStorePassword

the trust store's password, if it has one; never printed

Attributes

Companion
object
Source
HttpNetworkSettings.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object HttpTls

Attributes

Companion
class
Source
HttpNetworkSettings.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
HttpTls.type
@Stable
final case class JsonHttpResponse

An HTTP response whose body has been parsed as JSON (see HttpResponse.toJson).

An HTTP response whose body has been parsed as JSON (see HttpResponse.toJson).

Value parameters

body

Response body parsed as JSON

headers

Response headers as a multi-valued map (lowercase keys) Build one with JsonHttpResponse.apply and change it with the with* setters; the constructor and copy are private, so a new field never breaks callers.

statusCode

HTTP status code

Attributes

Companion
object
Source
Llm4sHttpClient.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Source
Llm4sHttpClient.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
@Stable

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

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
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Source
Llm4sHttpClient.scala
Supertypes
class Object
trait Matchable
class Any
Self type
@Stable
sealed trait MultipartPart

Represents a single part in a multipart/form-data request.

Represents a single part in a multipart/form-data request.

Build one with MultipartPart.TextField(name, value), MultipartPart.FilePart(name, path, filename) or MultipartPart.FilePart.ofBytes, and change it with the with* setters; the constructors and copy are private, so a new field never breaks callers.

Attributes

Companion
object
Source
Llm4sHttpClient.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class FilePart
class TextField
object MultipartPart

Attributes

Companion
trait
Source
Llm4sHttpClient.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
@Stable
final case class StreamingHttpResponse

HTTP response wrapper for streaming (InputStream-based) response bodies.

HTTP response wrapper for streaming (InputStream-based) response bodies.

Use this instead of HttpResponse when the response body must be consumed incrementally (e.g. server-sent events, JSON lines).

Value parameters

body

Response body as an InputStream — caller is responsible for closing it, on error statuses too

headers

Response headers as a multi-valued map (lowercase keys) Build one with StreamingHttpResponse.apply and change it with the with* setters; the constructor and copy are private, so a new field never breaks callers.

statusCode

HTTP status code

Attributes

Companion
object
Source
Llm4sHttpClient.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Source
Llm4sHttpClient.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type