> ## 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.

# Estimate Input Token Costs for LLM Gateway

AssemblyAI's [LLM Gateway](/llm-gateway/quickstart) is a unified API providing access to 25+ models from Claude, GPT, Gemini, and more through a single interface.
It's 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](https://www.assemblyai.com/pricing) for LLM Gateway is based on **both** input and output tokens.

Output tokens will vary depending on the model and the complexity of your request, but how do you determine the amount of input tokens you'll be sending to LLM Gateway?
How many tokens does an audio file and your prompt contain? This guide will show you how to roughly calculate that information to help predict LLM Gateway's input token cost ahead of time.

<Note>
  This guide calculates **input token costs only**.
  Output token costs will vary based on the model used and the length of the generated response.

  To see the specific cost of each model (per 1M input and output tokens) applicable to your AssemblyAI account, refer to the Rates table on the [Billing page](https://www.assemblyai.com/dashboard/home) of the dashboard.
</Note>

## 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"}

    # Transcribe audio file
    audio_url = "https://assembly.ai/wildfires.mp3"
    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}"

    # Poll for completion
    print("Waiting for transcription to complete...")

    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']}")
        time.sleep(3)

    # Define your prompt
    prompt = "Provide a brief summary of the transcript."

    # Calculate character count (transcript + prompt)
    transcript_chars = len(transcript["text"])
    prompt_chars = len(prompt)
    total_chars = transcript_chars + prompt_chars
    print(f"\nTotal characters: {total_chars}")

    # Estimate tokens (roughly 4 characters = 1 token)
    estimated_tokens = total_chars / 4
    tokens_in_millions = estimated_tokens / 1_000_000

    # Calculate input costs for different models
    gpt5_cost = 1.25 * tokens_in_millions
    claude_sonnet_cost = 3.00 * tokens_in_millions
    gemini_pro_cost = 1.25 * tokens_in_millions

    print(f"Estimated input tokens: {estimated_tokens:,.0f}")
    print(f"\nEstimated input costs:")
    print(f"GPT-5: ${gpt5_cost:.4f}")
    print(f"Claude Sonnet 4.6: ${claude_sonnet_cost:.4f}")
    print(f"Gemini 2.5 Pro: ${gemini_pro_cost:.4f}")
    ```
  </Tab>

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

    // Transcribe audio file
    const audioUrl = "https://assembly.ai/wildfires.mp3";
    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}`;

    // Poll for completion
    console.log("Waiting for transcription to complete...");

    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") {
        break;
      } else if (transcript.status === "error") {
        throw new Error(`Transcription failed: ${transcript.error}`);
      }
      await new Promise((resolve) => setTimeout(resolve, 3000));
    }

    // Define your prompt
    const prompt = "Provide a brief summary of the transcript.";

    // Calculate character count (transcript + prompt)
    const transcriptChars = transcript.text.length;
    const promptChars = prompt.length;
    const totalChars = transcriptChars + promptChars;
    console.log(`\nTotal characters: ${totalChars}`);

    // Estimate tokens (roughly 4 characters = 1 token)
    const estimatedTokens = totalChars / 4;
    const tokensInMillions = estimatedTokens / 1_000_000;

    // Calculate input costs for different models
    const gpt5Cost = 1.25 * tokensInMillions;
    const claudeSonnetCost = 3.00 * tokensInMillions;
    const geminiProCost = 1.25 * tokensInMillions;

    console.log(`Estimated input tokens: ${estimatedTokens.toLocaleString("en-US", { maximumFractionDigits: 0 })}`);
    console.log(`\nEstimated input costs:`);
    console.log(`GPT-5: $${gpt5Cost.toFixed(4)}`);
    console.log(`Claude Sonnet 4.6: $${claudeSonnetCost.toFixed(4)}`);
    console.log(`Gemini 2.5 Pro: $${geminiProCost.toFixed(4)}`);
    ```
  </Tab>
</Tabs>

## Step-by-Step Guide

### Install dependencies

Install the required library:

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

### Set up your API key

Import the necessary libraries and set your AssemblyAI API key, which can be found on your account [dashboard](https://www.assemblyai.com/dashboard/home):

<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>

### Transcribe your audio file

Transcribe your audio file using AssemblyAI:

<Tabs groupId="language">
  <Tab language="python" title="Python" default>
    ```python theme={null}
    audio_url = "https://assembly.ai/wildfires.mp3"
    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}"

    # Poll for completion
    print("Waiting for transcription to complete...")

    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']}")
        time.sleep(3)
    ```
  </Tab>

  <Tab language="javascript" title="JavaScript">
    ```javascript expandable theme={null}
    const audioUrl = "https://assembly.ai/wildfires.mp3";
    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}`;

    // Poll for completion
    console.log("Waiting for transcription to complete...");

    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") {
        break;
      } else if (transcript.status === "error") {
        throw new Error(`Transcription failed: ${transcript.error}`);
      }
      await new Promise((resolve) => setTimeout(resolve, 3000));
    }
    ```
  </Tab>
</Tabs>

### Calculate character count

We'll count the characters in both the transcript and your prompt:

