⇠ chan.dev / posts

How I Use AssemblyAI's APIs for chantastic.fm

AI-assisted post: written from the transcription pipeline behind chantastic.fm.

I don’t edit podcast transcripts.

I call AssemblyAI, let code check what comes back, and when something is wrong I change the inputs and run it again.

chantastic.fm is the show that used to be React Podcast. The pipeline lives in chantastic/podcast. This is how the APIs are wired, with the request shapes we actually send.

We use three AssemblyAI endpoints:

  1. POST https://api.assemblyai.com/v2/transcript to transcribe and diarize
  2. POST https://llm-gateway.assemblyai.com/v1/understanding for a Speaker Identification follow-up, when we didn’t ask on the original job
  3. POST https://llm-gateway.assemblyai.com/v1/chat/completions for everything we ask a model: corrections, then chapters, topics, and a summary

We do not use AssemblyAI’s built-in summarization or auto-chapters. Those last two jobs go through the LLM Gateway with our own schemas, and code decides what is kept.

Transcribe and diarize

Each episode is submitted to the pre-recorded transcription API with model assemblyai-stt-3-7, speaker labels, punctuation, and formatting on. The request is built in src/transcription/assemblyai.js:

export const API = 'https://api.assemblyai.com/v2';
export function requestBody({
audioUrl, model, keyterms = [], prompt,
speakerLabels = true, webhook, speechUnderstanding
}) {
const body = {
audio_url: audioUrl,
speech_models: [model],
speaker_labels: !!speakerLabels,
punctuate: true,
format_text: true
};
if (keyterms.length) body.keyterms_prompt = keyterms;
if (prompt) body.prompt = prompt;
if (speechUnderstanding) body.speech_understanding = speechUnderstanding;
if (webhook?.url) {
body.webhook_url = webhook.url;
if (webhook.headerName && webhook.headerValue) {
body.webhook_auth_header_name = webhook.headerName;
body.webhook_auth_header_value = webhook.headerValue;
}
}
return body;
}

In practice we do not send a free-text prompt. The useful hint is keyterms_prompt: a lean list of proper nouns for that episode.

A finished request looks like this (trimmed, no secrets):

// POST https://api.assemblyai.com/v2/transcript
{
audio_url: "https://media.example.com/show/audio/123.mp3",
speech_models: ["assemblyai-stt-3-7"],
speaker_labels: true,
punctuate: true,
format_text: true,
keyterms_prompt: ["chantastic", "Dan Abramov", "Redux"]
// speech_understanding and webhook_url are added when they apply
}

If a name comes out wrong, I don’t patch the transcript. I add the name to the seeds or the notes and transcribe again.

Key terms

keyterms_prompt is built only from data we already have (src/transcription/seeds.js). The sources, in order, are:

  • hosts and guests, including spoken aliases and former names
  • people, products, libraries, and companies in the visible show-note link text (never the href)
  • sponsor names
  • a show-wide glossary
  • per-episode seed fixes

Proper nouns only. No dictionary words, no URLs, and nothing taken from the title or description. AssemblyAI’s limit is 1,000 terms, each at most six words; we log the count and flag an episode that goes over.

Speaker Identification

speaker_labels gives us lettered speakers (A, B, C). Naming those letters is a separate step.

A single host and a single guest skip Speaker Identification. We request it only for a group episode: more than one credited guest, a panel, or three or more credited people.

When we do, it goes on the original transcription request as speech_understanding, with effort always low:

export function speakerIdentificationRequest(people, { effort = 'low' } = {}) {
return {
speaker_type: 'name',
speakers: speakerIdCandidates(people),
effort: effort === 'medium' ? 'low' : (effort || 'low'),
};
}

speakerIdCandidates sends each credited person as { name, description }, for example "Host of the show" or "Guest on this episode".

The attached request looks like this:

speech_understanding: {
request: {
speaker_identification: {
speaker_type: "name",
speakers: [
{ name: "chantastic", description: "Host of the show" },
{ name: "Guest One", description: "Guest on this episode" },
{ name: "Guest Two", description: "Guest on this episode" }
],
effort: "low"
}
}
}

