@jaypie/llm 1.3.14 → 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.
@@ -52,6 +52,61 @@ declare const MODEL: {
52
52
  SONNET: string;
53
53
  };
54
54
  };
55
+ /** Price of one million tokens, in US dollars. */
56
+ interface LlmModelCost {
57
+ /**
58
+ * Cache-read (cached input) tokens. Omitted when the provider does not price
59
+ * cache reads separately from uncached input.
60
+ */
61
+ cachedInputRead?: number;
62
+ /**
63
+ * Cache-write tokens. A scalar when the rate does not vary by TTL; keyed by
64
+ * the same `"5m"` / `"1h"` literals as `LlmCache` when it does, so a cost
65
+ * calculation reads the TTL straight off `OperateRequest.cache`. Omitted
66
+ * means cache writes bill at the `input` rate.
67
+ */
68
+ cachedInputWrite?: number | {
69
+ "1h": number;
70
+ "5m": number;
71
+ };
72
+ /** Uncached input tokens. */
73
+ input: number;
74
+ /** Output tokens. */
75
+ output: number;
76
+ /**
77
+ * Reasoning tokens, when billed at a rate other than `output`. Omitted means
78
+ * reasoning bills as output, which is true of every provider listed here.
79
+ */
80
+ reasoning?: number;
81
+ }
82
+ /**
83
+ * Standard list price per million tokens, keyed by literal model id (verified
84
+ * 2026-07-21). Keys are string literals rather than `MODEL.*` references so a
85
+ * model retired from the catalog keeps its price here: historic ids stay
86
+ * priceable after they leave `MODEL.*`, which is what makes replaying old
87
+ * usage records possible.
88
+ *
89
+ * Caveats the numbers cannot carry:
90
+ * - **Standard rate only.** Introductory, batch, flex, priority, fast-mode, and
91
+ * data-residency rates are excluded. Sonnet 5 is listed at its standard
92
+ * $3/$15, not the introductory rate.
93
+ * - **Cache writes are Anthropic-only.** Fireworks writes bill at the input
94
+ * rate. OpenAI and xAI discount reads automatically and publish no write
95
+ * premium. Google charges nothing to write an implicit cache; explicit
96
+ * caching bills storage per hour, a unit this table does not carry (and one
97
+ * `@jaypie/llm` does not wire).
98
+ * - **Short-context tier.** Long-prompt surcharges are not modeled: Gemini 3.1
99
+ * Pro doubles above 200K, Grok doubles at 200K, GPT-5.5 is 2x in / 1.5x out
100
+ * above 272K.
101
+ * - **Text rates.** Gemini prices audio input higher than text/image/video.
102
+ * - **Proxies are deliberately absent.** Bedrock (`PROVIDER.BEDROCK.*`) and
103
+ * OpenRouter (`MODEL.OPENROUTER.*`) resell many vendors and price per backend
104
+ * route, so no single rate is correct for a proxy id. Price those against the
105
+ * backend model, or against the proxy's own published rate.
106
+ *
107
+ * Unlisted ids return `undefined` — callers must handle a miss.
108
+ */
109
+ declare const COST: Record<string, LlmModelCost>;
55
110
  declare const PROVIDER: {
56
111
  readonly BEDROCK: {
57
112
  readonly DEFAULT: "amazon.nova-pro-v1:0";
@@ -206,22 +261,24 @@ declare const DEFAULT: {
206
261
  */
207
262
  declare const ALL: {
208
263
  readonly BASE: readonly ["claude-sonnet-4-6", "gemini-3.1-pro-preview", "gpt-5.4", "grok-latest"];
209
- 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")[];
264
+ 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.5-flash" | "gemini-3.1-flash-lite" | "gpt-5.4" | "grok-4-1-fast-reasoning" | "grok-4-1-fast-non-reasoning")[];
210
265
  readonly LARGE: readonly ["claude-opus-4-8", "gemini-3.1-pro-preview", "gpt-5.5", "grok-latest"];
211
266
  readonly SMALL: readonly ["claude-sonnet-4-6", "gemini-3.5-flash", "gpt-5.4-mini", "grok-4-1-fast-reasoning"];
212
267
  readonly TINY: readonly ["claude-haiku-4-5", "gemini-3.1-flash-lite", "gpt-5.4-nano", "grok-4-1-fast-non-reasoning"];
213
268
  };
214
269
 
215
270
  declare const constants_ALL: typeof ALL;
271
+ declare const constants_COST: typeof COST;
216
272
  declare const constants_DEFAULT: typeof DEFAULT;
217
273
  declare const constants_EFFORT: typeof EFFORT;
218
274
  type constants_LlmEffort = LlmEffort;
275
+ type constants_LlmModelCost = LlmModelCost;
219
276
  type constants_LlmProviderName = LlmProviderName;
220
277
  declare const constants_MODEL: typeof MODEL;
221
278
  declare const constants_PROVIDER: typeof PROVIDER;
222
279
  declare namespace constants {
223
- export { constants_ALL as ALL, constants_DEFAULT as DEFAULT, constants_EFFORT as EFFORT, constants_MODEL as MODEL, constants_PROVIDER as PROVIDER };
224
- export type { constants_LlmEffort as LlmEffort, constants_LlmProviderName as LlmProviderName };
280
+ export { constants_ALL as ALL, constants_COST as COST, constants_DEFAULT as DEFAULT, constants_EFFORT as EFFORT, constants_MODEL as MODEL, constants_PROVIDER as PROVIDER };
281
+ export type { constants_LlmEffort as LlmEffort, constants_LlmModelCost as LlmModelCost, constants_LlmProviderName as LlmProviderName };
225
282
  }
226
283
 
227
284
  interface LlmTool {
@@ -530,6 +587,7 @@ type LlmProgressCallback = (event: LlmProgressEvent) => unknown | Promise<unknow
530
587
  * `input` is the raw, pre-interpolation input with multimodal parts preserved.
531
588
  */
532
589
  interface LlmExchangeRequest {
590
+ cache?: LlmCache;
533
591
  data?: NaturalMap;
534
592
  effort?: LlmEffort;
535
593
  explain?: boolean;
@@ -600,7 +658,21 @@ interface LlmExchangeEnvelope {
600
658
  timing: LlmExchangeTiming;
601
659
  }
602
660
  type LlmExchangeCallback = (envelope: LlmExchangeEnvelope) => unknown | Promise<unknown>;
661
+ /**
662
+ * Prompt-caching control for operate()/stream().
663
+ * - `true` / omitted → caching enabled at the default `"5m"` TTL
664
+ * - `false` / `0` → caching disabled
665
+ * - `"5m"` / `"1h"` → enabled at that TTL (TTL honored by Anthropic/OpenRouter;
666
+ * other providers ignore it and cache with their own defaults)
667
+ */
668
+ type LlmCache = boolean | 0 | "5m" | "1h";
603
669
  interface LlmOperateOptions {
670
+ /**
671
+ * Prompt caching for the stable request prefix (system prompt + tools).
672
+ * Enabled by default; pass `false`/`0` to opt out, or `"5m"`/`"1h"` to set
673
+ * the TTL. See {@link LlmCache}.
674
+ */
675
+ cache?: LlmCache;
604
676
  data?: NaturalMap;
605
677
  /**
606
678
  * Provider-neutral reasoning effort (lowest | low | medium | high | highest).
@@ -709,6 +781,10 @@ interface LlmUsageItem {
709
781
  output: number;
710
782
  reasoning: number;
711
783
  total: number;
784
+ /** Prompt-cache tokens served from cache this call (billed at ~0.1x input) */
785
+ cacheRead?: number;
786
+ /** Prompt-cache tokens written to cache this call (billed at ~1.25x input) */
787
+ cacheWrite?: number;
712
788
  provider?: string;
713
789
  model?: string;
714
790
  }
@@ -1023,4 +1099,4 @@ declare class XaiProvider implements LlmProvider {
1023
1099
  }
1024
1100
 
1025
1101
  export { BedrockProvider, ErrorCategory, FireworksProvider, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmError, LlmMessageRole, LlmMessageType, LlmProgressEventType, LlmQuotaError, LlmRateLimitError, LlmStreamChunkType, LlmTransientError, LlmUnrecoverableError, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
1026
- export type { LlmEffort, LlmErrorOptions, LlmExchangeCallback, LlmExchangeEnvelope, LlmExchangeRequest, LlmExchangeResolution, LlmExchangeResponse, LlmExchangeTiming, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
1102
+ export type { LlmCache, LlmEffort, LlmErrorOptions, LlmExchangeCallback, LlmExchangeEnvelope, LlmExchangeRequest, LlmExchangeResolution, LlmExchangeResponse, LlmExchangeTiming, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelCost, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
@@ -1,7 +1,7 @@
1
1
  export { default as Llm } from "./Llm.js";
2
2
  export * as LLM from "./constants.js";
3
- export type { LlmEffort } from "./constants.js";
4
- export type { LlmExchangeCallback, LlmExchangeEnvelope, LlmExchangeRequest, LlmExchangeResolution, LlmExchangeResponse, LlmExchangeTiming, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, } from "./types/LlmProvider.interface.js";
3
+ export type { LlmEffort, LlmModelCost } from "./constants.js";
4
+ export type { LlmCache, LlmExchangeCallback, LlmExchangeEnvelope, LlmExchangeRequest, LlmExchangeResolution, LlmExchangeResponse, LlmExchangeTiming, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, } from "./types/LlmProvider.interface.js";
5
5
  export { LlmMessageRole, LlmMessageType, LlmProgressEventType, } from "./types/LlmProvider.interface.js";
6
6
  export { isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, } from "./types/LlmOperateInput.guards.js";
7
7
  export type { LlmTool } from "./types/LlmTool.interface.js";
@@ -47,16 +47,24 @@ type BedrockRequest = Omit<ConverseCommandInput, "messages"> & {
47
47
  type AnnotatedBedrockResponse = ConverseCommandOutput & {
48
48
  __jaypieStructuredOutput?: boolean;
49
49
  };
50
+ /** Exported for tests; not part of the package's public surface. */
51
+ export declare function isCachePointUnsupportedError(error: unknown): boolean;
50
52
  export declare class BedrockAdapter extends BaseProviderAdapter {
51
53
  readonly name: "bedrock";
52
54
  readonly defaultModel: "amazon.nova-pro-v1:0";
53
55
  private _modelsFallbackToStructuredOutputTool;
54
56
  private _modelsWithoutTemperature;
57
+ private _modelsWithoutCachePoint;
58
+ private rememberModelRejectsCachePoint;
59
+ private supportsCachePoint;
55
60
  private rememberModelRejectsOutputConfig;
56
61
  private useFakeToolForStructuredOutput;
57
62
  private rememberModelRejectsTemperature;
58
63
  private supportsTemperature;
59
64
  buildRequest(request: OperateRequest): BedrockRequest;
65
+ /** Remove any cachePoint blocks so the request can be retried unsupported. */
66
+ private stripCachePoints;
67
+ private requestHasCachePoints;
60
68
  formatTools(toolkit: Toolkit): ProviderToolDefinition[];
61
69
  formatOutputSchema(schema: JsonObject | NaturalSchema | z.ZodType): JsonObject;
62
70
  executeRequest(client: unknown, request: unknown, signal?: AbortSignal): Promise<AnnotatedBedrockResponse>;
@@ -21,6 +21,11 @@ export declare class OpenAiAdapter extends BaseProviderAdapter {
21
21
  private supportsTemperature;
22
22
  /** Whether `reasoning.effort` may be sent for this model. Overridden by xAI. */
23
23
  protected supportsReasoningEffort(model: string): boolean;
24
+ /**
25
+ * Whether to emit `prompt_cache_key` (OpenAI Responses API). Overridable by
26
+ * OpenAI-compatible subclasses whose backend rejects the field.
27
+ */
28
+ protected supportsPromptCacheKey(): boolean;
24
29
  /** Translate a normalized effort to this provider's `reasoning.effort` value. */
25
30
  protected mapReasoningEffort(effort: LlmEffort, model: string): LlmEffortMapping;
26
31
  buildRequest(request: OperateRequest): unknown;
@@ -42,6 +42,13 @@ interface OpenRouterUsage {
42
42
  completionTokensDetails?: {
43
43
  reasoningTokens?: number;
44
44
  };
45
+ promptTokensDetails?: {
46
+ cachedTokens?: number;
47
+ cached_tokens?: number;
48
+ };
49
+ prompt_tokens_details?: {
50
+ cached_tokens?: number;
51
+ };
45
52
  }
46
53
  interface OpenRouterResponse {
47
54
  id: string;
@@ -95,6 +102,10 @@ interface OpenRouterRequest {
95
102
  type OpenRouterContentPart = {
96
103
  type: "text";
97
104
  text: string;
105
+ cache_control?: {
106
+ type: "ephemeral";
107
+ ttl?: "5m" | "1h";
108
+ };
98
109
  } | {
99
110
  type: "image_url";
100
111
  imageUrl: {
@@ -1,6 +1,6 @@
1
1
  import { JsonObject } from "@jaypie/types";
2
2
  import { type LlmEffort } from "../constants.js";
3
- import { LlmHistory, LlmMessageType, LlmOperateOptions, LlmUsageItem } from "../types/LlmProvider.interface.js";
3
+ import { LlmCache, LlmHistory, LlmMessageType, LlmOperateOptions, LlmUsageItem } from "../types/LlmProvider.interface.js";
4
4
  import { Toolkit } from "../tools/Toolkit.class.js";
5
5
  /**
6
6
  * Standardized tool call representation across providers
@@ -73,6 +73,11 @@ export interface OperateRequest {
73
73
  effort?: LlmEffort;
74
74
  /** Provider-specific options */
75
75
  providerOptions?: JsonObject;
76
+ /**
77
+ * Prompt-caching control for the stable prefix (system + tools). `true`/
78
+ * omitted = enabled@5m, `false`/`0` = disabled, `"5m"`/`"1h"` = enabled@ttl.
79
+ */
80
+ cache?: LlmCache;
76
81
  /** Whether the request will execute over a streaming transport */
77
82
  stream?: boolean;
78
83
  /** Sampling temperature (0-2 for most providers) */
@@ -2,10 +2,20 @@ import { JsonObject } from "@jaypie/types";
2
2
  import { LlmMessageRole } from "../../types/LlmProvider.interface.js";
3
3
  export declare const ROLE_MAP: Record<LlmMessageRole, string>;
4
4
  export declare namespace Anthropic {
5
+ interface CacheControlEphemeral {
6
+ type: "ephemeral";
7
+ ttl?: "5m" | "1h";
8
+ }
5
9
  interface TextBlock {
6
10
  type: "text";
7
11
  text: string;
8
12
  }
13
+ /** Top-level `system` block form that can carry a cache breakpoint */
14
+ interface SystemTextBlockParam {
15
+ type: "text";
16
+ text: string;
17
+ cache_control?: CacheControlEphemeral;
18
+ }
9
19
  interface ToolUseBlock {
10
20
  type: "tool_use";
11
21
  id: string;
@@ -63,17 +73,20 @@ export declare namespace Anthropic {
63
73
  description?: string;
64
74
  input_schema: Messages.Tool.InputSchema;
65
75
  type?: "custom";
76
+ cache_control?: CacheControlEphemeral;
66
77
  }
67
78
  interface Usage {
68
79
  input_tokens: number;
69
80
  output_tokens: number;
70
81
  thinking_tokens?: number;
82
+ cache_read_input_tokens?: number;
83
+ cache_creation_input_tokens?: number;
71
84
  }
72
85
  interface MessageCreateParams {
73
86
  model: string;
74
87
  messages: MessageParam[];
75
88
  max_tokens: number;
76
- system?: string;
89
+ system?: string | SystemTextBlockParam[];
77
90
  tools?: Tool[];
78
91
  tool_choice?: {
79
92
  type: "auto" | "any" | "tool";
@@ -217,6 +217,7 @@ export type LlmProgressCallback = (event: LlmProgressEvent) => unknown | Promise
217
217
  * `input` is the raw, pre-interpolation input with multimodal parts preserved.
218
218
  */
219
219
  export interface LlmExchangeRequest {
220
+ cache?: LlmCache;
220
221
  data?: NaturalMap;
221
222
  effort?: LlmEffort;
222
223
  explain?: boolean;
@@ -287,7 +288,21 @@ export interface LlmExchangeEnvelope {
287
288
  timing: LlmExchangeTiming;
288
289
  }
289
290
  export type LlmExchangeCallback = (envelope: LlmExchangeEnvelope) => unknown | Promise<unknown>;
291
+ /**
292
+ * Prompt-caching control for operate()/stream().
293
+ * - `true` / omitted → caching enabled at the default `"5m"` TTL
294
+ * - `false` / `0` → caching disabled
295
+ * - `"5m"` / `"1h"` → enabled at that TTL (TTL honored by Anthropic/OpenRouter;
296
+ * other providers ignore it and cache with their own defaults)
297
+ */
298
+ export type LlmCache = boolean | 0 | "5m" | "1h";
290
299
  export interface LlmOperateOptions {
300
+ /**
301
+ * Prompt caching for the stable request prefix (system prompt + tools).
302
+ * Enabled by default; pass `false`/`0` to opt out, or `"5m"`/`"1h"` to set
303
+ * the TTL. See {@link LlmCache}.
304
+ */
305
+ cache?: LlmCache;
291
306
  data?: NaturalMap;
292
307
  /**
293
308
  * Provider-neutral reasoning effort (lowest | low | medium | high | highest).
@@ -396,6 +411,10 @@ export interface LlmUsageItem {
396
411
  output: number;
397
412
  reasoning: number;
398
413
  total: number;
414
+ /** Prompt-cache tokens served from cache this call (billed at ~0.1x input) */
415
+ cacheRead?: number;
416
+ /** Prompt-cache tokens written to cache this call (billed at ~1.25x input) */
417
+ cacheWrite?: number;
399
418
  provider?: string;
400
419
  model?: string;
401
420
  }
@@ -0,0 +1,21 @@
1
+ import { type LlmCache } from "../types/LlmProvider.interface.js";
2
+ export declare const CACHE_TTL_DEFAULT: "5m";
3
+ export type CacheTtl = "5m" | "1h";
4
+ export interface ResolvedCache {
5
+ enabled: boolean;
6
+ ttl: CacheTtl;
7
+ }
8
+ /**
9
+ * Normalize the caller-facing `cache` option into a concrete decision.
10
+ * - `undefined` / `true` → enabled at the default TTL
11
+ * - `false` / `0` → disabled
12
+ * - `"5m"` / `"1h"` → enabled at that TTL
13
+ */
14
+ export declare function resolveCache(cache: LlmCache | undefined): ResolvedCache;
15
+ /**
16
+ * Deterministic short key for providers with automatic, prefix-based caching
17
+ * (e.g. OpenAI `prompt_cache_key`). Derived from the stable prefix so the same
18
+ * system prompt + tools + model always routes to the same cache. Dependency-
19
+ * free FNV-1a; not cryptographic.
20
+ */
21
+ export declare function promptCacheKey(seed: string): string;
@@ -1,3 +1,4 @@
1
+ export * from "./cacheControl.js";
1
2
  export * from "./determineModelProvider.js";
2
3
  export * from "./extractReasoning.js";
3
4
  export * from "./fillFormatArrays.js";
@@ -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"];
@@ -52,6 +52,61 @@ declare const MODEL: {
52
52
  SONNET: string;
53
53
  };
54
54
  };
55
+ /** Price of one million tokens, in US dollars. */
56
+ interface LlmModelCost {
57
+ /**
58
+ * Cache-read (cached input) tokens. Omitted when the provider does not price
59
+ * cache reads separately from uncached input.
60
+ */
61
+ cachedInputRead?: number;
62
+ /**
63
+ * Cache-write tokens. A scalar when the rate does not vary by TTL; keyed by
64
+ * the same `"5m"` / `"1h"` literals as `LlmCache` when it does, so a cost
65
+ * calculation reads the TTL straight off `OperateRequest.cache`. Omitted
66
+ * means cache writes bill at the `input` rate.
67
+ */
68
+ cachedInputWrite?: number | {
69
+ "1h": number;
70
+ "5m": number;
71
+ };
72
+ /** Uncached input tokens. */
73
+ input: number;
74
+ /** Output tokens. */
75
+ output: number;
76
+ /**
77
+ * Reasoning tokens, when billed at a rate other than `output`. Omitted means
78
+ * reasoning bills as output, which is true of every provider listed here.
79
+ */
80
+ reasoning?: number;
81
+ }
82
+ /**
83
+ * Standard list price per million tokens, keyed by literal model id (verified
84
+ * 2026-07-21). Keys are string literals rather than `MODEL.*` references so a
85
+ * model retired from the catalog keeps its price here: historic ids stay
86
+ * priceable after they leave `MODEL.*`, which is what makes replaying old
87
+ * usage records possible.
88
+ *
89
+ * Caveats the numbers cannot carry:
90
+ * - **Standard rate only.** Introductory, batch, flex, priority, fast-mode, and
91
+ * data-residency rates are excluded. Sonnet 5 is listed at its standard
92
+ * $3/$15, not the introductory rate.
93
+ * - **Cache writes are Anthropic-only.** Fireworks writes bill at the input
94
+ * rate. OpenAI and xAI discount reads automatically and publish no write
95
+ * premium. Google charges nothing to write an implicit cache; explicit
96
+ * caching bills storage per hour, a unit this table does not carry (and one
97
+ * `@jaypie/llm` does not wire).
98
+ * - **Short-context tier.** Long-prompt surcharges are not modeled: Gemini 3.1
99
+ * Pro doubles above 200K, Grok doubles at 200K, GPT-5.5 is 2x in / 1.5x out
100
+ * above 272K.
101
+ * - **Text rates.** Gemini prices audio input higher than text/image/video.
102
+ * - **Proxies are deliberately absent.** Bedrock (`PROVIDER.BEDROCK.*`) and
103
+ * OpenRouter (`MODEL.OPENROUTER.*`) resell many vendors and price per backend
104
+ * route, so no single rate is correct for a proxy id. Price those against the
105
+ * backend model, or against the proxy's own published rate.
106
+ *
107
+ * Unlisted ids return `undefined` — callers must handle a miss.
108
+ */
109
+ declare const COST: Record<string, LlmModelCost>;
55
110
  declare const PROVIDER: {
56
111
  readonly BEDROCK: {
57
112
  readonly DEFAULT: "amazon.nova-pro-v1:0";
@@ -206,22 +261,24 @@ declare const DEFAULT: {
206
261
  */
207
262
  declare const ALL: {
208
263
  readonly BASE: readonly ["claude-sonnet-4-6", "gemini-3.1-pro-preview", "gpt-5.4", "grok-latest"];
209
- 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")[];
264
+ 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.5-flash" | "gemini-3.1-flash-lite" | "gpt-5.4" | "grok-4-1-fast-reasoning" | "grok-4-1-fast-non-reasoning")[];
210
265
  readonly LARGE: readonly ["claude-opus-4-8", "gemini-3.1-pro-preview", "gpt-5.5", "grok-latest"];
211
266
  readonly SMALL: readonly ["claude-sonnet-4-6", "gemini-3.5-flash", "gpt-5.4-mini", "grok-4-1-fast-reasoning"];
212
267
  readonly TINY: readonly ["claude-haiku-4-5", "gemini-3.1-flash-lite", "gpt-5.4-nano", "grok-4-1-fast-non-reasoning"];
213
268
  };
214
269
 
215
270
  declare const constants_ALL: typeof ALL;
271
+ declare const constants_COST: typeof COST;
216
272
  declare const constants_DEFAULT: typeof DEFAULT;
217
273
  declare const constants_EFFORT: typeof EFFORT;
218
274
  type constants_LlmEffort = LlmEffort;
275
+ type constants_LlmModelCost = LlmModelCost;
219
276
  type constants_LlmProviderName = LlmProviderName;
220
277
  declare const constants_MODEL: typeof MODEL;
221
278
  declare const constants_PROVIDER: typeof PROVIDER;
222
279
  declare namespace constants {
223
- export { constants_ALL as ALL, constants_DEFAULT as DEFAULT, constants_EFFORT as EFFORT, constants_MODEL as MODEL, constants_PROVIDER as PROVIDER };
224
- export type { constants_LlmEffort as LlmEffort, constants_LlmProviderName as LlmProviderName };
280
+ export { constants_ALL as ALL, constants_COST as COST, constants_DEFAULT as DEFAULT, constants_EFFORT as EFFORT, constants_MODEL as MODEL, constants_PROVIDER as PROVIDER };
281
+ export type { constants_LlmEffort as LlmEffort, constants_LlmModelCost as LlmModelCost, constants_LlmProviderName as LlmProviderName };
225
282
  }
226
283
 
227
284
  interface LlmTool {
@@ -530,6 +587,7 @@ type LlmProgressCallback = (event: LlmProgressEvent) => unknown | Promise<unknow
530
587
  * `input` is the raw, pre-interpolation input with multimodal parts preserved.
531
588
  */
532
589
  interface LlmExchangeRequest {
590
+ cache?: LlmCache;
533
591
  data?: NaturalMap;
534
592
  effort?: LlmEffort;
535
593
  explain?: boolean;
@@ -600,7 +658,21 @@ interface LlmExchangeEnvelope {
600
658
  timing: LlmExchangeTiming;
601
659
  }
602
660
  type LlmExchangeCallback = (envelope: LlmExchangeEnvelope) => unknown | Promise<unknown>;
661
+ /**
662
+ * Prompt-caching control for operate()/stream().
663
+ * - `true` / omitted → caching enabled at the default `"5m"` TTL
664
+ * - `false` / `0` → caching disabled
665
+ * - `"5m"` / `"1h"` → enabled at that TTL (TTL honored by Anthropic/OpenRouter;
666
+ * other providers ignore it and cache with their own defaults)
667
+ */
668
+ type LlmCache = boolean | 0 | "5m" | "1h";
603
669
  interface LlmOperateOptions {
670
+ /**
671
+ * Prompt caching for the stable request prefix (system prompt + tools).
672
+ * Enabled by default; pass `false`/`0` to opt out, or `"5m"`/`"1h"` to set
673
+ * the TTL. See {@link LlmCache}.
674
+ */
675
+ cache?: LlmCache;
604
676
  data?: NaturalMap;
605
677
  /**
606
678
  * Provider-neutral reasoning effort (lowest | low | medium | high | highest).
@@ -709,6 +781,10 @@ interface LlmUsageItem {
709
781
  output: number;
710
782
  reasoning: number;
711
783
  total: number;
784
+ /** Prompt-cache tokens served from cache this call (billed at ~0.1x input) */
785
+ cacheRead?: number;
786
+ /** Prompt-cache tokens written to cache this call (billed at ~1.25x input) */
787
+ cacheWrite?: number;
712
788
  provider?: string;
713
789
  model?: string;
714
790
  }
@@ -1023,4 +1099,4 @@ declare class XaiProvider implements LlmProvider {
1023
1099
  }
1024
1100
 
1025
1101
  export { BedrockProvider, ErrorCategory, FireworksProvider, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmError, LlmMessageRole, LlmMessageType, LlmProgressEventType, LlmQuotaError, LlmRateLimitError, LlmStreamChunkType, LlmTransientError, LlmUnrecoverableError, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
1026
- export type { LlmEffort, LlmErrorOptions, LlmExchangeCallback, LlmExchangeEnvelope, LlmExchangeRequest, LlmExchangeResolution, LlmExchangeResponse, LlmExchangeTiming, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
1102
+ export type { LlmCache, LlmEffort, LlmErrorOptions, LlmExchangeCallback, LlmExchangeEnvelope, LlmExchangeRequest, LlmExchangeResolution, LlmExchangeResponse, LlmExchangeTiming, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelCost, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };