←back to thread

268 points Areibman | 1 comments | | HN request time: 0.209s | source

Hey HN! Tokencost is a utility library for estimating LLM costs. There are hundreds of different models now, and they all have their own pricing schemes. It’s difficult to keep up with the pricing changes, and it’s even more difficult to estimate how much your prompts and completions will cost until you see the bill.

Tokencost works by counting the number of tokens in prompt and completion messages and multiplying that number by the corresponding model cost. Under the hood, it’s really just a simple cost dictionary and some utility functions for getting the prices right. It also accounts for different tokenizers and float precision errors.

Surprisingly, most model providers don't actually report how much you spend until your bills arrive. We built Tokencost internally at AgentOps to help users track agent spend, and we decided to open source it to help developers avoid nasty bills.

Show context
simonw ◴[] No.40710871[source]
I don't understand how the Claude functionality works.

As far as I know Anthropic haven't released the tokenizer for Claude - unlike OpenAI's tiktoken - but your tool lists the Claude 3 models as supported. How are you counting tokens for those?

replies(3): >>40710980 #>>40711374 #>>40718095 #
dudeinhawaii ◴[] No.40710980[source]
It's open source so you can take a look (I'm not the author): https://github.com/AgentOps-AI/tokencost/blob/main/tokencost...

It looks like tiktoken is the default for most of the methods.

Disclaimer: I didn't fully trace which are being used in each case/model.

replies(2): >>40711095 #>>40711161 #
1. simonw ◴[] No.40711161[source]
Yeah, I asked here because I dug around in the code and couldn't see how they were doing this, wanted to check I hadn't missed something.