Add your description here
Project description
tokenary
Minimal Python library to calculate LLM API costs based on the LiteLLM model catalog.
Installation
pip install tokenary
Usage
Functional API
import tokenary
from tokenary import ModelName
result = tokenary.calculate(
model=ModelName.AZURE_GPT_3_5_TURBO,
input_tokens=1000,
output_tokens=500,
)
print(result.total_cost)
print(result.model_dump())
Request object
from tokenary import ModelName, UsageCostRequest, calculate
request = UsageCostRequest(
model=ModelName.AZURE_GPT_3_5_TURBO,
input_tokens=2000,
output_tokens=800,
reasoning_tokens=200,
)
result = calculate(request)
print(result.model_dump())
Reasoning tokens (e.g. o1)
from tokenary import ModelName, calculate
result = calculate(
model=ModelName.O1,
input_tokens=500,
output_tokens=200,
reasoning_tokens=300,
)
print(f"Total: ${result.total_cost:.6f}")
print(f" Reasoning: ${result.reasoning_cost:.6f}")
All supported parameters
| Parameter | Type | Description |
|---|---|---|
model |
ModelName |
Model identifier |
input_tokens |
int |
Number of input tokens |
output_tokens |
int |
Number of output tokens |
reasoning_tokens |
int |
Reasoning tokens (e.g. o1) |
audio_input_tokens |
int |
Audio input tokens |
generated_images |
int |
Number of generated images |
code_interpreter_sessions |
int |
Code interpreter sessions |
file_search_calls |
int |
File search API calls |
file_search_gb_days |
float |
File search storage (GB-days) |
vector_store_gb_days |
float |
Vector store storage (GB-days) |
The returned CostBreakdown object contains per-category costs (input_cost, output_cost, reasoning_cost, …) and a total_cost, all in USD.
Generate pricing artifacts
Re-generate the bundled pricing data from the LiteLLM catalog:
python -m tokenary.generator
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tokenary-0.1.0.tar.gz
(220.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
tokenary-0.1.0-py3-none-any.whl
(141.4 kB
view details)
File details
Details for the file tokenary-0.1.0.tar.gz.
File metadata
- Download URL: tokenary-0.1.0.tar.gz
- Upload date:
- Size: 220.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92d04543932b706380adfc4f3a5178dfb5070fe18a3525aafcfe86ee6aa375cf
|
|
| MD5 |
3edfffa2f818696e8ec7ffbf86411636
|
|
| BLAKE2b-256 |
53bc96ebbdc926e364956630cd0130bb19558039169a2f10fb2d48ec2ca4918a
|
File details
Details for the file tokenary-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tokenary-0.1.0-py3-none-any.whl
- Upload date:
- Size: 141.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b18039692202213e43477c5adde4789b5f477a1fe971373634747576b3765b23
|
|
| MD5 |
b94cf4b464339827ec06fdc6fb089b7c
|
|
| BLAKE2b-256 |
e94010d0302113e6283922de672f8dbfee098cd04b27015b4732010e128d3eef
|