any-llm-ts
API reference

Error classes

The normalized error hierarchy exported from any-llm-ts.

AnyLLMError

All normalized provider errors extend AnyLLMError, which itself extends the built-in Error.

PropertyTypeDescription
namestringConcrete error class name.
messagestringProvider or library error message.
causeunknownOriginal SDK error when one exists.
providerstring | undefinedNormalized provider name.
statusCodenumber | undefinedHTTP status inferred from the SDK error.
codestring | undefinedProvider error code.
errorTypestring | undefinedProvider error type.
paramstring | undefinedInvalid provider parameter, when supplied.

Provider failures

AuthenticationError;
ContentFilterError;
ContextLengthExceededError;
GatewayTimeoutError;
InsufficientFundsError;
InvalidRequestError;
ModelNotFoundError;
ProviderError;
ProviderFileNotFoundError;
RateLimitError;
UpstreamProviderError;

RateLimitError also exposes retryAfter?: string.

Library and configuration failures

MissingApiKeyError;
UnsupportedProviderError;
UnsupportedOperationError;
InvalidModelSyntaxError;
UnsupportedParameterError;
BatchNotCompleteError;
LengthFinishReasonError;
ContentFilterFinishReasonError;

These errors represent failures detected before or independently of a provider HTTP response.

Narrowing

try {
  await llm.completion(params);
} catch (error) {
  if (error instanceof RateLimitError) {
    scheduleRetry(error.retryAfter);
  } else if (error instanceof AnyLLMError) {
    reportProviderFailure(error);
  } else {
    throw error;
  }
}

See the error handling guide for a complete example.

On this page