Skip to content

Estimate price

estimate_price(token_count, model_name='gpt-3.5-turbo')

Estimate the price for the token count, for different models.

Current, we will use the gpt to extract layout and content structure from the document.

So roughly input and output tokens are the same So we will have (input price + output price) * token_count * call_it_twice

Parameters:

Name Type Description Default
token_count int

Number of tokens

required
model_name str

Model name to estimate the price Choices: "gpt-3.5-turbo", "gpt-4o", "gpt-4-turbo"

'gpt-3.5-turbo'

Returns:

Name Type Description
price_in_usd float

Price in USD

  • Model: gpt-3.5-turbo => Price US$0.50 / 1M tokens (Input), US1.50 / 1M tokens (Output)
Source code in Docs2KG/utils/llm/estimate_price.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def estimate_price(token_count: int, model_name: str = "gpt-3.5-turbo") -> float:
    """
    Estimate the price for the token count, for different models.

    Current, we will use the gpt to extract layout and content structure from the document.

    So roughly input and output tokens are the same
    So we will have (input price + output price) * token_count * call_it_twice

    Args:
        token_count (int): Number of tokens
        model_name (str): Model name to estimate the price
            Choices: "gpt-3.5-turbo", "gpt-4o", "gpt-4-turbo"

    Returns:
        price_in_usd (float): Price in USD


    - Model: gpt-3.5-turbo => Price US$0.50 / 1M tokens (Input), US1.50 / 1M tokens (Output)

    """
    if model_name == "gpt-3.5-turbo":
        return 2 * token_count * 2 / 1000000
    if model_name == "gpt-4o":
        return 2 * token_count * 20 / 1000000
    if model_name == "gpt-4-turbo":
        return 2 * token_count * 40 / 1000000
    raise ValueError(f"Model {model_name} is not supported")