> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tensorcost.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI

> @tensorcost/cli — estimate and compare LLM prompt costs from the command line, offline, with bundled pricing data.

# CLI

`@tensorcost/cli` estimates and compares LLM prompt costs from a terminal or CI job. It ships with bundled, offline pricing data — no API key or network access required to get a number.

<Note>
  This is a standalone estimation tool, not the way you connect an account to TensorCost. For that, see [get started](/getting-started). If you want live cost *observability* for calls your app is already making, see [developer tools](/developer-tools).
</Note>

## Install

```bash theme={null}
npm install -g @tensorcost/cli
# or run without installing:
npx @tensorcost/cli <subcommand>
```

Both `tensorcost` and `tc` are registered as binary names after a global install:

```bash theme={null}
tensorcost estimate --prompt "Hello" --model openai/gpt-4o
tc estimate --prompt "Hello" --model openai/gpt-4o
```

## `estimate`

Estimate the cost of a single prompt invocation.

```bash theme={null}
tensorcost estimate \
  --prompt "Summarize the following document in three bullet points." \
  --model anthropic/claude-3-haiku \
  --calls-per-day 5000
```

```
Estimated cost : $0.0042 / call
Input tokens   : 1,420
Output tokens  : 284
At 1,000 calls/day: $126.00/month
```

| 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`                       | Machine-readable output                                      |

## `compare`

Compare cost between a baseline and a candidate prompt — useful for a "does my prompt-engineering change cost more?" check before you ship it.

```bash theme={null}
tensorcost compare \
  --baseline-file prompts/v1.txt \
  --candidate-file prompts/v2.txt \
  --model openai/gpt-4o \
  --json
```

| 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`                                         | Machine-readable output                       |

## `models`

List every bundled model and its current rate.

```bash theme={null}
tensorcost models
tensorcost models --json
```

Covers Anthropic, OpenAI, AWS Bedrock, Google Vertex, and Azure OpenAI model IDs. Run `tensorcost models --json` for the `last_updated` field per model — a few less-common models are marked in the CLI's own output as not yet confirmed against the provider's pricing page, so check there before relying on those specific figures.

## Live rates (optional)

By default everything runs offline against the bundled pricing table. Set `TENSORCOST_API_KEY` and the CLI fetches live rates — including any negotiated discount on your account — on each invocation, cached for an hour at `~/.tensorcost/rates-cache.json`. If the key is absent, the network is unreachable, or the request fails, the CLI falls back to the bundled table silently — offline use is never blocked.

| Variable              | Description                                                          |
| --------------------- | -------------------------------------------------------------------- |
| `TENSORCOST_API_KEY`  | API key for live rates from your TensorCost account                  |
| `TENSORCOST_BASE_URL` | Override the API base URL — defaults to `https://api.tensorcost.com` |

## Tokenization

Token counts are estimated using `ceil(charCount / 4)` by default, accurate to within roughly 10% for typical English text. If `tiktoken` or `@anthropic-ai/tokenizer` is installed alongside the CLI, it's used automatically — no configuration needed.

## CI usage

Both `estimate` and `compare` accept `--json`:

```bash theme={null}
result=$(tensorcost estimate --prompt-file prompt.txt --model openai/gpt-4o --json)
total=$(echo "$result" | jq '.totalCostUsd')
```

A common pattern is a Makefile target that fails a PR if a prompt change costs meaningfully more:

```makefile theme={null}
.PHONY: cost-check
cost-check:
	tensorcost compare \
	  --baseline-file $(shell git show main:$(PROMPT)) \
	  --candidate-file $(PROMPT) \
	  --model $(MODEL)
```
