@tensorcost/cli
v0.2.0
Published
TensorCost CLI — estimate and compare LLM prompt costs from the command line.
Maintainers
Readme
@tensorcost/cli
Estimate and compare LLM prompt costs from the command line. No API key required — pricing is bundled offline and works in CI with no network access.
npx @tensorcost/cli estimate --prompt-file prompts/rerank.v3.txt \
--model claude-3-sonnet
Estimated cost : $0.0042 / call
Input tokens : 1,420
Output tokens : 284
At 1,000 calls/day: $126.00/monthnpx @tensorcost/cli compare \
--baseline-file prompts/rerank.v2.txt \
--candidate-file prompts/rerank.v3.txt \
--model anthropic/claude-3-sonnet
baseline → candidate:
Input tokens : 1,280 → 1,420 (+10.9%)
Cost/call : $0.0038 → $0.0042 (+10.9%)
Verdict : candidate is 10.9% more expensive per call.Installation
npm install -g @tensorcost/cli
# or run without installing:
npx @tensorcost/cli <subcommand>Both tensorcost and tc are registered as binary names, so after a global install you can use either:
tensorcost estimate --prompt "Hello" --model openai/gpt-4o
tc estimate --prompt "Hello" --model openai/gpt-4oCommands
estimate
Estimate the cost of a single prompt invocation.
| Flag | Description |
|------|-------------|
| --prompt <text> | Inline prompt text |
| --prompt-file <path> | Path to a prompt file |
| --model <id> | Model identifier (required) — see tensorcost models |
| --expected-output-tokens <n> | Override output token estimate (default: max(64, input/5)) |
| --calls-per-day <n> | Also print a monthly cost projection |
| --json | Output machine-readable JSON |
tensorcost estimate \
--prompt "Summarize the following document in three bullet points." \
--model anthropic/claude-3-haiku \
--calls-per-day 5000compare
Compare cost between a baseline and a candidate prompt.
| Flag | Description |
|------|-------------|
| --baseline <text> / --baseline-file <path> | Baseline prompt |
| --candidate <text> / --candidate-file <path> | Candidate prompt |
| --model <id> | Model identifier (required) |
| --expected-output-tokens <n> | Override output token estimate for both sides |
| --json | Output machine-readable JSON |
tensorcost compare \
--baseline-file prompts/v1.txt \
--candidate-file prompts/v2.txt \
--model openai/gpt-4o \
--jsonmodels
List all bundled models and their current input/output rates.
tensorcost models
tensorcost models --jsonSupported models
| ID | Provider | Input $/M | Output $/M |
|----|----------|-----------|------------|
| anthropic/claude-3-haiku | Anthropic | $0.25 | $1.25 |
| anthropic/claude-3-sonnet | Anthropic | $3.00 | $15.00 |
| anthropic/claude-3-opus | Anthropic | $15.00 | $75.00 |
| anthropic/claude-3-5-sonnet | Anthropic | $3.00 | $15.00 |
| anthropic/claude-3-5-haiku | Anthropic | $1.00 | $5.00 |
| anthropic/claude-3-7-sonnet | Anthropic | $3.00* | $15.00* |
| anthropic/claude-sonnet-4-5 | Anthropic | $3.00* | $15.00* |
| openai/gpt-3.5-turbo | OpenAI | $0.50 | $1.50 |
| openai/gpt-4o | OpenAI | $2.50 | $10.00 |
| openai/gpt-4o-mini | OpenAI | $0.15 | $0.60 |
| openai/gpt-4-turbo | OpenAI | $10.00 | $30.00 |
| openai/o1 | OpenAI | $15.00* | $60.00* |
| openai/o1-mini | OpenAI | $3.00* | $12.00* |
| openai/o3-mini | OpenAI | $1.10* | $4.40* |
| bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0 | AWS Bedrock | $3.00 | $15.00 |
| bedrock/anthropic.claude-3-5-haiku-20241022-v1:0 | AWS Bedrock | $1.00 | $5.00 |
| bedrock/anthropic.claude-3-opus-20240229-v1:0 | AWS Bedrock | $15.00 | $75.00 |
| bedrock/amazon.titan-text-express-v1 | AWS Bedrock | $0.20 | $0.60 |
| bedrock/meta.llama3-70b-instruct-v1:0 | AWS Bedrock | $2.65 | $3.50 |
| bedrock/meta.llama3-1-70b-instruct-v1:0 | AWS Bedrock | $2.65* | $3.50* |
| bedrock/meta.llama3-1-8b-instruct-v1:0 | AWS Bedrock | $0.22* | $0.22* |
| bedrock/amazon.nova-micro-v1:0 | AWS Bedrock | $0.035* | $0.14* |
| bedrock/amazon.nova-lite-v1:0 | AWS Bedrock | $0.06* | $0.24* |
| bedrock/amazon.nova-pro-v1:0 | AWS Bedrock | $0.80* | $3.20* |
| vertex/gemini-1.5-pro | Google Vertex | $1.25 | $5.00 |
| vertex/gemini-1.5-flash | Google Vertex | $0.075 | $0.30 |
| vertex/gemini-2.0-flash | Google Vertex | $0.10* | $0.40* |
| azure/gpt-4o | Azure OpenAI | $2.50 | $10.00 |
| azure/gpt-4o-mini | Azure OpenAI | $0.15 | $0.60 |
* Price not confirmed against repo sources — verify against the provider pricing page before relying on this figure.
Prices are sourced from provider public pricing pages. Run tensorcost models to see the last_updated field for each model, or tensorcost models --json for a machine-readable export.
Environment variables
| Variable | Description |
|----------|-------------|
| TENSORCOST_API_KEY | API key for the TensorCost backend. When set, the CLI fetches live rates (including customer-specific negotiated discounts) from the backend on each invocation. Rates are cached for 1 hour at ~/.tensorcost/rates-cache.json. Falls back to the bundled table silently on any network or auth error. |
| TENSORCOST_BASE_URL | Override the TensorCost API base URL. Defaults to https://api.tensorcost.com. Useful for pointing at a self-hosted or staging instance. |
Live rates
When TENSORCOST_API_KEY is set, the CLI merges rates from GET {base_url}/api/v1/cli/model-rates over the bundled table. Any model present in the live response takes precedence; models absent from the response keep their bundled prices. The cache file at ~/.tensorcost/rates-cache.json is updated on a successful fetch and reused for 1 hour before the next network request.
Offline use is never affected — if the key is absent, the network is unreachable, or the endpoint returns an error, the CLI proceeds silently with the bundled table.
Tokenization
Token counts are estimated using ceil(charCount / 4), which is accurate to within ~10% for typical English text. If tiktoken or @anthropic-ai/tokenizer is installed in the same environment, the CLI will use it automatically — no configuration needed.
JSON output
Both estimate and compare accept --json for CI / scripting:
result=$(tensorcost estimate --prompt-file prompt.txt --model openai/gpt-4o --json)
total=$(echo "$result" | jq '.totalCostUsd')PR review workflow
# Makefile target — compare your branch's prompt against main
.PHONY: cost-check
cost-check:
tensorcost compare \
--baseline-file $(shell git show main:$(PROMPT)) \
--candidate-file $(PROMPT) \
--model $(MODEL)