Integration
Client lifecycle, typed error handling, persistent speaker identity, and cross-session memory recall.
Reuse one client
Construct a single ProsodyClient per process and share it across requests. Pass an AbortSignal as the final argument to cancel individual operations or bound wait times:
import { ProsodyClient } from '@prosodyai/sdk';
export const prosody = new ProsodyClient({
timeoutMs: 120_000,
retry: { maxRetries: 2 },
});
const result = await prosody.transcribe(
'./call.wav',
undefined,
AbortSignal.timeout(60_000),
);Handle typed errors
All HTTP and WebSocket errors flow through one error module and extend ProsodyError. Handle the subclasses explicitly so your application responds cleanly to balance exhaustion, rate limits, and bad input:
import {
ProsodyError,
AuthenticationError,
InsufficientCreditsError,
RateLimitError,
ValidationError,
} from '@prosodyai/sdk';
try {
await prosody.transcribe(audio);
} catch (err) {
if (err instanceof InsufficientCreditsError) {
// HTTP 402 or WS 4002: workspace balance too low (auto-reload triggers if enabled)
logger.warn({ balanceCents: err.balanceCents, requiredCents: err.requiredCents });
} else if (err instanceof RateLimitError) {
// HTTP 429: retry after err.retryAfterMs
logger.warn({ retryAfterMs: err.retryAfterMs });
} else if (err instanceof ValidationError) {
// HTTP 422: inspect err.details for per-field errors
logger.error({ details: err.details });
} else if (err instanceof AuthenticationError) {
// HTTP 401 or 403, or WS 4001 / 4003
logger.error({ statusCode: err.statusCode });
} else if (err instanceof ProsodyError) {
logger.error({ statusCode: err.statusCode, requestId: err.requestId, message: err.message });
}
}Transient 408, 429, 500, 502, 503, 504, and network errors are retried automatically with exponential backoff up to retry.maxRetries. 402 (InsufficientCreditsError), 401/403, and 422 fail fast without retrying.
Speaker identity
Every voice discovered in a recording or live session is tracked by a recurrent speaker state. Enrolling or naming a speaker binds a display name to that speaker's person_id so subsequent recordings, live sessions, and voice agent rooms resolve the same person automatically.
// List enrolled speakers in your organization
const { speakers } = await prosody.speakers.list(50);
// Preview diarized lanes before persisting any identity
const preview = await prosody.speakers.previewEnrollment('./sample.wav');
// Confirm mappings once verified
await prosody.speakers.confirmEnrollment('./sample.wav', preview.preview_sha256, [
{ lane_id: preview.lanes[0].lane_id, display_name: 'Alex Rivera' },
]);
// Rename, inspect cross-session turns, or forget a speaker
await prosody.speakers.rename(personId, 'Alex Rivera');
const history = await prosody.speakers.transcript(personId, 200);
await prosody.speakers.delete(personId);Consent before enrolling voices
Obtain explicit speaker consent before enrolling a voice or attaching a personal name to a person_id. Without enrollment, voices remain anonymous session labels ("Speaker 1", "Speaker 2").
Cross-session memory recall
Retrieve a saved person's top-K committed moments across previous calls, recency-ranked with the measured acoustic facts that selected each moment:
const recalled = await prosody.memory.recall.post(personId, 10);