> ## Documentation Index
> Fetch the complete documentation index at: https://assemblyai.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup An AI Coach With LLM Gateway

This tutorial will demonstrate how to use AssemblyAI's [LLM Gateway](/llm-gateway) framework to receive AI coaching. LLM Gateway provides access to multiple LLM providers through a unified API.

## Quickstart

<Tabs groupId="language">
  <Tab language="python" title="Python" default>
    ```python expandable theme={null}
    import requests
    import time

    base_url = "https://api.assemblyai.com"
    headers = {"authorization": "<YOUR_API_KEY>"}

    # Use a publicly-accessible URL:
    audio_url = "https://storage.googleapis.com/aai-web-samples/meeting.mp4"

    # with open("/your_audio_file.mp3", "rb") as f:
    #     response = requests.post(base_url + "/v2/upload", headers=headers, data=f)
    #     if response.status_code != 200:
    #         print(f"Error: {response.status_code}, Response: {response.text}")
    #         response.raise_for_status()
    #     upload_json = response.json()
    #     audio_url = upload_json["upload_url"]

    data = {
        "audio_url": audio_url
    }

    response = requests.post(base_url + "/v2/transcript", headers=headers, json=data)

    if response.status_code != 200:
        print(f"Error: {response.status_code}, Response: {response.text}")

    transcript_json = response.json()
    transcript_id = transcript_json["id"]
    polling_endpoint = f"{base_url}/v2/transcript/{transcript_id}"

    while True:
        transcript = requests.get(polling_endpoint, headers=headers).json()
        if transcript["status"] == "completed":
            print(transcript['id'])
            print(f" \nFull Transcript: \n\n{transcript['text']}\n")

            break
        elif transcript["status"] == "error":
            raise RuntimeError(f"Transcription failed: {transcript['error']}")
        else:
            time.sleep(3)

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

    llm_gateway_data = {
        "model": "claude-sonnet-4-5-20250929",
        "messages": [
          {
            "role": "user",
            "content": f"{prompt} Please provide feedback for this transcript: \n\n{{{{ transcript }}}}"
          }
        ],
        "transcript_id": transcript_id,
        "max_tokens": 1500
      }

    response = requests.post(
      "https://llm-gateway.assemblyai.com/v1/chat/completions",
      headers=headers,
      json=llm_gateway_data
    )

    result = response.json()

    if "error" in result:
        print(f"\nError from LLM Gateway: {result['error']}")
    else:
        response_text = result['choices'][0]['message']['content']
        print(f"\nResponse ID: {result['request_id']}\n")
        print(response_text)
    ```
  </Tab>

  <Tab language="javascript" title="JavaScript">
    ```javascript expandable theme={null}
    const baseUrl = "https://api.assemblyai.com";
    const headers = { authorization: "<YOUR_API_KEY>" };

    // Use a publicly-accessible URL:
    const audioUrl = "https://storage.googleapis.com/aai-web-samples/meeting.mp4";

    // Or upload a local file:
    // import fs from "fs-extra";
    // const audioData = await fs.readFile("./your_audio_file.mp3");
    // const uploadRes = await fetch(`${baseUrl}/v2/upload`, {
    //   method: "POST",
    //   headers,
    //   body: audioData,
    // });
    // if (!uploadRes.ok) throw new Error(`Error: ${uploadRes.status}`);
    // const uploadResponse = await uploadRes.json();
    // const audioUrl = uploadResponse.upload_url;

    const data = {
      audio_url: audioUrl
    };

    let res = await fetch(`${baseUrl}/v2/transcript`, {
      method: "POST",
      headers: { ...headers, "Content-Type": "application/json" },
      body: JSON.stringify(data),
    });
    if (!res.ok) throw new Error(`Error: ${res.status}`);
    const transcriptResponse = await res.json();
    const transcriptId = transcriptResponse.id;
    const pollingEndpoint = `${baseUrl}/v2/transcript/${transcriptId}`;

    let transcript;
    while (true) {
      res = await fetch(pollingEndpoint, { headers });
      if (!res.ok) throw new Error(`Error: ${res.status}`);
      transcript = await res.json();
      if (transcript.status === "completed") {
        console.log(transcript.id);
        console.log(`\nFull Transcript:\n\n${transcript.text}\n`);
        break;
      } else if (transcript.status === "error") {
        throw new Error(`Transcription failed: ${transcript.error}`);
      } else {
        await new Promise((resolve) => setTimeout(resolve, 3000));
      }
    }

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

    const llmGatewayData = {
      model: "claude-sonnet-4-5-20250929",
      messages: [
        {
          role: "user",
          content: `${prompt} Please provide feedback for this transcript: \n\n{{ transcript }}`,
        },
      ],
      transcript_id: transcriptId,
      max_tokens: 1500,
    };

    res = await fetch("https://llm-gateway.assemblyai.com/v1/chat/completions", {
      method: "POST",
      headers: { ...headers, "Content-Type": "application/json" },
      body: JSON.stringify(llmGatewayData),
    });
    if (!res.ok) throw new Error(`Error: ${res.status}`);
    const result = await res.json();

    if (result.error) {
      console.log(`\nError from LLM Gateway: ${result.error}`);
    } else {
      const responseText = result.choices[0].message.content;
      console.log(`\nResponse ID: ${result.request_id}\n`);
      console.log(responseText);
    }
    ```
  </Tab>