<Tabs groupId="language">
  <Tab language="python" title="Python" default>
    ```python theme={null}
    # Define your prompt
    prompt = "Provide a brief summary of the transcript."

    # Calculate character count (transcript + prompt)
    transcript_chars = len(transcript["text"])
    prompt_chars = len(prompt)
    total_chars = transcript_chars + prompt_chars
    print(f"\nTotal characters: {total_chars}")
    ```
  </Tab>

  <Tab language="javascript" title="JavaScript">
    ```javascript theme={null}
    // Define your prompt
    const prompt = "Provide a brief summary of the transcript.";

    // Calculate character count (transcript + prompt)
    const transcriptChars = transcript.text.length;
    const promptChars = prompt.length;
    const totalChars = transcriptChars + promptChars;
    console.log(`\nTotal characters: ${totalChars}`);
    ```
  </Tab>
</Tabs>

For this specific file with the example prompt, the transcript contains approximately 4,880 characters and the prompt contains 42 characters, for a total of 4,922 characters.

### Estimate tokens

Different LLM providers use different tokenization methods, but a rough estimate is that **4 characters equals approximately 1 token**. This is based on guidance from:

* [Claude tokenization documentation](https://docs.claude.com/en/docs/about-claude/pricing#frequently-asked-questions)
* [OpenAI token counting guide](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them)
* [Gemini tokens documentation](https://ai.google.dev/gemini-api/docs/tokens?lang=python)

<Tabs groupId="language">
  <Tab language="python" title="Python" default>
    ```python theme={null}
    # Estimate tokens (roughly 4 characters = 1 token)
    estimated_tokens = total_chars / 4
    tokens_in_millions = estimated_tokens / 1_000_000

    print(f"Estimated input tokens: {estimated_tokens:,.0f}")
    ```
  </Tab>

  <Tab language="javascript" title="JavaScript">
    ```javascript theme={null}
    // Estimate tokens (roughly 4 characters = 1 token)
    const estimatedTokens = totalChars / 4;
    const tokensInMillions = estimatedTokens / 1_000_000;

    console.log(`Estimated input tokens: ${estimatedTokens.toLocaleString("en-US", { maximumFractionDigits: 0 })}`);
    ```
  </Tab>
</Tabs>

<Note>
  **Language considerations**

  Token counts can differ significantly across languages. Non-English languages
  typically require more tokens per character than English. For instance, text
  in languages like Spanish, Chinese, or Arabic may use 2-3 characters per token
  instead of 4, resulting in higher token costs for the same amount of content.
</Note>

### Calculate input token costs

LLM Gateway's pricing is calculated per 1M input tokens. Here are the [current rates](https://www.assemblyai.com/pricing) for popular models:

<Tabs groupId="language">
  <Tab language="python" title="Python" default>
    ```python theme={null}
    # Calculate input costs for different models (rates per 1M tokens)
    gpt5_cost = 1.25 * tokens_in_millions
    claude_sonnet_cost = 3.00 * tokens_in_millions
    gemini_pro_cost = 1.25 * tokens_in_millions

    print(f"\nEstimated input costs:")
    print(f"GPT-5: ${gpt5_cost:.4f}")
    print(f"Claude Sonnet 4.6: ${claude_sonnet_cost:.4f}")
    print(f"Gemini 2.5 Pro: ${gemini_pro_cost:.4f}")
    ```
  </Tab>

  <Tab language="javascript" title="JavaScript">
    ```javascript theme={null}
    // Calculate input costs for different models (rates per 1M tokens)
    const gpt5Cost = 1.25 * tokensInMillions;
    const claudeSonnetCost = 3.00 * tokensInMillions;
    const geminiProCost = 1.25 * tokensInMillions;

    console.log(`\nEstimated input costs:`);
    console.log(`GPT-5: $${gpt5Cost.toFixed(4)}`);
    console.log(`Claude Sonnet 4.6: $${claudeSonnetCost.toFixed(4)}`);
    console.log(`Gemini 2.5 Pro: $${geminiProCost.toFixed(4)}`);
    ```
  </Tab>
</Tabs>

For our example file with approximately 1,230 input tokens:

* **GPT-5** (`gpt-5`): \~\$0.0015
* **Claude Sonnet 4.6** (`claude-sonnet-4-6`): \~\$0.0037
* **Gemini 2.5 Pro** (`gemini-2.5-pro`): \~\$0.0015

<Note>
  These calculations estimate **input token costs only**. Output tokens are not included and will vary based on:

  * The model you choose
  * The complexity of your request
  * The length of the generated response

  To see the complete pricing for both input and output tokens for all available models, visit the Rates table on the [Billing page](https://www.assemblyai.com/dashboard/home) of your dashboard.
</Note>

## Next steps

* [LLM Gateway Overview](/llm-gateway/quickstart) - Learn about all available models and capabilities
* [Apply LLM Gateway to Audio Transcripts](/llm-gateway/apply-llms-to-audio-files) - Complete guide to using LLM Gateway with transcripts
* [Billing page](https://www.assemblyai.com/dashboard/home) - View LLM pricing for your account
