Embed Cost Estimator
A lightweight Python library and CLI to estimate OpenAI embedding costs.
Installation
Install from PyPI:
pip install embedding-cost-estimator
Basic CLI Usage (Rough Estimate)
Run a quick rough estimate using a simple chars/4 heuristic:
embed-cost --chunks <NUM_CHUNKS> --chars <AVG_CHARS_PER_CHUNK> [--model <MODEL>]
#--chunks, -n Number of chunks (required)
#--chars, -c Average characters per chunk (default: 500)
#--model, -m Embedding model choice (default: text-embedding-ada-002)
CLI Options
| Option | Shortcut | Type | Default | Description |
|---|---|---|---|---|
--chunks |
-n |
integer | required | Number of chunks for rough estimate |
--chars |
-c |
integer | 500 |
Average characters per chunk |
--model |
-m |
choice | text-embedding-ada-002 |
Embedding model to use (see MODEL_RATES) |
--help |
— | flag | — | Show this help message and exit |
Examples:
1. Default model, custom sizes
embed-cost --chunks 1000 --chars 500
#Estimated embedding cost: $0.050000
2. Using a different model
embed-cost --chunks 500 --chars 300 --model text-embedding-3-small
# Estimated embedding cost: $0.003000
Python API
You can call estimate_embedding_cost() in two mutually-exclusive ways:
1. Rough estimate
Rough estimate using a simple chars/4 heuristic
from embed_cost import estimate_embedding_cost
cost = estimate_embedding_cost(
num_chunks=250,
chunk_size_chars=400,
model="text-embedding-3-small",
)
print(f"Rough cost: ${cost:.6f}")
2. Precise mode (exact token counts via tiktoken):
For exact token counts via tiktoken, by passing your list of text chunks
from embed_cost import estimate_embedding_cost
# your pre-chunked list of text segments
chunked_docs = [
"First chunk of text…",
"Second chunk of text…",
# …etc…
]
cost = estimate_embedding_cost(
chunk_texts=chunked_docs,
model="text-embedding-ada-002",
)
print(f"Precise cost: ${cost:.6f}")
Example
1. Exact Token Count in Code
from embed_cost import estimate_embedding_cost
# assuming your document is already split:
chunked = ["Lorem ipsum…", "Dolor sit amet…", …]
cost = estimate_embedding_cost(
chunk_texts=chunked,
)
print(cost) # e.g. 0.000320
Contributing
We welcome contributions!
-
Fork the repo and create a feature branch.
-
Run tests and lint locally:
poetry install # or pip install -e .
poetry run pytest -q # or pytest -q
poetry run flake8 src tests
poetry run black --check .
-
Open a pull request against
main. -
Maintain 100% test coverage for new code and adhere to Black/Flake8 style.
Please see CONTRIBUTING.md for more details.
License
MIT © Pragasen Naicker
Metadata
Release files for embedding-cost-estimator 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| embedding_cost_estimator-1.0.1.tar.gz | 4.2 kB | Without provenance | Details for embedding_cost_estimator-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| embedding_cost_estimator-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for embedding_cost_estimator-1.0.1-py3-none-any.whl |
Total release size: 9.8 kB
Release files / embedding_cost_estimator-1.0.1.tar.gz
| Download URL | embedding_cost_estimator-1.0.1.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1cc505eee25e8ec86fad80fad74fab1e14b99c53a2aeaf47900afc8f039fc179
|
|
BLAKE2b-256 checksum How to use checksums |
d2f80356219da36c99f3ea88d0e8da394479d25b1f1c1b0dadc78fbaf1fa9432
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.2 Darwin/23.6.0
|
Release files / embedding_cost_estimator-1.0.1-py3-none-any.whl
| Download URL | embedding_cost_estimator-1.0.1-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ccda2c187acabf278c3b3ca0cd87967acd5abc76b2ef523def91244284dc660a
|
|
BLAKE2b-256 checksum How to use checksums |
6e2526955deb3e30f9333d18dd0f015f28f9d5aa89b438ac875e36156c427ca1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.2 Darwin/23.6.0
|
Security for embedding-cost-estimator 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.