Errors
Every typed error in @radonsdk/ai — the stable .code on each, what causes it, and the extra fields some carry (retryAfterSec, rawArguments, packageName, status).
Every failure Radon AI throws is a subclass of AIError with a stable
.code string. Branch on the class (instanceof) or the code — never on message
text, which can change.
import { RateLimitError, AuthenticationError, AIError } from "@radonsdk/ai";
try {
await ai.chat({ messages });
} catch (err) {
if (err instanceof RateLimitError) {
await sleep((err.retryAfterSec ?? 1) * 1000);
} else if (err instanceof AuthenticationError) {
// bad or missing API key
} else if (err instanceof AIError) {
console.error(err.code, err.message); // any other Radon error
}
}Base class
AIErrorcode: AIErrorCodeThe base of every error below. err.code is the stable machine-readable
string; err.message is human-readable. Catch this to handle any Radon AI
failure generically.
Every error
| Class | .code | Cause |
|---|---|---|
InvalidConfigError | invalid_config | Misconfiguration caught before any network call — empty providers, an unknown defaultProvider, or a missing embedding model. |
ProviderNotFoundError | provider_not_found | A slug was requested that isn't registered as a built-in or via registerProvider. |
ProviderNotConfiguredError | provider_not_configured | A provider was used that the app never added to its providers config. |
LicenseRequiredError | license_required | A Pro provider or Pro feature was used without a license. Set licenseKey and call await ai.init(). |
LicenseInvalidError | license_invalid | The license key could not be verified (invalid, revoked, or the verify endpoint was unreachable — fail-closed). |
UnsupportedOperationError | unsupported_operation | A provider was asked to do something it genuinely can't (e.g. embed() on a chat-only provider). Reflected in provider.capabilities. |
AuthenticationError | authentication_failed | The provider rejected the credentials (HTTP 401/403) — bad or expired API key. |
ProviderApiError | provider_error | The provider's API returned an error (bad request, model not found, 5xx). Carries status, providerCode, raw. |
RateLimitError | rate_limited | The provider signalled a rate limit (HTTP 429). Carries retryAfterSec when reported. |
ContextLengthExceededError | context_length_exceeded | The request exceeded the model's context window. |
NetworkError | network_error | A transport failure reaching the provider — DNS, timeout, TLS, connection reset. Carries cause. |
InvalidToolArgumentsError | invalid_tool_arguments | A model produced tool-call arguments that weren't valid JSON. Carries rawArguments. |
StreamError | stream_error | A streaming response broke mid-flight (malformed SSE, transport reset). Carries cause. |
NativeClientUnavailableError | native_client_unavailable | native() was called but the provider's official SDK isn't installed. Carries packageName. |
content_filtered
AIErrorCode also includes content_filtered. Safety-filtered generations are
normally surfaced as a finishReason of "content_filter" on a successful
ChatResult rather than thrown — inspect
res.finishReason.
Errors that carry extra fields
Some errors expose structured data beyond code and message.
ProviderApiError
providerstringThe provider slug the error came from.
statusnumber | undefinedThe HTTP status, when the failure came from an HTTP response.
providerCodestring | undefinedThe provider's own machine error code, if it returned one.
rawunknownThe raw provider response body (parsed JSON or text) — an escape hatch for debugging.
RateLimitError
providerstringThe provider that rate-limited you.
retryAfterSecnumber | undefinedSeconds until you may retry, from the provider's Retry-After header when
present.
if (err instanceof RateLimitError) {
await sleep((err.retryAfterSec ?? 5) * 1000);
}InvalidToolArgumentsError
providerstringThe provider whose model produced the bad arguments.
toolNamestringWhich tool the malformed call was for.
rawArgumentsstringThe raw string the model produced, for logging or an automated repair attempt.
NativeClientUnavailableError
providerstringThe provider whose native SDK is missing.
packageNamestringThe exact package to install — the message includes the npm install command.
Or fall back to rawClient(), which needs no
dependency.
UnsupportedOperationError
providerstringThe provider that can't do it.
operationstringThe operation attempted (e.g. "embed", "streamChat").
NetworkError and StreamError
Both carry provider and a cause (the underlying transport error). A
caller-initiated abort during a stream is surfaced verbatim (an AbortError), not
wrapped as a StreamError.
Fallback and errors
In a fallback chain, most errors advance to the next provider,
but LicenseRequiredError and InvalidConfigError re-throw immediately — trying
another provider can't fix a licensing or configuration problem.