If that did not run, and the finished transcript has three or more voices (each with at least 30 seconds of talk) and the host never introduced themselves, we send a follow-up. That call does not re-transcribe. It posts the existing transcript_id to the Speech Understanding API:

// POST https://llm-gateway.assemblyai.com/v1/understanding
{
transcript_id: "transcript_id",
speech_understanding: {
request: {
speaker_identification: { /* same shape as above */ }
}
}
}

A name from Speaker Identification is used only if that person is credited on the episode. If it disagrees with the word-based naming, Identification wins, but still only for a credited person. Anything uncertain stays Speaker X.

Webhooks, then a fingerprint so we don’t pay twice

If a webhook is configured, the transcription request also includes:

{
webhook_url: "https://chantastic.fm/_hooks/assemblyai",
webhook_auth_header_name: "x-webhook-secret",
webhook_auth_header_value: "…"
}

AssemblyAI POSTs { transcript_id, status } to that URL when the job finishes, and we complete the sync. The hook checks the shared secret in the x-webhook-secret header with a constant-time compare. If the secret is not set, that route is a 404 and nothing extra is billed; we poll GET /v2/transcript/:id instead.

We also refuse to submit the same job twice. Stage A is cached by a SHA-256 fingerprint of the provider, the audio object (its key, etag, and size), and the request params, which include the seeds and the model:

