←back to thread

268 points Areibman | 1 comments | | HN request time: 0s | 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 #
Areibman ◴[] No.40711374[source]
Anthropic actually has a Claude 3 tokenizer tucked away in one of their repos: https://github.com/anthropics/anthropic-tokenizer-typescript

At this moment, Tokencost uses the OpenAI tokenizer as a default tokenizer, but this would be a welcome PR!

replies(1): >>40711504 #
simonw ◴[] No.40711504[source]
"This package can be used to count tokens for Anthropic's older models. As of the Claude 3 models, this algorithm is no longer accurate [...]"

I've been bugging Anthropic about this for a while, they said that releasing a new tokenizer is not on their current roadmap.

replies(1): >>40711734 #
throwaway211 ◴[] No.40711734[source]
Imagine a coffee shop refusing to have a price list until after the coffee's been made.
replies(3): >>40712333 #>>40715060 #>>40717521 #
kevindamm ◴[] No.40712333[source]
In many countries a taxi won't tell you how much the ride will cost. The first time I traveled to somewhere that negotiated the cost up front it blew my mind.

Frequently, contracts will have room for additional charges if circumstances change even a little, or products will have a market rate (fish, equity, etc.).

It might seem absurd but variable cost things are not uncommon.

replies(5): >>40712570 #>>40714914 #>>40715972 #>>40720216 #>>40777992 #
1. szundi ◴[] No.40720216{3}[source]
These are called the variable variable costs now