Generate A Custom Summary Using LLM Gateway

This tutorial will demonstrate how to use AssemblyAI’s LLM Gateway to get a custom summary using advanced prompting techniques.

Quickstart

1import requests
2import time
3
4base_url = "https://api.assemblyai.com"
5headers = {"authorization": "<YOUR_API_KEY>"}
6
7# Step 1: Transcribe the audio
8audio_url = "https://storage.googleapis.com/aai-web-samples/meeting.mp4"
9data = {"audio_url": audio_url}
10
11response = requests.post(base_url + "/v2/transcript", json=data, headers=headers)
12transcript_id = response.json()['id']
13polling_endpoint = base_url + "/v2/transcript/" + transcript_id
14
15while True:
16 transcription_result = requests.get(polling_endpoint, headers=headers).json()
17 if transcription_result['status'] == 'completed':
18 break
19 elif transcription_result['status'] == 'error':
20 raise RuntimeError(f"Transcription failed: {transcription_result['error']}")
21 else:
22 time.sleep(3)
23
24# Step 2: Generate custom summary with LLM Gateway
25prompt = """
26- You are an expert at writing factual, useful summaries.
27- You focus on key details, leave out irrelevant information, and do not add in information that is not already present in the transcript.
28- Your summaries accurately represent the information in the transcript.
29- You are useful to the reader, are true and concise, and are written in perfect English.
30- Use multiple parts of the transcript to form your summary.
31- Make your summary follow the sequential order of events in the transcript.
32- Your summaries do not describe the context of the transcript - they only summarize the events in the text.
33- Your summaries do not describe what type of text they summarize.
34- You do not dumb down specific language nor make big generalizations.
35- Respond with just the summary and don't include a preamble or introduction.
36
37Your summary should use the following format: Bullet points
38"""
39
40llm_gateway_data = {
41 "model": "claude-sonnet-4-5-20250929",
42 "messages": [
43 {"role": "user", "content": f"{prompt}\n\nTranscript: {transcription_result['text']}"}
44 ],
45 "max_tokens": 1500
46}
47
48response = requests.post(
49 "https://llm-gateway.assemblyai.com/v1/chat/completions",
50 headers=headers,
51 json=llm_gateway_data
52)
53
54result = response.json()["choices"][0]["message"]["content"]
55print(result)

Getting Started

Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up for an AssemblyAI account and get your API key from your dashboard.

Step-by-Step Instructions

In this guide, we will use LLM Gateway to generate a custom summary.

Install the required packages:

$pip install requests

Set up your API client and transcribe the audio file:

1import requests
2import time
3
4base_url = "https://api.assemblyai.com"
5headers = {"authorization": "<YOUR_API_KEY>"}
6
7# Transcribe the audio
8audio_url = "https://storage.googleapis.com/aai-web-samples/meeting.mp4"
9data = {"audio_url": audio_url}
10
11response = requests.post(base_url + "/v2/transcript", json=data, headers=headers)
12transcript_id = response.json()['id']
13polling_endpoint = base_url + "/v2/transcript/" + transcript_id
14
15while True:
16 transcription_result = requests.get(polling_endpoint, headers=headers).json()
17 if transcription_result['status'] == 'completed':
18 break
19 elif transcription_result['status'] == 'error':
20 raise RuntimeError(f"Transcription failed: {transcription_result['error']}")
21 else:
22 time.sleep(3)

Define your detailed prompt instructions for generating a custom summary:

1prompt = """
2- You are an expert at writing factual, useful summaries.
3- You focus on key details, leave out irrelevant information, and do not add in information that is not already present in the transcript.
4- Your summaries accurately represent the information in the transcript.
5- You are useful to the reader, are true and concise, and are written in perfect English.
6- Use multiple parts of the transcript to form your summary.
7- Make your summary follow the sequential order of events in the transcript.
8- Your summaries do not describe the context of the transcript - they only summarize the events in the text.
9- Your summaries do not describe what type of text they summarize.
10- You do not dumb down specific language nor make big generalizations.
11- Respond with just the summary and don't include a preamble or introduction.
12"""

Optionally specify a summary format and append it to the prompt:

1answer_format = "Bullet points"
2
3if answer_format:
4 prompt += f"\nYour summary should use the following format: {answer_format}"

Generate the custom summary using LLM Gateway:

1llm_gateway_data = {
2 "model": "claude-sonnet-4-5-20250929",
3 "messages": [
4 {"role": "user", "content": f"{prompt}\n\nTranscript: {transcription_result['text']}"}
5 ],
6 "max_tokens": 1500
7}
8
9response = requests.post(
10 "https://llm-gateway.assemblyai.com/v1/chat/completions",
11 headers=headers,
12 json=llm_gateway_data
13)
14
15result = response.json()["choices"][0]["message"]["content"]
16print(result)