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:
an interrupted request, or a stream read interrupted mid-body, is a Left(org.llm4s.error.CancelledError), with the thread's interrupt flag kept.
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.
gives up after request.responseTimeout without the response's status line and headers;
makes a read of the body that waits longer than request.idleTimeout fail with a java.net.SocketTimeoutException (org.llm4s.http.StreamingHttpResponse.withIdleTimeout does this for a transport with no read timeout of its own);
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.
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.
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.
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.
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.