@jaypie/llm 1.3.15 → 1.3.16

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.
@@ -47,6 +47,61 @@ export declare const MODEL: {
47
47
  SONNET: string;
48
48
  };
49
49
  };
50
+ /** Price of one million tokens, in US dollars. */
51
+ export interface LlmModelCost {
52
+ /**
53
+ * Cache-read (cached input) tokens. Omitted when the provider does not price
54
+ * cache reads separately from uncached input.
55
+ */
56
+ cachedInputRead?: number;
57
+ /**
58
+ * Cache-write tokens. A scalar when the rate does not vary by TTL; keyed by
59
+ * the same `"5m"` / `"1h"` literals as `LlmCache` when it does, so a cost
60
+ * calculation reads the TTL straight off `OperateRequest.cache`. Omitted
61
+ * means cache writes bill at the `input` rate.
62
+ */
63
+ cachedInputWrite?: number | {
64
+ "1h": number;
65
+ "5m": number;
66
+ };
67
+ /** Uncached input tokens. */
68
+ input: number;
69
+ /** Output tokens. */
70
+ output: number;
71
+ /**
72
+ * Reasoning tokens, when billed at a rate other than `output`. Omitted means
73
+ * reasoning bills as output, which is true of every provider listed here.
74
+ */
75
+ reasoning?: number;
76
+ }
77
+ /**
78
+ * Standard list price per million tokens, keyed by literal model id (verified
79
+ * 2026-07-21). Keys are string literals rather than `MODEL.*` references so a
80
+ * model retired from the catalog keeps its price here: historic ids stay
81
+ * priceable after they leave `MODEL.*`, which is what makes replaying old
82
+ * usage records possible.
83
+ *
84
+ * Caveats the numbers cannot carry:
85
+ * - **Standard rate only.** Introductory, batch, flex, priority, fast-mode, and
86
+ * data-residency rates are excluded. Sonnet 5 is listed at its standard
87
+ * $3/$15, not the introductory rate.
88
+ * - **Cache writes are Anthropic-only.** Fireworks writes bill at the input
89
+ * rate. OpenAI and xAI discount reads automatically and publish no write
90
+ * premium. Google charges nothing to write an implicit cache; explicit
91
+ * caching bills storage per hour, a unit this table does not carry (and one
92
+ * `@jaypie/llm` does not wire).
93
+ * - **Short-context tier.** Long-prompt surcharges are not modeled: Gemini 3.1
94
+ * Pro doubles above 200K, Grok doubles at 200K, GPT-5.5 is 2x in / 1.5x out
95
+ * above 272K.
96
+ * - **Text rates.** Gemini prices audio input higher than text/image/video.
97
+ * - **Proxies are deliberately absent.** Bedrock (`PROVIDER.BEDROCK.*`) and
98
+ * OpenRouter (`MODEL.OPENROUTER.*`) resell many vendors and price per backend
99
+ * route, so no single rate is correct for a proxy id. Price those against the
100
+ * backend model, or against the proxy's own published rate.
101
+ *
102
+ * Unlisted ids return `undefined` — callers must handle a miss.
103
+ */
104
+ export declare const COST: Record<string, LlmModelCost>;
50
105
  export declare const PROVIDER: {
51
106
  readonly BEDROCK: {
52
107
  readonly DEFAULT: "amazon.nova-pro-v1:0";
@@ -201,7 +256,7 @@ export declare const DEFAULT: {
201
256
  */
202
257
  export declare const ALL: {
203
258
  readonly BASE: readonly ["claude-sonnet-4-6", "gemini-3.1-pro-preview", "gpt-5.4", "grok-latest"];
204
- readonly COMBINED: readonly ("claude-opus-4-8" | "claude-haiku-4-5" | "gemini-3.5-flash" | "gemini-3.1-flash-lite" | "gemini-3.1-pro-preview" | "gpt-5.5" | "gpt-5.4-mini" | "gpt-5.4-nano" | "grok-latest" | "claude-sonnet-4-6" | "gpt-5.4" | "grok-4-1-fast-reasoning" | "grok-4-1-fast-non-reasoning")[];
259
+ readonly COMBINED: readonly ("claude-opus-4-8" | "claude-haiku-4-5" | "gemini-3.1-pro-preview" | "gpt-5.5" | "gpt-5.4-mini" | "gpt-5.4-nano" | "grok-latest" | "claude-sonnet-4-6" | "gemini-3.1-flash-lite" | "gemini-3.5-flash" | "gpt-5.4" | "grok-4-1-fast-non-reasoning" | "grok-4-1-fast-reasoning")[];
205
260
  readonly LARGE: readonly ["claude-opus-4-8", "gemini-3.1-pro-preview", "gpt-5.5", "grok-latest"];
206
261
  readonly SMALL: readonly ["claude-sonnet-4-6", "gemini-3.5-flash", "gpt-5.4-mini", "grok-4-1-fast-reasoning"];
207
262
  readonly TINY: readonly ["claude-haiku-4-5", "gemini-3.1-flash-lite", "gpt-5.4-nano", "grok-4-1-fast-non-reasoning"];
@@ -46,8 +46,8 @@ const MODEL = {
46
46
  QWEN: "accounts/fireworks/models/qwen3p7-plus",
47
47
  },
48
48
  // Google
49
- GEMINI_FLASH: "gemini-3.5-flash",
50
- GEMINI_FLASH_LITE: "gemini-3.1-flash-lite",
49
+ GEMINI_FLASH: "gemini-3.6-flash",
50
+ GEMINI_FLASH_LITE: "gemini-3.5-flash-lite",
51
51
  GEMINI_PRO: "gemini-3.1-pro-preview",
52
52
  // OpenAI
53
53
  SOL: "gpt-5.6-sol",
@@ -68,6 +68,177 @@ const MODEL = {
68
68
  SONNET: "anthropic/claude-sonnet-5",
69
69
  },
70
70
  };
71
+ /**
72
+ * Standard list price per million tokens, keyed by literal model id (verified
73
+ * 2026-07-21). Keys are string literals rather than `MODEL.*` references so a
74
+ * model retired from the catalog keeps its price here: historic ids stay
75
+ * priceable after they leave `MODEL.*`, which is what makes replaying old
76
+ * usage records possible.
77
+ *
78
+ * Caveats the numbers cannot carry:
79
+ * - **Standard rate only.** Introductory, batch, flex, priority, fast-mode, and
80
+ * data-residency rates are excluded. Sonnet 5 is listed at its standard
81
+ * $3/$15, not the introductory rate.
82
+ * - **Cache writes are Anthropic-only.** Fireworks writes bill at the input
83
+ * rate. OpenAI and xAI discount reads automatically and publish no write
84
+ * premium. Google charges nothing to write an implicit cache; explicit
85
+ * caching bills storage per hour, a unit this table does not carry (and one
86
+ * `@jaypie/llm` does not wire).
87
+ * - **Short-context tier.** Long-prompt surcharges are not modeled: Gemini 3.1
88
+ * Pro doubles above 200K, Grok doubles at 200K, GPT-5.5 is 2x in / 1.5x out
89
+ * above 272K.
90
+ * - **Text rates.** Gemini prices audio input higher than text/image/video.
91
+ * - **Proxies are deliberately absent.** Bedrock (`PROVIDER.BEDROCK.*`) and
92
+ * OpenRouter (`MODEL.OPENROUTER.*`) resell many vendors and price per backend
93
+ * route, so no single rate is correct for a proxy id. Price those against the
94
+ * backend model, or against the proxy's own published rate.
95
+ *
96
+ * Unlisted ids return `undefined` — callers must handle a miss.
97
+ */
98
+ const COST = {
99
+ // Anthropic — https://platform.claude.com/docs/en/about-claude/pricing
100
+ "claude-3-5-haiku-20241022": {
101
+ cachedInputRead: 0.08,
102
+ cachedInputWrite: { "1h": 1.6, "5m": 1.0 },
103
+ input: 0.8,
104
+ output: 4.0,
105
+ },
106
+ "claude-fable-5": {
107
+ cachedInputRead: 1.0,
108
+ cachedInputWrite: { "1h": 20.0, "5m": 12.5 },
109
+ input: 10.0,
110
+ output: 50.0,
111
+ },
112
+ "claude-haiku-4-5": {
113
+ cachedInputRead: 0.1,
114
+ cachedInputWrite: { "1h": 2.0, "5m": 1.25 },
115
+ input: 1.0,
116
+ output: 5.0,
117
+ },
118
+ "claude-mythos-5": {
119
+ cachedInputRead: 1.0,
120
+ cachedInputWrite: { "1h": 20.0, "5m": 12.5 },
121
+ input: 10.0,
122
+ output: 50.0,
123
+ },
124
+ "claude-opus-4-1": {
125
+ cachedInputRead: 1.5,
126
+ cachedInputWrite: { "1h": 30.0, "5m": 18.75 },
127
+ input: 15.0,
128
+ output: 75.0,
129
+ },
130
+ "claude-opus-4-5": {
131
+ cachedInputRead: 0.5,
132
+ cachedInputWrite: { "1h": 10.0, "5m": 6.25 },
133
+ input: 5.0,
134
+ output: 25.0,
135
+ },
136
+ "claude-opus-4-6": {
137
+ cachedInputRead: 0.5,
138
+ cachedInputWrite: { "1h": 10.0, "5m": 6.25 },
139
+ input: 5.0,
140
+ output: 25.0,
141
+ },
142
+ "claude-opus-4-7": {
143
+ cachedInputRead: 0.5,
144
+ cachedInputWrite: { "1h": 10.0, "5m": 6.25 },
145
+ input: 5.0,
146
+ output: 25.0,
147
+ },
148
+ "claude-opus-4-8": {
149
+ cachedInputRead: 0.5,
150
+ cachedInputWrite: { "1h": 10.0, "5m": 6.25 },
151
+ input: 5.0,
152
+ output: 25.0,
153
+ },
154
+ "claude-sonnet-4-20250514": {
155
+ cachedInputRead: 0.3,
156
+ cachedInputWrite: { "1h": 6.0, "5m": 3.75 },
157
+ input: 3.0,
158
+ output: 15.0,
159
+ },
160
+ "claude-sonnet-4-5": {
161
+ cachedInputRead: 0.3,
162
+ cachedInputWrite: { "1h": 6.0, "5m": 3.75 },
163
+ input: 3.0,
164
+ output: 15.0,
165
+ },
166
+ "claude-sonnet-4-6": {
167
+ cachedInputRead: 0.3,
168
+ cachedInputWrite: { "1h": 6.0, "5m": 3.75 },
169
+ input: 3.0,
170
+ output: 15.0,
171
+ },
172
+ "claude-sonnet-5": {
173
+ cachedInputRead: 0.3,
174
+ cachedInputWrite: { "1h": 6.0, "5m": 3.75 },
175
+ input: 3.0,
176
+ output: 15.0,
177
+ },
178
+ // Fireworks — https://docs.fireworks.ai/serverless/pricing
179
+ "accounts/fireworks/models/deepseek-v4-pro": {
180
+ cachedInputRead: 0.145,
181
+ input: 1.74,
182
+ output: 3.48,
183
+ },
184
+ "accounts/fireworks/models/glm-5p2": {
185
+ cachedInputRead: 0.14,
186
+ input: 1.4,
187
+ output: 4.4,
188
+ },
189
+ "accounts/fireworks/models/kimi-k2p7-code": {
190
+ cachedInputRead: 0.19,
191
+ input: 0.95,
192
+ output: 4.0,
193
+ },
194
+ "accounts/fireworks/models/minimax-m2p7": {
195
+ cachedInputRead: 0.06,
196
+ input: 0.3,
197
+ output: 1.2,
198
+ },
199
+ "accounts/fireworks/models/qwen3p7-plus": {
200
+ cachedInputRead: 0.08,
201
+ input: 0.4,
202
+ output: 1.6,
203
+ },
204
+ // Google — https://ai.google.dev/gemini-api/docs/pricing
205
+ "gemini-2.5-flash": { cachedInputRead: 0.03, input: 0.3, output: 2.5 },
206
+ "gemini-3.1-flash-lite": {
207
+ cachedInputRead: 0.025,
208
+ input: 0.25,
209
+ output: 1.5,
210
+ },
211
+ "gemini-3.1-flash-lite-preview": {
212
+ cachedInputRead: 0.025,
213
+ input: 0.25,
214
+ output: 1.5,
215
+ },
216
+ "gemini-3.1-pro-preview": { cachedInputRead: 0.2, input: 2.0, output: 12.0 },
217
+ "gemini-3.5-flash": { cachedInputRead: 0.15, input: 1.5, output: 9.0 },
218
+ // Flash-Lite 3.5 has no separate cache-read rate on the standard tier
219
+ "gemini-3.5-flash-lite": { input: 0.3, output: 2.5 },
220
+ "gemini-3.6-flash": { cachedInputRead: 0.15, input: 1.5, output: 7.5 },
221
+ // OpenAI — https://developers.openai.com/api/docs/pricing
222
+ "gpt-5.4": { cachedInputRead: 0.25, input: 2.5, output: 15.0 },
223
+ "gpt-5.4-mini": { cachedInputRead: 0.075, input: 0.75, output: 4.5 },
224
+ "gpt-5.4-nano": { cachedInputRead: 0.02, input: 0.2, output: 1.25 },
225
+ "gpt-5.5": { cachedInputRead: 0.5, input: 5.0, output: 30.0 },
226
+ "gpt-5.6-luna": { cachedInputRead: 0.1, input: 1.0, output: 6.0 },
227
+ "gpt-5.6-sol": { cachedInputRead: 0.5, input: 5.0, output: 30.0 },
228
+ "gpt-5.6-terra": { cachedInputRead: 0.25, input: 2.5, output: 15.0 },
229
+ // xAI — https://docs.x.ai/docs/models ("grok-latest" aliases grok-4.3-latest)
230
+ "grok-4-1-fast-non-reasoning": {
231
+ cachedInputRead: 0.05,
232
+ input: 0.2,
233
+ output: 0.5,
234
+ },
235
+ "grok-4-1-fast-reasoning": {
236
+ cachedInputRead: 0.05,
237
+ input: 0.2,
238
+ output: 0.5,
239
+ },
240
+ "grok-latest": { cachedInputRead: 0.2, input: 1.25, output: 2.5 },
241
+ };
71
242
  const GOOGLE_PROVIDER = {
72
243
  // https://ai.google.dev/gemini-api/docs/models
73
244
  DEFAULT: MODEL.GEMINI_FLASH,
@@ -273,6 +444,7 @@ const ALL = {
273
444
  var constants = /*#__PURE__*/Object.freeze({
274
445
  __proto__: null,
275
446
  ALL: ALL,
447
+ COST: COST,
276
448
  DEFAULT: DEFAULT,
277
449
  EFFORT: EFFORT,
278
450
  MODEL: MODEL,
@@ -2999,13 +3171,16 @@ function isTemperatureDeprecationError$3(error) {
2999
3171
  const msg = error?.message ?? "";
3000
3172
  return /temperature.*deprecated|deprecated.*temperature/i.test(msg);
3001
3173
  }
3174
+ /** Exported for tests; not part of the package's public surface. */
3002
3175
  function isCachePointUnsupportedError(error) {
3003
3176
  const name = error?.constructor?.name ?? "";
3004
3177
  const msg = error?.message ?? "";
3005
3178
  // A model that cannot cache rejects the cachePoint block with a
3006
- // ValidationException naming caching / cachePoint.
3007
- return (/ValidationException|invalid|not support/i.test(name + " " + msg) &&
3008
- /cachePoint|cache_point|prompt caching|caching/i.test(msg));
3179
+ // ValidationException naming caching / cachePoint. Bedrock words this as
3180
+ // "You invoked an unsupported model or your request did not allow prompt
3181
+ // caching" — "unsupported" is one word, so it must be matched separately
3182
+ // from "not support".
3183
+ return (/ValidationException|invalid|not support|unsupported/i.test(name + " " + msg) && /cachePoint|cache_point|prompt caching|caching/i.test(msg));
3009
3184
  }
3010
3185
  function extractJson(text) {
3011
3186
  // Try direct parse first