SDK: npm i assemblyai
Auth header format: Authorization: KEY (no Bearer prefix).
import { AssemblyAI } from "assemblyai";
const client = new AssemblyAI({ apiKey: process.env.ASSEMBLYAI_API_KEY! });
const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
});
console.log(transcript.text);const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
speaker_labels: true,
});
for (const utterance of transcript.utterances!) {
console.log(`Speaker ${utterance.speaker}: ${utterance.text}`);
}const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
speech_model: "nano",
// Falls back to "best" if nano is unavailable for the detected language
});import { AssemblyAI } from "assemblyai";
const client = new AssemblyAI({ apiKey: process.env.ASSEMBLYAI_API_KEY! });
try {
const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
});
if (transcript.status === "error") {
console.error("Transcription failed:", transcript.error);
return;
}
console.log(transcript.text);
} catch (err) {
console.error("API request failed:", err);
}const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
speaker_labels: true,
speakers_expected: 3, // optional hint
});
for (const utterance of transcript.utterances!) {
console.log(`Speaker ${utterance.speaker} [${utterance.start}-${utterance.end}]: ${utterance.text}`);
}import { AssemblyAI, PiiPolicy } from "assemblyai";
const client = new AssemblyAI({ apiKey: process.env.ASSEMBLYAI_API_KEY! });
const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
redact_pii: true,
redact_pii_policies: [
PiiPolicy.PersonName,
PiiPolicy.PhoneNumber,
PiiPolicy.EmailAddress,
PiiPolicy.CreditCardNumber,
],
redact_pii_sub: "hash", // "hash" or "entity_name"
});
console.log(transcript.text); // PII is redacted in the textNote: auto_chapters and summarization are mutually exclusive. You cannot enable both on the same transcription request.
const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
sentiment_analysis: true,
});
for (const result of transcript.sentiment_analysis_results!) {
console.log(`${result.text} — ${result.sentiment} (${result.confidence})`);
}const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
entity_detection: true,
});
for (const entity of transcript.entities!) {
console.log(`${entity.entity_type}: ${entity.text}`);
}const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
auto_chapters: true,
});
for (const chapter of transcript.chapters!) {
console.log(`[${chapter.start}-${chapter.end}] ${chapter.headline}`);
console.log(chapter.summary);
}const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
summarization: true,
summary_model: "informative", // "informative", "conversational", "catchy"
summary_type: "bullets", // "bullets", "bullets_verbose", "gist", "headline", "paragraph"
});
console.log(transcript.summary);const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
content_safety: true,
});
for (const result of transcript.content_safety_labels!.results!) {
for (const label of result.labels) {
console.log(`${label.label}: ${label.confidence}`);
}
}The prompt and keyterms_prompt parameters are mutually exclusive.
Provide free-form context to guide transcription accuracy.
const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
speech_model: "universal-3-pro",
prompt: "This is a medical consultation discussing cardiology topics including echocardiograms and EKGs.",
});Provide a list of key terms to boost recognition accuracy.
const transcript = await client.transcripts.transcribe({
audio: "https://example.com/audio.mp3",
speech_model: "universal-3-pro",
keyterms_prompt: ["echocardiogram", "EKG", "arrhythmia", "cardiomyopathy"],
});Uses RealtimeTranscriber with event-based handling.
import { AssemblyAI, RealtimeTranscriber } from "assemblyai";
const client = new AssemblyAI({ apiKey: process.env.ASSEMBLYAI_API_KEY! });
const transcriber = client.realtime.transcriber({
sampleRate: 16_000,
});
transcriber.on("open", ({ sessionId }) => {
console.log("Session opened:", sessionId);
});
transcriber.on("transcript.partial", (transcript) => {
if (transcript.text) {
process.stdout.write(`\rPartial: ${transcript.text}`);
}
});
transcriber.on("transcript.final", (transcript) => {
if (transcript.text) {
console.log("\nFinal:", transcript.text);
}
});
transcriber.on("error", (err) => {
console.error("Realtime error:", err);
});
transcriber.on("close", (code, reason) => {
console.log("Session closed:", code, reason);
});
await transcriber.connect();
// Send audio data (PCM16 chunks)
// transcriber.sendAudio(audioBuffer);
// When done:
// await transcriber.close();Uses client.streaming.transcriber with a turn-based event model.
import { AssemblyAI } from "assemblyai";
const client = new AssemblyAI({ apiKey: process.env.ASSEMBLYAI_API_KEY! });
const transcriber = client.streaming.transcriber({
sampleRate: 16_000,
});
transcriber.on("turn", (turn) => {
console.log(`Turn [${turn.start}-${turn.end}]: ${turn.transcript}`);
if (turn.end_of_turn) {
console.log("-- End of turn --");
}
});
await transcriber.connect();
// Send audio data (PCM16 chunks)
// transcriber.sendAudio(audioBuffer);
// When done:
// await transcriber.close();Use fetch to call the AssemblyAI LLM Gateway directly. Auth is Authorization: KEY (no Bearer).
const response = await fetch(
"https://llm-gateway.assemblyai.com/v1/chat/completions",
{
method: "POST",
headers: {
Authorization: process.env.ASSEMBLYAI_API_KEY!,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "claude-sonnet-4-5-20250929",
messages: [
{ role: "user", content: "Summarize this transcript..." },
],
}),
}
);
const data = await response.json();
console.log(data.choices[0].message.content);