Hey folks! I figured I'd make an API for tokenizing prompt text, getting the total tokens for that text and the OpenAI cost based on the model you pass through.
For example:
"model": "gpt-4",
"inputType": "prompt",
"text": "Your prompt text goes here!"
}```
Becomes this:
```{
"model": "gpt-4",
"inputType": "prompt",
"tokens": 6,
"costing": {
"promptCostPer1KTokens": 0.03,
"promptCostPerToken": 0.000029999999999999997,
"completionCostPer1KToken": 0.06,
"completionCostPerToken": 0.000059999999999999995,
"totalCost": 0.00017999999999999998
},
"text": [7927, 10137, 1495, 5900, 1618, 0]
}```
And vice versa. You can also lookup OpenAI models and pricing information. I wrote a tutorial that you can check out on Github. You can also find me on Discord if you're stuck.
**API**: https://bit.ly/openai-prompt-text-tokenizer-cost-calculator
**Tutorial**: https://bit.ly/openai-prompt-text-tokenizer-and-cost-calculator
RapidAPI
Tokenize OpenAI promp text, get token counts and OpenAI costs. GPT-4 compatible and over 30 others models.