In this guide, you’ll learn how to use LLM Gateway to ask questions and get answers about your audio transcripts.
Basic Q&A example
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.
import requests
import 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-6",
"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);
Example output
Based on the transcript, runner's knee is a condition characterized
by pain behind or around the kneecap. It is caused by overuse,
muscle imbalance and inadequate stretching. Symptoms include pain
under or around the kneecap and pain when walking.
Structured Q&A with LLM Gateway
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:
import requests
import time
# Step 1: Transcribe the audio
base_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 prompt
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)"
]
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 Gateway
llm_gateway_data = {
"model": "claude-sonnet-4-6",
"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 audio
const 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 prompt
const 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 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);
Advanced Q&A with LLM Gateway
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.
More Q&A prompt examples
Try any of these prompts to get started:
| Use case | Example prompt |
|---|
| Question and answer | ”Identify any patterns or trends based on the transcript” |
| Closed-ended questions | ”Did the customer express a positive sentiment in the phone call?” |
| Sentiment analysis | ”What was the emotional sentiment of the phone call?” |
For more examples and techniques, experiment with different prompt structures and try various LLM models available through LLM Gateway.
API reference
Improve the results
To improve your Q&A results with LLM Gateway:
- Experiment with different models: Try Claude, GPT, or Gemini models to find the best fit for your use case
- Refine your prompts: Use clear, specific instructions and examples to guide the model’s responses
- Add context: Provide relevant background information to help the model understand the domain
- Structure your questions: Use consistent formatting to get more predictable outputs