#Calculate API Pricing
1 messages · Page 1 of 1 (latest)
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.
Remember, the total cost is the sum of the input token costs and the output token costs. For more information, you can refer to the OpenAI Pricing Guide (https://openai.com/pricing) and the OpenAI Cookbook (https://cookbook.openai.com/examples/named_entity_recognition_to_enrich_text#53-token-usage).
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@stray mountain kapa.ai is still learning and improving, please let us know how it did by reacting below