Reference
Errors
SDK error classes, HTTP and WebSocket error mapping, retries, and cancellation.
All REST and WebSocket errors are normalized in one error module and extend ProsodyError.
ProsodyError
class ProsodyError extends Error {
statusCode: number;
responseBody?: unknown;
code?: string;
requestId?: string;
}| Status / WS code | Error class | Meaning |
|---|---|---|
401, 403, WS 4001/4003 | AuthenticationError | Missing, invalid, revoked, or unauthorized API key |
402, WS 4002 | InsufficientCreditsError | Workspace balance cannot cover the request (auto-reload triggers if enabled) |
413 | ProsodyError | Upload exceeds the maximum request size |
422 | ValidationError | Request or audio validation failed |
429 | RateLimitError | Request exceeded its rate limit |
5xx | ProsodyError | API or upstream failure |
InsufficientCreditsError
class InsufficientCreditsError extends ProsodyError {
statusCode: 402;
balanceCents?: number;
requiredCents?: number;
billingUrl?: string;
}Thrown by REST endpoints on HTTP 402 and by LiveSession / ProsodyRealtimeStream on WebSocket error frames (insufficient_credits / credits_required) or close code 4002.
ValidationError
class ValidationError extends ProsodyError {
details?: Record<string, string[]>;
}FastAPI validation arrays ({ detail: [{ loc, msg }] }) are parsed into a readable message and keyed by field path in details.
RateLimitError
class RateLimitError extends ProsodyError {
retryAfterMs: number;
}Transport errors
class TimeoutError extends ProsodyError {}
class ConnectionError extends ProsodyError {}Transport errors carry statusCode = 0.
Retries
The default policy retries status 408, 429, 500, 502, 503, and 504 twice with exponential backoff. 401, 402, 403, and 422 fail immediately without retrying.
const prosody = new ProsodyClient({
retry: {
maxRetries: 4,
initialDelayMs: 500,
maxDelayMs: 10_000,
backoffMultiplier: 2,
},
});Cancellation
Every request method accepts an AbortSignal as its final argument:
const controller = new AbortController();
const pending = prosody.transcribe('./call.wav', undefined, controller.signal);
controller.abort();
await pending;