Overview
core-ai provides a hierarchy of error types that help you handle failures gracefully. For the complete API surface, see the errors reference.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 making a provider call.- Empty messages array
- Empty input for embeddings
- Empty prompt for image generation
- Unsupported input modalities in user messages (
UnsupportedInputModalityError) - Invalid local request configuration
AbortedError
Thrown when an operation is cancelled via anAbortSignal.
StreamAbortedError
Thrown when a streaming operation is aborted via anAbortSignal.
StreamAbortedError applies to an in-flight stream. Validation errors such
as empty messages throw ValidationError.ProviderError
Error for provider API failures (network errors, API errors, rate limits, etc.). Discriminate with subclasses andinstanceof. Transient failures (RateLimitError, ModelOverloadedError, ServiceUnavailableError) extend RetryableProviderError so you can retry with a single check.
Each provider
wrap*Error helper decides which subclass to throw from SDK-specific fields (error types, status codes, message shapes). Typical order inside a wrapper: abort → context length → provider specials (quota, Azure capacity) → overload → rate limit → service unavailable / transient 5xx → generic ProviderError.
HTTP 429 is not always RateLimitError. For example OpenAI insufficient_quota stays a non-retryable ProviderError, while Azure NoCapacity maps to ModelOverloadedError. Provider-specific quirks stay in the provider package (Azure "Backend error." as unavailable, Vertex RESOURCE_EXHAUSTED as a rate limit).
Usage:
ContextLengthExceededError— optionalmaxTokens/actualTokenswhen token counts are parseable (string-length limits are classified without inventing token metadata)RateLimitError— optionalretryAfterSecondsfromRetry-After, Azureretry-after-ms, or an HTTP-dateRetry-AftervalueModelOverloadedError— capacity / high-demand signal (wins over generic 5xx unavailable; AzureNoCapacityon 429 included)ServiceUnavailableError— temporary unavailability, including HTTP 500/502/503/504
Structured Output Errors
Errors specific to structured output generation (generateObject and streamObject).
StructuredOutputError
Base class for all structured output errors.rawOutput: The raw text output from the model (if available)provider: Which provider was usedstatusCode: HTTP status code (if applicable)cause: Underlying error that caused this error
StructuredOutputNoObjectGeneratedError
Thrown when the model doesn’t generate any structured output.- Model responds with regular text instead of structured output
- Tool call for structured output was not made
- Finish reason is not ‘stop’ or ‘tool-calls’
StructuredOutputParseError
Thrown when the model’s output cannot be parsed as JSON.- Model output is not valid JSON
- JSON syntax errors in model output
- Malformed structured output
StructuredOutputValidationError
Thrown when the model’s output doesn’t match the Zod schema.issues: Array of human-readable validation error messages
- Missing required fields
- Wrong data types
- Values that don’t match schema constraints
- Invalid enum values
Complete Error Handling Example
Retry Strategies
Exponential Backoff
Circuit Breaker
Validation Best Practices
Logging Errors
Next Steps
- Learn about Providers for provider-specific behavior
- Explore Configuration for controlling generation
- Understand Messages for building conversations