Setup An AI Coach With LLM Gateway

This tutorial will demonstrate how to use AssemblyAI’s LLM Gateway framework to receive AI coaching. LLM Gateway provides access to multiple LLM providers through a unified API.

Quickstart

1import requests
2import time
3
4base_url = "https://api.assemblyai.com"
5headers = {"authorization": "<YOUR_API_KEY>"}
6
7# Use a publicly-accessible URL:
8audio_url = "https://storage.googleapis.com/aai-web-samples/meeting.mp4"
9
10# with open("/your_audio_file.mp3", "rb") as f:
11# response = requests.post(base_url + "/v2/upload", headers=headers, data=f)
12# if response.status_code != 200:
13# print(f"Error: {response.status_code}, Response: {response.text}")
14# response.raise_for_status()
15# upload_json = response.json()
16# audio_url = upload_json["upload_url"]
17
18data = {
19 "audio_url": audio_url,
20}
21
22response = requests.post(base_url + "/v2/transcript", headers=headers, json=data)
23
24if response.status_code != 200:
25 print(f"Error: {response.status_code}, Response: {response.text}")
26
27transcript_json = response.json()
28transcript_id = transcript_json["id"]
29polling_endpoint = f"{base_url}/v2/transcript/{transcript_id}"
30
31while True:
32 transcript = requests.get(polling_endpoint, headers=headers).json()
33 if transcript["status"] == "completed":
34 print(transcript['id'])
35 print(f" \nFull Transcript: \n\n{transcript['text']}\n")
36
37 break
38 elif transcript["status"] == "error":
39 raise RuntimeError(f"Transcription failed: {transcript['error']}")
40 else:
41 time.sleep(3)
42
43prompt = f"""
44 - You are an expert at providing valuable feedback to individuals.
45 - You possess exceptionally high emotional intelligence.
46 - You excel at analyzing the behavior of individuals in the given transcript and providing insights on how they could improve.
47 - You emphasize constructive criticism in your feedback.
48 - The feedback focuses on how people can better achieve their objectives.
49 - You avoid providing unjustified or unfounded feedback.
50 - Your communication is clear, accurate and concise, and you write with perfect English.
51 - Directly start with the feedback without any preamble or introduction.
52 """
53
54llm_gateway_data = {
55 "model": "claude-sonnet-4-5-20250929",
56 "messages": [
57 {
58 "role": "user",
59 "content": f"{prompt} Please provide feedback for this transcript: \n\n{transcript["text"]}"
60 }
61 ],
62 "max_tokens": 1500
63 }
64
65response = requests.post(
66 "https://llm-gateway.assemblyai.com/v1/chat/completions",
67 headers=headers,
68 json=llm_gateway_data
69)
70
71result = response.json()
72
73if "error" in result:
74 print(f"\nError from LLM Gateway: {result['error']}")
75else:
76 response_text = result['choices'][0]['message']['content']
77 print(f"\nResponse ID: {result["request_id"]}\n")
78 print(response_text)

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.

Find more details on the current LLM Gateway pricing on the AssemblyAI pricing page.

Step-by-Step Instructions

In this guide, we’ll prompt LLM Gateway to perform some AI coaching.

Import the required pagackes and set the base URL and headers.

1import requests
2import time
3
4base_url = "https://api.assemblyai.com"
5headers = {"authorization": "<YOUR_API_KEY>"}

Use AssemblyAI to transcribe a file and save the transcript.

1audio_url = "https://storage.googleapis.com/aai-web-samples/meeting.mp4"
2
3# with open("/your_audio_file.mp3", "rb") as f:
4# response = requests.post(base_url + "/v2/upload", headers=headers, data=f)
5# if response.status_code != 200:
6# print(f"Error: {response.status_code}, Response: {response.text}")
7# response.raise_for_status()
8# upload_json = response.json()
9# audio_url = upload_json["upload_url"]
10
11data = {
12 "audio_url": audio_url,
13}
14
15response = requests.post(base_url + "/v2/transcript", headers=headers, json=data)
16
17if response.status_code != 200:
18 print(f"Error: {response.status_code}, Response: {response.text}")
19
20transcript_json = response.json()
21transcript_id = transcript_json["id"]
22polling_endpoint = f"{base_url}/v2/transcript/{transcript_id}"
23
24while True:
25 transcript = requests.get(polling_endpoint, headers=headers).json()
26 if transcript["status"] == "completed":
27 print(transcript['id'])
28 print(f" \nFull Transcript: \n\n{transcript['text']}\n")
29
30 break
31 elif transcript["status"] == "error":
32 raise RuntimeError(f"Transcription failed: {transcript['error']}")
33 else:
34 time.sleep(3)

Define your detailed prompt instructions for generating feedback on the transcript text of your sales call, meeting, or other content. This is an example prompt, which you can modify to suit your specific requirements.

1prompt = f"""
2 - You are an expert at providing valuable feedback to individuals.
3 - You possess exceptionally high emotional intelligence.
4 - You excel at analyzing the behavior of individuals in the given transcript and providing insights on how they could improve.
5 - You emphasize constructive criticism in your feedback.
6 - The feedback focuses on how people can better achieve their objectives.
7 - You avoid providing unjustified or unfounded feedback.
8 - Your communication is clear, accurate and concise, and you write with perfect English.
9 - Directly start with the feedback without any preamble or introduction.
10 """

Generate the custom feedback using LLM Gateway.

1llm_gateway_data = {
2 "model": "claude-sonnet-4-5-20250929",
3 "messages": [
4 {
5 "role": "user",
6 "content": f"{prompt} Please provide feedback for this transcript: \n\n{transcript["text"]}"
7 }
8 ],
9 "max_tokens": 1500,
10 "temperature": 0
11 }
12
13response = requests.post(
14 "https://llm-gateway.assemblyai.com/v1/chat/completions",
15 headers=headers,
16 json=llm_gateway_data
17)

Finally, save and return the LLM response.

1result = response.json()
2
3if "error" in result:
4 print(f"\nError from LLM Gateway: {result['error']}")
5else:
6 response_text = result['choices'][0]['message']['content']
7 print(f"\nResponse ID: {result["request_id"]}\n")
8 print(response_text)