TheoApiError
All REST API errors are thrown asTheoApiError instances with structured details.
Error Properties
| Property | Type | Description |
|---|---|---|
status | number | HTTP status code (0 for network/timeout/cancel) |
kind | string | "http" | "timeout" | "cancelled" | "network" — branch on this instead of string-matching |
message | string | Human-readable error message |
body | string | Raw response body |
url | string | Request URL |
details | object | null | Parsed { message, type, code, request_id } |
Error Types
TheoApiError is the base class — every error below is instanceof TheoApiError, so existing catch blocks keep working. Branch on the subclass (or err.kind) for precise handling:
TheoTimeoutError(kind: "timeout") — the SDK aborted aftertimeoutMs(unary / stream connect) orstreamIdleTimeoutMs(stream idle). Carries the offending budget in.timeoutMs. Not auto-retried on POSTs.TheoCancelledError(kind: "cancelled") — you aborted viaTheoStream.cancel()or anAbortSignalpassed towaitForJob().TheoUsageError(extendsError, notTheoApiError) — thrown synchronously for misuse before any network call, e.g. passingmode: "research" | "video"tocomplete()/stream()(use the async job methods instead).
Stream Errors
The SSEerror event carries the same envelope as the REST error body — reuse one code path for both.
0.1.x, where stream errors were { message } only. See the Streaming Completions reference for the full envelope schema.
First-Run Diagnostic
Instead of surfacing raw errors,theo.verify() returns a structured diagnosis with a remediation hint:
Automatic Retries
The SDK retries automatically on:- 429 — Rate limited (respects
Retry-Afterheader up to 60s) - 5xx — Server errors (exponential backoff: 1s, 2s, 4s, max 8s)
Client errors (400, 401, 403, 404) are not retried. Timeouts are not retried on non-idempotent POSTs (
complete,research,video) — re-issuing could double-run and double-bill the request; pair your own retry with anIdempotency-Keyif you need one. See Timeouts & Retries for the full model, including the stream idle timeout. Configure:
Cancellation
TheoStream.cancel() aborts an in-flight stream without throwing. The underlying fetch is aborted via AbortController; subsequent events stop arriving and the iterator ends cleanly.
