#Calculate API Pricing

1 messages · Page 1 of 1 (latest)

stray mountain
#

I'm using whisper and completions API with python, how can I calculate price and tokens info for each call?

final lakeBOT
#

Hi @stray mountain. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To calculate the cost of using the Whisper and Completions API, you need to consider the number of tokens used in each API call. Both input and output tokens count towards these quantities.

For the Completions API, you can parse the response's "usage" field to estimate the inference costs. Here's an example of how you can do this in Python:

# estimate inference cost assuming gpt-3.5-turbo (4K context)
i_tokens = result["model_response"].usage.prompt_tokens 
o_tokens = result["model_response"].usage.completion_tokens 

i_cost = (i_tokens / 1000) * 0.0015
o_cost = (o_tokens / 1000) * 0.002

print(f"""Token Usage
 Prompt: {i_tokens} tokens
 Completion: {o_tokens} tokens
 Cost estimation: ${round(i_cost + o_cost, 5)}""")

This code calculates the cost by multiplying the number of tokens by the cost per token. The cost per token can be found in the OpenAI Pricing Guide (https://openai.com/pricing).

For the Whisper API, the pricing is based on the duration of the audio processed, rounded to the nearest second. The cost is $0.006 per minute. However, it's important to note that speeding up the audio files does not reduce the cost, as one user found out in a forum post (https://community.openai.com/t/658024).

Unfortunately, the Whisper API does not return pricing or token information in the API response. If you believe you're being overcharged, it might be worth reaching out to OpenAI support for clarification.

#

@stray mountain kapa.ai is still learning and improving, please let us know how it did by reacting below