Estimate Input Token Costs for LeMUR

AssemblyAI’s LeMUR (Leveraging Large Language Models to Understand Recognized Speech) framework is a powerful way to extract insights from transcripts generated from audio and video files. Given how varied the type of input and output could be for these use cases, the pricing for LeMUR is based on input and output tokens.

Output tokens can be controlled via LeMUR’s max_output_size parameter, but how do you determine the amount of input tokens you’ll be sending to LeMUR? How many tokens does an audio file contain? This Colab will show you how to calculate that information to help predict LeMUR’s cost ahead of time.

Quickstart

1import assemblyai as aai
2
3aai.settings.api_key = "YOUR_API_KEY"
4transcriber = aai.Transcriber()
5
6transcript = transcriber.transcribe("https://github.com/AssemblyAI-Examples/audio-examples/raw/main/20230607_me_canadian_wildfires.mp3")
7character_count = len(transcript.text)
8count_in_thousands = character_count / 1000
9
10sonnet_cost = 0.003 * count_in_thousands
11opus_cost = 0.015 * count_in_thousands
12haiku_cost = 0.00025 * count_in_thousands
13
14print(f"LeMUR Claude 3.5 Sonnet | LeMUR Claude 3 Sonnet Cost: ${sonnet_cost}")
15print(f"LeMUR Default | LeMUR Claude 2.1 | LeMUR Claude 3 Opus Cost: ${opus_cost}")
16print(f"LeMUR Claude 3 Haiku Cost: ${haiku_cost}")

Step-by-Step Guide

To get started, you’ll need to install the AssemblyAI Python SDK, which we’ll use to transcribe our file.

$pip install -U assemblyai

Now we’ll import these files and set our AssemblyAI API key, which can be found on your account dashboard.

1import assemblyai as aai
2
3aai.settings.api_key = "API_KEY"

Next we’ll transcribe our file using AssemblyAI.

1transcriber = aai.Transcriber()
2
3transcript = transcriber.transcribe("https://github.com/AssemblyAI-Examples/audio-examples/raw/main/20230607_me_canadian_wildfires.mp3")

LeMUR counts tokens based solely on character count, so we’ll be using Python’s built-in len() function to count the characters in our transcript.

1character_count = len(transcript.text)
2
3print(character_count)

For this specific file, we got 4,928 tokens. LeMUR’s pricing is calculated per 1K tokens, and is prorated for amounts below this.

1count_in_thousands = character_count / 1000
2
3sonnet_cost = 0.003 * count_in_thousands
4opus_cost = 0.015 * count_in_thousands
5haiku_cost = 0.00025 * count_in_thousands
6
7print(f"LeMUR Claude 3.5 Sonnet | LeMUR Claude 3 Sonnet Cost: ${sonnet_cost}")
8print(f"LeMUR Default | LeMUR Claude 2.1 | LeMUR Claude 3 Opus Cost: ${opus_cost}")
9print(f"LeMUR Claude 3 Haiku Cost: ${haiku_cost}")

Here we’ve determined how much the input tokens from our transcript will cost with LeMUR, not including the tokens of our prompt. To calculate how much the input tokens will cost for your prompt, or how much the amount of output tokens you’re limited to will cost, you can follow this same method, replacing transcript.text with the text of your prompt, or num_tokens with the max_output_size amount you’ve specified to LeMUR.