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) - Unsupported, excessive, or non-strict-capable strict tool schemas
(
ToolSchemaStrictnessError) - Tool
parametersor a structured outputschemathat cannot be converted to JSON Schema, including a Standard Schema without JSON Schema support - A request that breaks a tool discovery rule, such as an unanswered discovery call
- Invalid local request configuration
validateToolCall() checks them against a tool’s Standard Schema and reports
problems as issues instead of throwing. See
Validate tool calls.
ToolSchemaStrictnessError includes typed providerId, modelId,
toolNames, reason, and optional maxStrictTools, maxUnionParameters,
unionParameterCount, and violations fields. Its reason is one of
'unsupported', 'limit-exceeded', 'union-limit-exceeded', or
'invalid-schema'. Core-ai throws it before the provider request. See the
errors reference for the complete
shape.
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 → media / image count → 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)MediaCountExceededError— base class for media-count limits, thrown directly when images and document pages share one limit; optionalmaxMedia/actualMediawhen the provider reports them. Not retryable until images or documents are removed from the messages.ImageCountExceededError— subclass ofMediaCountExceededErrorfor a limit on images alone;maxMedia/actualMediacount images. Not retryable until images are removed from the messages. The counts are the provider’s own and can include inputs other than image parts, such as document pages. Check your messages for image parts before you ask a user to remove images.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
ImageCountExceededError first to ask for fewer images, then MediaCountExceededError for the general case. The errors cover the wordings each provider is known to return:
- OpenAI-based providers — the two Azure OpenAI wordings. Every OpenAI-based provider matches them, but other backends may word the limit differently.
- Anthropic and Anthropic Vertex —
MediaCountExceededErrorfor both media-limit wordings of the Anthropic API. Anthropic Vertex matches them, but Vertex may word the limit differently. - Gemini API and Vertex Gemini — the Gemini API wording. Vertex Gemini matches it, but Vertex may word the limit differently.
- Mistral — the Mistral API wording.
ProviderError, so keep a ProviderError branch as the fallback.
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 a Standard Schema. core-ai never validates output against plain JSON Schema, so it never raises this error for one.issues: Validation messages from the schema library, each formatted aspath.to.key: message(<root>for issues at the root)
- 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