LlmException

org.llm4s.javaapi.LlmException
See theLlmException companion object
final class LlmException(val error: LLMError) extends RuntimeException

A checked-free runtime exception wrapping an LLMError, thrown only when Java callers dereference a failed LlmResult via LlmResult#get.

If the wrapped error carries an underlying Throwable (for example a cause: Option[Throwable] field), it is exposed through getCause.

The failure can be read without Scala types: getKind is a Java enum to switch on, isRecoverable says whether trying again may help, and getRetryAfter and getStatusCode report what the provider said.

LlmException e = result.getError();
switch (e.getKind()) {
   case RATE_LIMIT -> wait(e.getRetryAfter().orElse(Duration.ofSeconds(30)));
   case AUTHENTICATION, CONFIGURATION -> alertOperator(e.getMessage());
   default -> { if (e.isRecoverable()) retry(); else report(e); }
}

Attributes

Companion
object
Source
LlmException.scala
Graph
Supertypes
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def getKind: LlmErrorKind

What kind of failure this is; LlmErrorKind.OTHER for an error the library does not know.

What kind of failure this is; LlmErrorKind.OTHER for an error the library does not know.

Attributes

Source
LlmException.scala

How long the provider asked the caller to wait before trying again - its Retry-After header - or empty when it did not say. Only a rate limit (RATE_LIMIT) or a provider's error response (SERVICE) carries one.

How long the provider asked the caller to wait before trying again - its Retry-After header - or empty when it did not say. Only a rate limit (RATE_LIMIT) or a provider's error response (SERVICE) carries one.

Attributes

Source
LlmException.scala

The HTTP status of the provider's error response, or empty when the error carries none. Present for a provider's error response that kept its status (a ServiceError, an APIError that has one, or an embedding provider's EmbeddingError whose code is a status), whose kind is SERVICE - or, for 400, 401, 403 and 429, the kind that status means (see getKind).

The HTTP status of the provider's error response, or empty when the error carries none. Present for a provider's error response that kept its status (a ServiceError, an APIError that has one, or an embedding provider's EmbeddingError whose code is a status), whose kind is SERVICE - or, for 400, 401, 403 and 429, the kind that status means (see getKind).

Attributes

Source
LlmException.scala

Whether the call may succeed if tried again, perhaps after the caller does something first (waits, re-reads, corrects the request): core's LLMError.isRecoverable, which is true exactly for a RecoverableError. It is wider than what is worth retrying unchanged: a provider's answer with a client-error status, such as 400, is recoverable but needs a corrected request.

Whether the call may succeed if tried again, perhaps after the caller does something first (waits, re-reads, corrects the request): core's LLMError.isRecoverable, which is true exactly for a RecoverableError. It is wider than what is worth retrying unchanged: a provider's answer with a client-error status, such as 400, is recoverable but needs a corrected request.

Attributes

Source
LlmException.scala

Inherited methods

Attributes

Inherited from:
Throwable

Attributes

Inherited from:
Throwable

Attributes

Inherited from:
Throwable

Attributes

Inherited from:
Throwable

Attributes

Inherited from:
Throwable

Attributes

Inherited from:
Throwable
final def getSuppressed(): Array[Throwable]

Attributes

Inherited from:
Throwable

Attributes

Inherited from:
Throwable

Attributes

Inherited from:
Throwable

Attributes

Inherited from:
Throwable

Attributes

Inherited from:
Throwable

Attributes

Inherited from:
Throwable
def toString(): String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Inherited from:
Throwable

Concrete fields

Attributes

Source
LlmException.scala