</Tabs>

## Getting Started

Before we begin, make sure you have an AssemblyAI account and an API key. You can [sign up for an AssemblyAI account](https://www.assemblyai.com/dashboard/home) and get your API key from your dashboard.

Find more details on the current LLM Gateway pricing on the AssemblyAI [pricing page](https://www.assemblyai.com/pricing).

## Step-by-Step Instructions

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

Install the required packages:

<Tabs groupId="language">
  <Tab language="python" title="Python" default>
    ```bash theme={null}
    pip install requests
    ```
  </Tab>
</Tabs>

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

<Tabs groupId="language">
  <Tab language="python" title="Python" default>
    ```python theme={null}
    import requests
    import time

    base_url = "https://api.assemblyai.com"
    headers = {"authorization": "<YOUR_API_KEY>"}
    ```
  </Tab>

  <Tab language="javascript" title="JavaScript">
    ```javascript theme={null}
    const baseUrl = "https://api.assemblyai.com";
    const headers = { authorization: "<YOUR_API_KEY>" };
    ```
  </Tab>
</Tabs>

Use AssemblyAI to transcribe a file and save the transcript.

<Tabs groupId="language">
  <Tab language="python" title="Python" default>
    ```python expandable theme={null}
    audio_url = "https://storage.googleapis.com/aai-web-samples/meeting.mp4"

    # with open("/your_audio_file.mp3", "rb") as f:
    #     response = requests.post(base_url + "/v2/upload", headers=headers, data=f)
    #     if response.status_code != 200:
    #         print(f"Error: {response.status_code}, Response: {response.text}")
    #         response.raise_for_status()
    #     upload_json = response.json()
    #     audio_url = upload_json["upload_url"]

    data = {
        "audio_url": audio_url
    }

    response = requests.post(base_url + "/v2/transcript", headers=headers, json=data)

    if response.status_code != 200:
        print(f"Error: {response.status_code}, Response: {response.text}")

    transcript_json = response.json()
    transcript_id = transcript_json["id"]
    polling_endpoint = f"{base_url}/v2/transcript/{transcript_id}"

    while True:
        transcript = requests.get(polling_endpoint, headers=headers).json()
        if transcript["status"] == "completed":
            print(transcript['id'])
            print(f" \nFull Transcript: \n\n{transcript['text']}\n")

            break
        elif transcript["status"] == "error":
            raise RuntimeError(f"Transcription failed: {transcript['error']}")
        else:
            time.sleep(3)
    ```
  </Tab>

  <Tab language="javascript" title="JavaScript">
    ```javascript expandable theme={null}
    // Use a publicly-accessible URL:
    const audioUrl = "https://storage.googleapis.com/aai-web-samples/meeting.mp4";

    // Or upload a local file:
    // import fs from "fs-extra";
    // const audioData = await fs.readFile("./your_audio_file.mp3");
    // const uploadRes = await fetch(`${baseUrl}/v2/upload`, {
    //   method: "POST",
    //   headers,
    //   body: audioData,
    // });
    // if (!uploadRes.ok) throw new Error(`Error: ${uploadRes.status}`);
    // const uploadResponse = await uploadRes.json();
    // const audioUrl = uploadResponse.upload_url;

    const data = {
      audio_url: audioUrl
    };

    let res = await fetch(`${baseUrl}/v2/transcript`, {
      method: "POST",
      headers: { ...headers, "Content-Type": "application/json" },
      body: JSON.stringify(data),
    });
    if (!res.ok) throw new Error(`Error: ${res.status}`);
    const transcriptResponse = await res.json();
    const transcriptId = transcriptResponse.id;
    const pollingEndpoint = `${baseUrl}/v2/transcript/${transcriptId}`;

    let transcript;
    while (true) {
      res = await fetch(pollingEndpoint, { headers });
      if (!res.ok) throw new Error(`Error: ${res.status}`);
      transcript = await res.json();
      if (transcript.status === "completed") {
        console.log(transcript.id);
        console.log(`\nFull Transcript:\n\n${transcript.text}\n`);
        break;
      } else if (transcript.status === "error") {
        throw new Error(`Transcription failed: ${transcript.error}`);
      } else {
        await new Promise((resolve) => setTimeout(resolve, 3000));
      }
    }
    ```
  </Tab>
</Tabs>

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.

<Tabs groupId="language">
  <Tab language="python" title="Python" default>
    ```python theme={null}
    prompt = f"""
            - You are an expert at providing valuable feedback to individuals.
            - You possess exceptionally high emotional intelligence.
            - You excel at analyzing the behavior of individuals in the given transcript and providing insights on how they could improve.
            - You emphasize constructive criticism in your feedback.
            - The feedback focuses on how people can better achieve their objectives.
            - You avoid providing unjustified or unfounded feedback.
            - Your communication is clear, accurate and concise, and you write with perfect English.
            - Directly start with the feedback without any preamble or introduction.
            """
    ```
  </Tab>

  <Tab language="javascript" title="JavaScript">
    ```javascript theme={null}
    const prompt = `
            - You are an expert at providing valuable feedback to individuals.
            - You possess exceptionally high emotional intelligence.
            - You excel at analyzing the behavior of individuals in the given transcript and providing insights on how they could improve.
            - You emphasize constructive criticism in your feedback.
            - The feedback focuses on how people can better achieve their objectives.
            - You avoid providing unjustified or unfounded feedback.
            - Your communication is clear, accurate and concise, and you write with perfect English.
            - Directly start with the feedback without any preamble or introduction.
            `;
    ```
  </Tab>
</Tabs>

Generate the custom feedback using LLM Gateway.

<Tabs groupId="language">
  <Tab language="python" title="Python" default>
    ```python theme={null}
    llm_gateway_data = {
        "model": "claude-sonnet-4-5-20250929",
        "messages": [
          {
            "role": "user",
            "content": f"{prompt} Please provide feedback for this transcript: \n\n{{{{ transcript }}}}"
          }
        ],
        "transcript_id": transcript_id,
        "max_tokens": 1500,
        "temperature": 0
      }

    response = requests.post(
      "https://llm-gateway.assemblyai.com/v1/chat/completions",
      headers=headers,
      json=llm_gateway_data
    )
    ```
  </Tab>

  <Tab language="javascript" title="JavaScript">
    ```javascript theme={null}
    const llmGatewayData = {
      model: "claude-sonnet-4-5-20250929",
      messages: [
        {
          role: "user",
          content: `${prompt} Please provide feedback for this transcript: \n\n{{ transcript }}`,
        },
      ],
      transcript_id: transcriptId,
      max_tokens: 1500,
      temperature: 0,
    };

    const res = await fetch("https://llm-gateway.assemblyai.com/v1/chat/completions", {
      method: "POST",
      headers: { ...headers, "Content-Type": "application/json" },
      body: JSON.stringify(llmGatewayData),
    });
    if (!res.ok) throw new Error(`Error: ${res.status}`);
    const response = await res.json();
    ```
  </Tab>
</Tabs>

Finally, save and return the LLM response.

<Tabs groupId="language">
  <Tab language="python" title="Python" default>
    ```python theme={null}
    result = response.json()

    if "error" in result:
        print(f"\nError from LLM Gateway: {result['error']}")
    else:
        response_text = result['choices'][0]['message']['content']
        print(f"\nResponse ID: {result['request_id']}\n")
        print(response_text)
    ```
  </Tab>

  <Tab language="javascript" title="JavaScript">
    ```javascript theme={null}
    if (response.error) {
      console.log(`\nError from LLM Gateway: ${response.error}`);
    } else {
      const responseText = response.choices[0].message.content;
      console.log(`\nResponse ID: ${response.request_id}\n`);
      console.log(responseText);
    }
    ```
  </Tab>
</Tabs>
