Provider error normalization. Classifies provider/LLM API errors into a common shape (e.g. context_overflow vs api_error), extracts human-readable messages from heterogeneous response bodies, and detects context-window overflow across many providers via message-pattern matching.
Methods
(static) parseAPICallError(input) → {Object}
Normalize a non-streaming API call error into a common shape, classifying it as "context_overflow" (via isOverflow, a 413, or an explicit context_length_exceeded code) or otherwise "api_error" with status/retry info.
| Name | Type | Description |
|---|---|---|
input | Object |
|
A normalized error descriptor.
- Type:
- Object
(static) parseStreamError(input) → {Object}
Parse an error object delivered inside a streaming response into a normalized error, mapping known error codes (context_length_exceeded, insufficient_quota, usage_not_included, invalid_prompt, server_error) to their type and retryability.
| Name | Type | Description |
|---|---|---|
input | * | The raw stream error payload (object or JSON string). |
A normalized error {type, message, ...}, or undefined when not an error.
- Type:
- Object
(inner) isOpenAiErrorRetryable(e) → {boolean}
Decide whether an OpenAI-style API error should be retried, treating 404 as retryable because OpenAI sometimes 404s models that are actually available.
| Name | Type | Description |
|---|---|---|
e | Object | The provider error ( |
True when the request should be retried.
- Type:
- boolean
(inner) isOverflow(message) → {boolean}
Detect whether an error message indicates a context-window overflow, matching the provider-specific OVERFLOW_PATTERNS plus bare 400/413 "(no body)" responses from providers like Cerebras and Mistral.
| Name | Type | Description |
|---|---|---|
message | string | The error message text to test. |
True when the message looks like a context overflow.
- Type:
- boolean
(inner) json(input) → {Object}
Coerce a value to a plain object: parse a JSON string, pass through objects, and return undefined for anything that is not (or does not parse to) an object.
| Name | Type | Description |
|---|---|---|
input | * | A JSON string or value to coerce. |
The parsed object, or undefined.
- Type:
- Object
(inner) message(providerID, e) → {string}
Build the best human-readable message for a provider error, falling back from the error message to the response body, JSON error fields, or the HTTP status text, and rewriting HTML gateway/proxy 401/403 pages into actionable guidance.
| Name | Type | Description |
|---|---|---|
providerID | string | The provider id (reserved for provider-specific handling). |
e | Object | The provider error ( |
A trimmed, human-readable error message.
- Type:
- string