const fp = await fingerprint({
provider: config.provider,
audio: {
key: input.episode.audioKey,
etag: String(head.etag || '').replace(/"/g, ''),
size: head.size ?? null
},
params
});

If a completed or in-flight version already has that fingerprint, the episode is skipped. Unchanged audio and unchanged inputs are not sent again.

Correct the transcript through the LLM Gateway

Stage B is not “the model rewrites the transcript.” The model proposes edits. Code accepts or rejects each one. Timestamps and speaker labels are off limits.

The call goes to AssemblyAI’s LLM Gateway, on the same key and balance as transcription. The show’s correction model is claude-opus-5-5. About 10 cents per episode with Opus.

// POST https://llm-gateway.assemblyai.com/v1/chat/completions
const body = {
model, // "claude-opus-5-5"
messages,
max_tokens: maxTokens || c.maxOutputTokens || 16000,
response_format: {
type: "json_schema",
json_schema: { name: "transcript_edits", strict: true, schema }
}
};
if (m.region) body.model_region = m.region;

For this show, max_tokens is 10,000 and model_region is "global". The transcript is sent in 15-minute chunks, with the previous chunk’s last three segments as read-only context.

The model must return JSON in this schema:

export const OUTPUT_SCHEMA = {
type: "object",
additionalProperties: false,
required: ["edits", "listen"],
properties: {
edits: {
type: "array",
items: {
type: "object",
additionalProperties: false,
required: ["segment", "old", "new", "source", "reason", "confidence"],
properties: {
segment: { type: "integer" },
old: { type: "string" },
new: { type: "string" },
source: {
type: "string",
enum: ["seed", "notes", "model-knowledge"]
},
reason: { type: "string" },
confidence: { type: "number" }
}
}
},
listen: {
type: "array",
items: {
type: "object",
additionalProperties: false,
required: ["segment", "words", "note"],
properties: {
segment: { type: "integer" },
words: { type: "string" },
note: { type: "string" }
}
}
}
}
};

old has to be copied from the segment. source is "seed" or "notes" when the new words are in those lists, and "model-knowledge" only when they are not. If the model is unsure, it should not edit: it adds a listen note instead.

Validate every edit in code

validateEdit in src/transcription/correct.js is the gate. A rejected edit is recorded with a reason and never applied. The rules that matter in practice:

  • old must match the current segment exactly once. Surrounding punctuation can differ; the transcript keeps its own.
  • The edit cannot change punctuation, except writing out an initial (M. → Michel).
  • A no-op (old equals new) is refused.
  • Word-count changes are capped: at most 12 words out, 6 words in, and a net growth of 2. Joining a split name is allowed (React XP → ReactXP) and needs no extra evidence. Ordinary joins (on to → onto) are refused.
  • A "seed" or "notes" edit has to be backed by those lists, or by one credited person’s name.
  • "model-knowledge" needs confidence of at least 0.9. Below that, code may still allow it through a lane: dictionary terms at 0.6 if they sound like the original, a sounds-alike lane at 0.75, or evidence from seeds, notes, or a person credited on this episode.

The model’s answer is stored with the question. If I only change a validation rule, the stored answer is judged again and there is no new API call.

Summarize, chapters, and topics

Stage D is one more Gateway call per episode, after the transcript has been corrected. The model never writes a timestamp. It points at a numbered line of the transcript, and code reads the time off that line, so a chapter can only start where something was said.

The lines are caption sentences joined into one-speaker spans of at most 30 seconds. The call reuses callGateway with a different schema name:

await callGateway(io, config, model, plan.messages, {
name: "episode_chapters",
schema: CHAPTER_SCHEMA,
maxTokens: plan.settings.maxOutputTokens // 2000
});
export const CHAPTER_SCHEMA = {
type: "object",
additionalProperties: false,
required: ["chapters", "topics", "summary"],
properties: {
summary: { type: "string" },
chapters: {
type: "array",
items: {
type: "object",
additionalProperties: false,
required: ["line", "title"],
properties: {
line: { type: "integer" },
title: { type: "string" }
}
}
},
topics: {
type: "array",
items: {
type: "object",
additionalProperties: false,
required: ["name", "kind"],
properties: {
name: { type: "string" },
kind: {
type: "string",
enum: ["person", "technology", "organization", "work", "concept"]
}
}
}
}
}
};

judgeAnswer keeps only what passes. Anything else is listed with a reason and never repaired:

  • Chapters must point at a real line, run in time order, start at least 120 seconds apart, use a title of at most 60 characters, and not repeat a title. At most 20 are kept. If fewer than 3 usable chapters remain, we write none: players ignore fewer.
  • Players want the first chapter at zero. A first chapter that starts in the opening minute is moved there; otherwise we add an "Introduction" chapter.
  • Topics must be said in the episode, as whole words, any casing. At most 15, no duplicates, and only the kinds in the schema.
  • The summary must be 80 to 400 characters, one plain paragraph, with no markup or URLs. A mid-sentence capitalized word is treated as a name and must appear in the transcript or the episode title. Fail any of that and there is no summary.

As with corrections, the model’s answer is stored once per question. Changing a spacing or count rule re-judges the stored answer for nothing.

Render the files, then go live

Stage C always re-runs and costs no API call. It applies any pinned corrections, then writes the files other apps read from one list of sentence-level cues.

The episode page is speaker turns: one paragraph per turn, as Markdown and HTML. Caption files are sentence-level, because a three-minute monologue is useless as a single subtitle. From those cues, src/transcription/exporters.js writes three files that always agree:

  • .vtt — WebVTT with <v Speaker> tags, for Apple Podcasts and browsers
  • .srt — SubRip, as Speaker: text, for YouTube and video tools
  • .podcast.json — Podcasting 2.0 transcript JSON 1.0.0 (speaker, startTime, endTime in seconds, body), for <podcast:transcript type="application/json">

Stage D adds .chapters.json (Podcasting 2.0 chapters, for <podcast:chapters>) and a .chapters.txt of 00:00:00 Title lines for the description.

None of that is live until we promote it. promote copies the current live row aside, then switches the live transcript, captions, speakers, chapters, topics, and summary in one statement. unpromote writes that copy back, or removes the live row if there was none before. Neither call touches AssemblyAI. The same render twice is skipped.

That’s the pipeline: transcribe with the names we already have, name speakers only when they’re credited, let the model propose, let code decide, and ship open files. When something is wrong, I change the inputs and run it again.