To ask a question about your audio transcript, define a prompt with your questions, reference the transcript text with a {{ transcript }} tag, and pass the transcript ID alongside the prompt to the chat completions API.
Only the first occurrence of {{ transcript }} in the first message that contains it is substituted — additional tags or tags in later messages are left as-is. The tag must be exactly {{ transcript }} (with the spaces); variants like {{transcript}} or {{ TRANSCRIPT }} are not substituted. The endpoint returns 404 if the transcript ID does not exist or belongs to a different account.
Python
JavaScript
import requestsimport time# Step 1: Transcribe an audio file.base_url = "https://api.assemblyai.com"headers = { "authorization": "<YOUR_API_KEY>"}# You can use a local filepath:# with open("./my-audio.mp3", "rb") as f:# response = requests.post(base_url + "/v2/upload",# headers=headers,# data=f)# upload_url = response.json()["upload_url"]# Or use a publicly-accessible URL:upload_url = "https://assembly.ai/sports_injuries.mp3"data = { "audio_url": upload_url}response = requests.post(base_url + "/v2/transcript", headers=headers, json=data)transcript_id = response.json()["id"]polling_endpoint = base_url + f"/v2/transcript/{transcript_id}"while True: transcript = requests.get(polling_endpoint, headers=headers).json() if transcript["status"] == "completed": break elif transcript["status"] == "error": raise RuntimeError(f"Transcription failed: {transcript['error']}") else: time.sleep(3)# Step 2: Define a prompt with your question(s).prompt = "What is a runner's knee?"# Step 3: Send to LLM Gateway.llm_gateway_data = { "model": "claude-sonnet-4-5-20250929", "messages": [ {"role": "user", "content": f"{prompt}\n\n{{{{ transcript }}}}"} ], "transcript_id": transcript_id, "max_tokens": 1000}result = requests.post( "https://llm-gateway.assemblyai.com/v1/chat/completions", headers=headers, json=llm_gateway_data)print(result.json()["choices"][0]["message"]["content"])
// Step 1: Transcribe an audio file.const base_url = "https://api.assemblyai.com";const headers = {authorization: "<YOUR_API_KEY>",};// import fs from 'fs-extra';// const path = './my-audio.mp3';// const audioData = await fs.readFile(path)// const uploadRes = await fetch(`${base_url}/v2/upload`, {// method: "POST",// headers,// body: audioData,// });// if (!uploadRes.ok) throw new Error(`Error: ${uploadRes.status}`);// const uploadResponse = await uploadRes.json();// const uploadUrl = uploadResponse.upload_url// Or use a publicly-accessibly URL:const uploadUrl = "https://assembly.ai/sports_injuries.mp3";const data = {audio_url: uploadUrl,};let res = await fetch(base_url + "/v2/transcript", { method: "POST", headers: { ...headers, "Content-Type": "application/json" }, body: JSON.stringify(data),});if (!res.ok) throw new Error(`Error: ${res.status}`);const response = await res.json();const transcript_id = response.id;const polling_endpoint = base_url + `/v2/transcript/${transcript_id}`;let transcript;while (true) {res = await fetch(polling_endpoint, { headers });if (!res.ok) throw new Error(`Error: ${res.status}`);transcript = await res.json();if (transcript.status === "completed") {break;} else if (transcript.status === "error") {throw new Error(`Transcription failed: ${transcript.error}`);} else {await new Promise((resolve) => setTimeout(resolve, 3000));}}// Step 2: Define a prompt with your question(s).const prompt = "What is a runner's knee?";// Step 3: Send to LLM Gateway.const llm_gateway_data = {model: "claude-sonnet-4-6",messages: [{ role: "user", content: `${prompt}\n\n{{ transcript }}` }],transcript_id: transcript_id,max_tokens: 1000};res = await fetch("https://llm-gateway.assemblyai.com/v1/chat/completions", { method: "POST", headers: { ...headers, "Content-Type": "application/json" }, body: JSON.stringify(llm_gateway_data),});if (!res.ok) throw new Error(`Error: ${res.status}`);const result = await res.json();console.log(result.choices[0].message.content);
Based on the transcript, runner's knee is a condition characterizedby pain behind or around the kneecap. It is caused by overuse,muscle imbalance and inadequate stretching. Symptoms include painunder or around the kneecap and pain when walking.
You can achieve structured question-and-answer outputs by crafting specific prompts that guide the LLM to format responses in a consistent way. Here’s how to create structured Q&A responses using LLM Gateway:
Python
JavaScript
import requestsimport time# Step 1: Transcribe the audiobase_url = "https://api.assemblyai.com"headers = {"authorization": "<YOUR_API_KEY>"}audio_url = "https://assembly.ai/meeting.mp4"data = {"audio_url": audio_url}response = requests.post(base_url + "/v2/transcript", headers=headers, json=data)transcript_id = response.json()["id"]polling_endpoint = base_url + f"/v2/transcript/{transcript_id}"while True: transcript = requests.get(polling_endpoint, headers=headers).json() if transcript["status"] == "completed": break elif transcript["status"] == "error": raise RuntimeError(f"Transcription failed: {transcript['error']}") else: time.sleep(3)# Step 2: Create structured Q&A promptquestions = [ "What are the top level KPIs for engineering? (KPI stands for key performance indicator)", "How many days has it been since the data team has gotten updated metrics? (Choose from: 1, 2, 3, 4, 5, 6, 7, more than 7)"]prompt = f"""Answer the following questions based on the meeting transcript. Format your response as:Q1: [question]A1: [answer]Q2: [question]A2: [answer]Questions:{". ".join([f"{i+1}. {q}" for i, q in enumerate(questions)])}Context: This is a GitLab meeting to discuss logistics."""# Step 3: Send to LLM Gatewayllm_gateway_data = { "model": "claude-sonnet-4-5-20250929", "messages": [ {"role": "user", "content": f"{prompt}\n\n{{{{ transcript }}}}"} ], "transcript_id": transcript_id, "max_tokens": 1000}result = requests.post( "https://llm-gateway.assemblyai.com/v1/chat/completions", headers=headers, json=llm_gateway_data)print(result.json()["choices"][0]["message"]["content"])
// Step 1: Transcribe the audioconst base_url = "https://api.assemblyai.com";const headers = { authorization: "<YOUR_API_KEY>" };const audio_url = "https://assembly.ai/meeting.mp4";const data = { audio_url };let res = await fetch(base_url + "/v2/transcript", { method: "POST", headers: { ...headers, "Content-Type": "application/json" }, body: JSON.stringify(data),});if (!res.ok) throw new Error(`Error: ${res.status}`);const response = await res.json();const transcript_id = response.id;const polling_endpoint = base_url + `/v2/transcript/${transcript_id}`;let transcript;while (true) { res = await fetch(polling_endpoint, { headers }); if (!res.ok) throw new Error(`Error: ${res.status}`); transcript = await res.json(); if (transcript.status === "completed") break; if (transcript.status === "error") throw new Error(`Transcription failed: ${transcript.error}`); await new Promise((resolve) => setTimeout(resolve, 3000));}// Step 2: Create structured Q&A promptconst questions = [ "What are the top level KPIs for engineering? (KPI stands for key performance indicator)", "How many days has it been since the data team has gotten updated metrics? (Choose from: 1, 2, 3, 4, 5, 6, 7, more than 7)",];const prompt = `Answer the following questions based on the meeting transcript. Format your response as:Q1: [question]A1: [answer]Q2: [question]A2: [answer]Questions:${questions.map((q, i) => `${i + 1}. ${q}`).join("\n")}Context: This is a GitLab meeting to discuss logistics.`;// Step 3: Send to LLM Gatewayconst llm_gateway_data = { model: "claude-sonnet-4-6", messages: [ { role: "user", content: `${prompt}\n\n{{ transcript }}` }, ], transcript_id: transcript_id, max_tokens: 1000,};res = await fetch("https://llm-gateway.assemblyai.com/v1/chat/completions", { method: "POST", headers: { ...headers, "Content-Type": "application/json" }, body: JSON.stringify(llm_gateway_data),});if (!res.ok) throw new Error(`Error: ${res.status}`);const result = await res.json();console.log(result.choices[0].message.content);
For more sophisticated question-answering scenarios, you can create detailed prompts that guide the LLM to produce highly structured and context-aware responses using LLM Gateway’s flexible chat completions API.