Chat Errors
chat/errors
Section titled “chat/errors”Classes
Section titled “Classes”ChatError
Section titled “ChatError”Defined in: chat/errors.ts:33
Unified error class for all chat SDK errors
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ChatError(
message,options):ChatError
Defined in: chat/errors.ts:39
Parameters
Section titled “Parameters”message
Section titled “message”string
options
Section titled “options”Returns
Section titled “Returns”Overrides
Section titled “Overrides”Properties
Section titled “Properties”
readonlycode:ErrorCode
Defined in: chat/errors.ts:34
Machine-readable error code. Prefer values from the ErrorCode enum.
Overrides
Section titled “Overrides”httpStatus?
Section titled “httpStatus?”
readonlyoptionalhttpStatus:number
Defined in: errors.ts:25
HTTP status code hint for error classification
Inherited from
Section titled “Inherited from”retryable
Section titled “retryable”
readonlyretryable:boolean
Defined in: chat/errors.ts:35
Whether this error is safe to retry
Overrides
Section titled “Overrides”retryAfter?
Section titled “retryAfter?”
readonlyoptionalretryAfter:number
Defined in: chat/errors.ts:36
timestamp
Section titled “timestamp”
readonlytimestamp:string
Defined in: chat/errors.ts:37
Methods
Section titled “Methods”
staticis(error):error is AgentSDKError
Defined in: errors.ts:36
Check if an error is an AgentSDKError (works across bundled copies)
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”error is AgentSDKError
Inherited from
Section titled “Inherited from”ExponentialBackoffStrategy
Section titled “ExponentialBackoffStrategy”Defined in: chat/errors.ts:253
Exponential backoff with optional jitter
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ExponentialBackoffStrategy(
options?):ExponentialBackoffStrategy
Defined in: chat/errors.ts:259
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Methods
Section titled “Methods”nextDelay()
Section titled “nextDelay()”nextDelay(
attempt,error):number|null
Defined in: chat/errors.ts:266
Return delay in ms for the given attempt (0-based), or null to stop
Parameters
Section titled “Parameters”attempt
Section titled “attempt”number
Returns
Section titled “Returns”number | null
Implementation of
Section titled “Implementation of”Interfaces
Section titled “Interfaces”ChatErrorOptions
Section titled “ChatErrorOptions”Defined in: chat/errors.ts:19
Options for constructing a ChatError
Properties
Section titled “Properties”cause?
Section titled “cause?”
optionalcause:unknown
Defined in: chat/errors.ts:27
Original cause, if wrapping another error
code:
ErrorCode
Defined in: chat/errors.ts:21
Machine-readable error code
retryable?
Section titled “retryable?”
optionalretryable:boolean
Defined in: chat/errors.ts:23
Whether this error is retryable (default: false)
retryAfter?
Section titled “retryAfter?”
optionalretryAfter:number
Defined in: chat/errors.ts:25
Retry delay hint in milliseconds
ExponentialBackoffOptions
Section titled “ExponentialBackoffOptions”Defined in: chat/errors.ts:241
Options for ExponentialBackoffStrategy
Properties
Section titled “Properties”baseMs?
Section titled “baseMs?”
optionalbaseMs:number
Defined in: chat/errors.ts:243
Base delay in ms (default: 1000)
jitter?
Section titled “jitter?”
optionaljitter:number
Defined in: chat/errors.ts:249
Jitter factor 0–1 (default: 0.1)
maxAttempts?
Section titled “maxAttempts?”
optionalmaxAttempts:number
Defined in: chat/errors.ts:247
Maximum number of attempts (default: 3)
maxMs?
Section titled “maxMs?”
optionalmaxMs:number
Defined in: chat/errors.ts:245
Maximum delay in ms (default: 30000)
RetryOptions
Section titled “RetryOptions”Defined in: chat/errors.ts:284
Options for withRetry execution
Properties
Section titled “Properties”onRetry()?
Section titled “onRetry()?”
optionalonRetry: (error,attempt,delayMs) =>void
Defined in: chat/errors.ts:288
Called before each retry with the error and delay
Parameters
Section titled “Parameters”attempt
Section titled “attempt”number
delayMs
Section titled “delayMs”number
Returns
Section titled “Returns”void
signal?
Section titled “signal?”
optionalsignal:AbortSignal
Defined in: chat/errors.ts:286
Abort signal to cancel retries
RetryStrategy
Section titled “RetryStrategy”Defined in: chat/errors.ts:235
Strategy for computing retry delays
Methods
Section titled “Methods”nextDelay()
Section titled “nextDelay()”nextDelay(
attempt,error):number|null
Defined in: chat/errors.ts:237
Return delay in ms for the given attempt (0-based), or null to stop
Parameters
Section titled “Parameters”attempt
Section titled “attempt”number
Returns
Section titled “Returns”number | null
Functions
Section titled “Functions”classifyError()
Section titled “classifyError()”classifyError(
error):ChatError
Defined in: chat/errors.ts:69
Classify an unknown thrown value into a ChatError with the appropriate code. Pattern-matches against common error shapes:
- Already a ChatError → returned as-is
- Fetch/network errors (ECONNREFUSED, ETIMEDOUT, etc.)
- HTTP status codes (401→AUTH_INVALID, 429→RATE_LIMIT, 5xx→PROVIDER_ERROR)
- Timeout patterns
- Zod validation errors
- Context overflow patterns
- Unknown → wrapped as ChatError with PROVIDER_ERROR
Parameters
Section titled “Parameters”unknown
The thrown value to classify
Returns
Section titled “Returns”ChatError with appropriate error code and retryable flag
isRetryable()
Section titled “isRetryable()”isRetryable(
error):boolean
Defined in: chat/errors.ts:337
Type guard: check if an error is retryable
Parameters
Section titled “Parameters”unknown
The error to check
Returns
Section titled “Returns”boolean
True if error is a retryable ChatError
withRetry()
Section titled “withRetry()”withRetry<
T>(fn,strategy,options?):Promise<T>
Defined in: chat/errors.ts:302
Execute an async function with automatic retries using the provided strategy. Respects ChatError.retryable and ChatError.retryAfter. Classifies non-ChatError errors before deciding on retry.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”() => Promise<T>
Async function to execute
strategy
Section titled “strategy”Retry strategy providing delay calculations
options?
Section titled “options?”Optional abort signal and retry callback
Returns
Section titled “Returns”Promise<T>
Result of fn on success
Throws
Section titled “Throws”ChatError when all retries exhausted or error is non-retryable
References
Section titled “References”ErrorCode
Section titled “ErrorCode”Re-exports ErrorCode