Token Calculator feature available as API

Hi All,

I want to know how many tokens does OpenAI count for a given text when using OpenAI models/APIs. In other words, I want the feature to calculate number of tokens for a given text just as tokenizer(OpenAI API) does but using an API.

Thanks

I guess, there’s an npm package for that if you make a search

More specifically this one

The tokens are stored locally, thus fetching a decode/encode is immediate.

Hi all, what is the formula for calculating the price of a payload?

Thanks

Hi and welcome to the developer forum!

If you use that pricing guide you can multiply the cost per 1k tokens with the number of tokens divided by 1000

1 Like

It’s straight forward:

(input_price_per_thousand_tokens * input tokens / 1000) + (output_price_per_thousand_tokens * output tokens / 1000)