erltoken
View SourceErlang token budgeting and cost estimation backed by the Rust tiktoken crate.
Version: 0.1.7
All string inputs and outputs are binaries.
Versioning
bump2version patch
bump2version minor
bump2version major
Version bumps update the README, Erlang .app.src, and Rust package metadata together.
Build
rebar3 compile
Examples
1> erltoken:encoding_for_model(<<"gpt-4o">>).
{ok,<<"o200k_base">>}
2> erltoken:count(<<"gpt-4o">>, <<"hello world">>).
{ok,2}
3> erltoken:fits(<<"gpt-4o">>, <<"hello world">>, 10).
{ok,true}
4> erltoken:trim_to_token_limit(<<"cl100k_base">>, <<"hello world">>, 1).
{ok,<<"hello">>}
5> erltoken:estimate_cost_usd_micro(<<"gpt-4o">>, 1000, 1000).
{ok,12500}estimate_cost_usd_micro/3 returns micro-USD. 12500 means $0.012500.
API
list_encodings/0encoding_for_model/1count/2encode/2encode_with_special_tokens/2decode/2fits/3remaining/3trim_to_token_limit/3estimate_cost_usd_micro/3
For token APIs, the first argument may be an encoding name such as <<"cl100k_base">> or a model name such as <<"gpt-4o">>.
License
Apache-2.0