Skip to main content
The SDK throws typed errors so you can catch and react to specific failure modes. Every error is a subclass of Error. Transient failures retry automatically; payment and session failures need your attention.

Error types

Try/catch pattern

Every Error has a code string and a message. The code is stable — branch on it, not the message text.

Retry behavior

The SDK retries transient errors (NetworkError, ServerError, RateLimitError) automatically with exponential backoff. Configure the policy at init time:
The default is 2 retries. Payment and session errors are never retried — they require action on your side.

Payment failures

PaymentError covers anything that goes wrong during x402 negotiation. Common codes:

Session failures

SessionError fires when your Compose Key can no longer be used. Listen for the sessionInvalid event to catch this proactively:

Stream errors

If the SSE stream fails mid-response, you get an error event in the loop, and the iterator throws a StreamError when it ends. Partial text already received is still valid — decide whether to show it or discard based on your UX.

Next