@trazum/cli 1.53.0 → 1.53.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trazum/cli",
3
- "version": "1.53.0",
3
+ "version": "1.53.1",
4
4
  "description": "Trazum CLI: find where your LLM bill goes, price every finding per month, and enforce token budgets in CI.",
5
5
  "license": "MIT",
6
6
  "author": "David Mu\u00f1oz Rey",
@@ -37,7 +37,7 @@
37
37
  "prepublishOnly": "npm run build && npm test"
38
38
  },
39
39
  "dependencies": {
40
- "@trazum/core": "1.53.0"
40
+ "@trazum/core": "1.53.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^26.2.0",
package/src/i18n/en.ts CHANGED
@@ -295,7 +295,8 @@ ${bold('OPTIONS FOR optimize')}
295
295
  order mattered. Refuses on any block that refers
296
296
  backwards ("the text above"), and says which phrase.
297
297
  --llm Add a pass through the LLM configured by environment.
298
- --exact-tokens Count tokens with the official API instead of the heuristic.
298
+ --exact-tokens Count tokens with Anthropic's endpoint, not the heuristic.
299
+ Claude models only: it is Claude's tokenizer.
299
300
  --tokens-only Report the token saving and no money at all. The
300
301
  default inside Claude Code, Codex or Cursor, where
301
302
  a subscription means there is no bill to reduce.
@@ -802,6 +803,21 @@ ${bold('EXAMPLES')}
802
803
  'Set TRAZUM_LLM_BASE_URL and TRAZUM_LLM_MODEL (OpenAI-compatible endpoint),\n' +
803
804
  'or TRAZUM_LLM_PROVIDER=anthropic with TRAZUM_LLM_API_KEY.',
804
805
  exactTokensNeedsKey: () => '--exact-tokens needs ANTHROPIC_API_KEY in the environment.',
806
+ /**
807
+ * Named, and told what it cannot do rather than merely that it will not.
808
+ *
809
+ * The alternative on offer has to be somebody else's tooling, because
810
+ * Trazum has none for this family — saying so is the whole refusal. A
811
+ * refusal never arrives bare.
812
+ */
813
+ exactTokensWrongFamily: (model, provider) =>
814
+ `--exact-tokens counts with Anthropic's endpoint, which counts Claude's tokenizer${
815
+ provider === null
816
+ ? `, and the catalogue records no provider for "${model}" — so which tokenizer it uses is not something Trazum knows`
817
+ : `, and ${model} is a model from ${provider}`
818
+ }. Counting it there would either be refused upstream or return a number for a different tokenizer, and this tool will not label that exact. Drop --exact-tokens for the estimate — which is honest about being one — or count with ${
819
+ provider === null ? "that model's" : provider + "'s"
820
+ } own tooling.`,
805
821
  checkNeedsMaxTokens: () => 'trazum check needs --max-tokens <n>.',
806
822
  evalNeedsCases: () => 'trazum eval needs --cases <file>.',
807
823
  unknownExportFormat: (received, allowed) =>
package/src/i18n/es.ts CHANGED
@@ -829,6 +829,14 @@ ${bold('EJEMPLOS')}
829
829
  'Define TRAZUM_LLM_BASE_URL y TRAZUM_LLM_MODEL (endpoint compatible con OpenAI),\n' +
830
830
  'o TRAZUM_LLM_PROVIDER=anthropic con TRAZUM_LLM_API_KEY.',
831
831
  exactTokensNeedsKey: () => '--exact-tokens necesita ANTHROPIC_API_KEY en el entorno.',
832
+ exactTokensWrongFamily: (model, provider) =>
833
+ `--exact-tokens cuenta con el endpoint de Anthropic, que cuenta el tokenizador de Claude${
834
+ provider === null
835
+ ? `, y el catálogo no registra proveedor para "${model}": qué tokenizador usa no es algo que Trazum sepa`
836
+ : `, y ${model} es un modelo de ${provider}`
837
+ }. Contarlo ahí sería rechazado arriba o devolvería un número de otro tokenizador, y esta herramienta no va a llamar exacto a eso. Quita --exact-tokens y quédate con la estimación —que es honesta sobre serlo— o cuenta con las herramientas de ${
838
+ provider === null ? 'ese modelo' : provider
839
+ }.`,
832
840
  checkNeedsMaxTokens: () => 'trazum check necesita --max-tokens <n>.',
833
841
  evalNeedsCases: () => 'trazum eval necesita --cases <fichero>.',
834
842
  unknownExportFormat: (received, allowed) =>
package/src/i18n/types.ts CHANGED
@@ -52,6 +52,12 @@ export interface CliMessages {
52
52
  llmNotConfigured(): string;
53
53
  applyNeedsSuggest(): string;
54
54
  exactTokensNeedsKey(): string;
55
+ /**
56
+ * `provider` is null when the model is not in the price catalogue at all —
57
+ * a different mistake from asking for an exact count on a family Trazum
58
+ * cannot count, and told as a different sentence.
59
+ */
60
+ exactTokensWrongFamily(model: string, provider: string | null): string;
55
61
  checkNeedsMaxTokens(): string;
56
62
  evalNeedsCases(): string;
57
63
  evalNoCases(path: string): string;
package/src/index.ts CHANGED
@@ -36,6 +36,7 @@ import {
36
36
  comparePrompts,
37
37
  compareToBaseline,
38
38
  computeSavings,
39
+ bandGoverns,
39
40
  countTokensAnthropic,
40
41
  DEFAULT_USAGE,
41
42
  budgetPositions,
@@ -3613,6 +3614,26 @@ async function commandOptimize(
3613
3614
  }
3614
3615
 
3615
3616
  if (boolFlag(args, 'exact-tokens')) {
3617
+ /**
3618
+ * The family check comes **before** the key check, and the order is the
3619
+ * point.
3620
+ *
3621
+ * This branch used to hand `result.usage.model` straight to Anthropic's
3622
+ * `count_tokens`. On a Claude model that is exactly right. On `gpt-5` it
3623
+ * sends somebody else's model id to Anthropic and returns either a
3624
+ * confusing upstream error or a number counted with the wrong tokenizer and
3625
+ * labelled exact — and "exact" is the strongest word this tool uses about a
3626
+ * count.
3627
+ *
3628
+ * Asking for `ANTHROPIC_API_KEY` first would send a reader on another
3629
+ * family to find a credential that could not have helped them.
3630
+ */
3631
+ const priced = pricing.byId.get(result.usage.model);
3632
+ if (!bandGoverns(priced?.provider)) {
3633
+ throw new Error(
3634
+ t.errors.exactTokensWrongFamily(result.usage.model, priced?.provider ?? null),
3635
+ );
3636
+ }
3616
3637
  const apiKey = process.env.ANTHROPIC_API_KEY;
3617
3638
  if (!apiKey) {
3618
3639
  throw new Error(t.errors.exactTokensNeedsKey());