#OpenAI Prompt Text Tokenizer & Cost Calculator API

1 messages · Page 1 of 1 (latest)

tulip shore
#

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
GitHub

A tutorial on how to integrate the OpenAI Prompt Text Tokenizer & Cost Calculator API into apps. - GitHub - twixel-io/openai-prompt-text-tokenizer-and-cost-calculator: A tutorial on how to ...