Overview
core-ai provides a hierarchy of error classes for handling different types of failures when working with language models. All errors extend fromCoreAIError and provide structured error information.
Error Hierarchy
CoreAIError
Base error class for all core-ai errors.ValidationError
Thrown when core-ai rejects invalid caller input or local request configuration before calling a provider.Properties
string
Error message describing what went wrong.
unknown
Optional underlying cause of the error (e.g., network error, API error).
string | undefined
Optional provider context when the error can be attributed to a provider.
string
Error name, always
'ValidationError'.Example
UnsupportedInputModalityError
Thrown when user messages include content parts the model does not accept, before the provider call. ExtendsValidationError.
Properties
readonly string[]
Modalities present in the user messages.
readonly string[]
Modalities from
model.capabilities.modalities.input.readonly string[]
Requested modalities missing from the model capabilities.
Example
AbortedError
Thrown when an operation is cancelled via anAbortSignal.
StreamAbortedError
Thrown when a streaming operation is aborted via anAbortSignal.
Example
ProviderError
Error for provider/API failures. Discriminate with subclasses andinstanceof. Transient failures extend RetryableProviderError.
Properties
string
The provider that threw the error (e.g.,
'openai', 'anthropic').number | undefined
HTTP status code if available (e.g.,
404, 500, 429).Classified subclasses
Each provider
wrap*Error helper decides which subclass to throw from SDK-specific fields (error types, status codes, message shapes). Use instanceof to branch in application code — statusCode is for logging and debugging, not for retry decisions.
HTTP 429 is not always RateLimitError: billing quota (for example OpenAI insufficient_quota) remains a non-retryable ProviderError, while some capacity signals (for example Azure NoCapacity) map to ModelOverloadedError. RateLimitError.retryAfterSeconds may come from Retry-After, Azure retry-after-ms, or an HTTP-date Retry-After header.
Example
StructuredOutputError
Base class for errors related to structured output generation (objects).Properties
string | undefined
The raw output from the model that failed to parse/validate.
Example
StructuredOutputNoObjectGeneratedError
Thrown when the model doesn’t generate an object at all.Example
StructuredOutputParseError
Thrown when the model’s output cannot be parsed as JSON.Example
StructuredOutputValidationError
Thrown when the model’s output doesn’t match the Zod schema.Properties
string[]
Array of validation error messages from Zod.
Example
Error Handling Patterns
Comprehensive Error Handling
Retry Logic with Error Handling
Logging and Monitoring
Graceful Degradation
Best Practices
The
rawOutput property in structured output errors is useful for debugging
what the model actually generated.