Integration
Add ProsodyAI to your backend, handle errors, and work with speakers
import { ProsodyClient } from '@prosodyai/sdk';
const prosody = new ProsodyClient({
apiKey: process.env.PROSODY_API_KEY!,
});
const result = await prosody.transcribe('./call.wav');All requests go to https://api.prosodyai.app and authenticate with the
X-API-Key header. The SDK manages this for you. Keep API keys on the
server.
Server-side usage
The SDK is designed for server-side use. Create one ProsodyClient instance
and reuse it across requests.
import { ProsodyClient } from '@prosodyai/sdk';
const prosody = new ProsodyClient({
apiKey: process.env.PROSODY_API_KEY!,
});
const result = await prosody.transcribe('./call.wav');For a live call, open a realtime session and forward audio chunks from your media server:
const session = prosody.stream.session({
onUpdate: (current) => {
for (const turn of current.snapshot().turns) {
console.log(turn.speaker.label, turn.text);
}
},
});
await session.start();
// send PCM16 chunks as the call progresses
session.send(int16Array);
await session.stop();Error handling
The SDK throws typed errors. Catch them by class to respond appropriately.
import {
ProsodyError,
AuthenticationError,
RateLimitError,
ValidationError,
} from '@prosodyai/sdk';
try {
const result = await prosody.transcribe(file);
} catch (err) {
if (err instanceof AuthenticationError) {
// 401, 403: the key is missing, invalid, or lacks access
} else if (err instanceof RateLimitError) {
// 429: back off; err.retryAfterMs is set
} else if (err instanceof ValidationError) {
// 422: the request or the audio failed validation
} else if (err instanceof ProsodyError) {
// any other API error; err.statusCode is 402 when the balance is too low
}
}| Error | HTTP | When |
|---|---|---|
AuthenticationError | 401, 403 | Missing, invalid, or unauthorized key |
RateLimitError | 429 | Rate limit exceeded; retryAfterMs set |
ValidationError | 422 | Request or audio validation failed |
ProsodyError | 402 | Credit balance below the required charge |
ProsodyError | Any other status | Base class for all of the above |
See Errors for the full list.
Rate limits and credits
Recorded analysis and live sessions draw credits from your organization's prepaid balance, charged per audio-minute of processed audio. Check audio processed and spend in the dashboard under Usage.
When the balance is too low for the next charge, requests return 402 until
you top up. Rate limits are per-key and scale with your plan. See
Credits for rates.
Speaker identity
Within a recording or a live session, every turn carries a speaker with an
id and a label, taken from the waveform. A person your organization
enrolls, with their consent, carries a durable person_id, and resolves to
that same person_id on later recordings and live sessions. Enrollment and
retention are governed by the
Voice Authentication Policy.
prosody.speakers.list() calls GET /v1/voice/speakers and returns the
people stored for this organization. A display name is a label on that
person: set it when you confirm an enrollment, or from the workspace People
page.
Enrolled voice profiles stay inside the organization's namespace. The People page can rename an enrolled person or delete their profile.
const result = await prosody.transcribe('./call.wav');
for (const speaker of result.speakers) {
console.log(speaker.id, speaker.label, speaker.talkSeconds);
}
const { speakers: people } = await prosody.speakers.list();
for (const person of people) {
console.log(person.person_id, person.display_name);
}