modelmix 4.7.4 → 5.0.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/index.d.ts CHANGED
@@ -10,6 +10,20 @@ export type DebugLevel = 0 | 1 | 2 | 3 | 4;
10
10
  /** Unified effort: -1 = adaptive, 0–100 = intensity. */
11
11
  export type EffortValue = number;
12
12
 
13
+ export interface PromptCacheOptions {
14
+ mode?: 'implicit' | 'explicit';
15
+ ttl?: '30m';
16
+ }
17
+
18
+ export interface CacheBreakpoint {
19
+ breakpoint: true;
20
+ }
21
+
22
+ export interface AnthropicCacheControl {
23
+ type: 'ephemeral';
24
+ ttl?: '5m' | '1h';
25
+ }
26
+
13
27
  export interface BottleneckConfig {
14
28
  maxConcurrent?: number;
15
29
  minTime?: number;
@@ -35,6 +49,13 @@ export interface ModelMixOptions {
35
49
  model?: string;
36
50
  messages?: ChatMessage[];
37
51
  response_format?: { type: string; [key: string]: unknown };
52
+ prompt_cache_key?: string;
53
+ /** OpenAI models before GPT-5.6. GPT-5.6 uses prompt_cache_options.ttl. */
54
+ prompt_cache_retention?: string;
55
+ /** GPT-5.6 Responses API prompt caching controls. */
56
+ prompt_cache_options?: PromptCacheOptions;
57
+ /** Anthropic automatic caching, or the policy used by neutral explicit breakpoints. */
58
+ cache_control?: AnthropicCacheControl;
38
59
  [key: string]: unknown;
39
60
  }
40
61
 
@@ -49,7 +70,7 @@ export interface ModelMixConfig {
49
70
  roundRobin?: boolean;
50
71
  /** Unified effort (-1 adaptive, or 0–100). Not a native provider field. */
51
72
  effort?: EffortValue | null;
52
- replace?: Record<string, string>;
73
+ templateData?: Record<string, unknown>;
53
74
  schema?: Record<string, unknown>;
54
75
  [key: string]: unknown;
55
76
  }
@@ -82,11 +103,15 @@ export interface ModelAttachArgs {
82
103
 
83
104
  export interface RoleOptions {
84
105
  role?: MessageRole;
106
+ /** Provider-neutral explicit cache breakpoint, translated by each adapter. */
107
+ cache?: CacheBreakpoint;
85
108
  }
86
109
 
87
110
  export interface TextContentPart {
88
111
  type: 'text';
89
112
  text: string;
113
+ cache?: CacheBreakpoint;
114
+ cache_control?: AnthropicCacheControl;
90
115
  }
91
116
 
92
117
  export interface ImageContentPart {
@@ -96,6 +121,8 @@ export interface ImageContentPart {
96
121
  media_type?: string;
97
122
  data: string | Buffer;
98
123
  };
124
+ cache?: CacheBreakpoint;
125
+ cache_control?: AnthropicCacheControl;
99
126
  }
100
127
 
101
128
  export type ContentPart = TextContentPart | ImageContentPart | Record<string, unknown>;
@@ -121,12 +148,34 @@ export interface ToolCall {
121
148
  };
122
149
  }
123
150
 
151
+ export interface TokenCostBreakdown {
152
+ uncachedInput: number;
153
+ cachedInput: number;
154
+ cacheWrite: number;
155
+ cacheWrite5m: number;
156
+ cacheWrite1h: number;
157
+ output: number;
158
+ total: number;
159
+ }
160
+
124
161
  export interface TokenUsage {
125
162
  input: number;
126
163
  output: number;
127
164
  total: number;
128
165
  cached: number;
129
- cost?: number | null;
166
+ cacheWrite: number;
167
+ cacheWrite5m: number;
168
+ cacheWrite1h: number;
169
+ uncachedInput: number;
170
+ cacheHitRate: number;
171
+ /** USD avoided versus billing cache reads at the uncached input rate. */
172
+ cacheSavings: number;
173
+ /** Extra USD paid for cache writes versus ordinary uncached input. */
174
+ cacheWritePremium: number;
175
+ /** Full future cache hits needed to recover the current write premium. */
176
+ breakEvenHits: number;
177
+ cost: number;
178
+ costBreakdown: TokenCostBreakdown;
130
179
  speed?: number;
131
180
  }
132
181
 
@@ -244,9 +293,51 @@ export declare class ModelMix {
244
293
  static truncate(str: string, maxLen?: number): string;
245
294
  static calculateCost(
246
295
  modelKey: string,
247
- tokens: { input: number; output: number }
296
+ tokens: {
297
+ input: number;
298
+ output: number;
299
+ total?: number;
300
+ cached?: number;
301
+ cacheWrite?: number;
302
+ cacheWrite5m?: number;
303
+ cacheWrite1h?: number;
304
+ }
248
305
  ): number | null;
306
+ static calculateCostBreakdown(
307
+ modelKey: string,
308
+ tokens: {
309
+ input: number;
310
+ output: number;
311
+ total?: number;
312
+ cached?: number;
313
+ cacheWrite?: number;
314
+ cacheWrite5m?: number;
315
+ cacheWrite1h?: number;
316
+ }
317
+ ): TokenCostBreakdown;
318
+ static calculateCacheMetrics(
319
+ modelKey: string,
320
+ tokens: {
321
+ input: number;
322
+ output: number;
323
+ total?: number;
324
+ cached?: number;
325
+ cacheWrite?: number;
326
+ cacheWrite5m?: number;
327
+ cacheWrite1h?: number;
328
+ }
329
+ ): Pick<TokenUsage, 'cacheSavings' | 'cacheWritePremium' | 'breakEvenHits'>;
330
+ static normalizeTokenUsage(tokens?: {
331
+ input?: number;
332
+ output?: number;
333
+ total?: number;
334
+ cached?: number;
335
+ cacheWrite?: number;
336
+ cacheWrite5m?: number;
337
+ cacheWrite1h?: number;
338
+ }): TokenUsage;
249
339
  static extractCacheTokens(usage?: Record<string, unknown>): number;
340
+ static extractCacheWriteTokens(usage?: Record<string, unknown>): number;
250
341
  static formatInputSummary(
251
342
  messages: ChatMessage[],
252
343
  system: string,
@@ -256,7 +347,8 @@ export declare class ModelMix {
256
347
  static hasToolInteraction(message: ChatMessage | null | undefined): boolean;
257
348
 
258
349
  new(setup?: ModelMixSetup): ModelMix;
259
- replace(keyValues: Record<string, string>): this;
350
+ assign(keyValues: Record<string, unknown>): this;
351
+ assignKey(key: string, value: unknown): this;
260
352
  effort(value: EffortValue): this;
261
353
  attach(key: string, provider: MixCustom): this;
262
354
 
@@ -285,11 +377,14 @@ export declare class ModelMix {
285
377
  gptOss(args?: ModelAttachArgs): this;
286
378
 
287
379
  // Anthropic
380
+ fable50(args?: ModelAttachArgs): this;
288
381
  fable5(args?: ModelAttachArgs): this;
382
+ opus50(args?: ModelAttachArgs): this;
289
383
  opus5(args?: ModelAttachArgs): this;
290
384
  opus48(args?: ModelAttachArgs): this;
291
385
  opus47(args?: ModelAttachArgs): this;
292
386
  opus46(args?: ModelAttachArgs): this;
387
+ sonnet50(args?: ModelAttachArgs): this;
293
388
  sonnet5(args?: ModelAttachArgs): this;
294
389
  sonnet46(args?: ModelAttachArgs): this;
295
390
  sonnet45(args?: ModelAttachArgs): this;
@@ -357,9 +452,8 @@ export declare class ModelMix {
357
452
  raw(): Promise<ModelMixResult>;
358
453
  stream(callback: StreamCallback): Promise<ModelMixResult>;
359
454
 
360
- replaceKeyFromFile(key: string, filePath: string): this;
455
+ assignKeyFromFile(key: string, filePath: string): this;
361
456
  groupByRoles(messages: ChatMessage[]): ChatMessage[];
362
- applyTemplate(): void;
363
457
  prepareMessages(): Promise<void>;
364
458
  readFile(filePath: string, options?: { encoding?: BufferEncoding | null }): string | Buffer;
365
459
  execute(args?: CreateArgs): Promise<ModelMixResult>;
@@ -386,6 +480,7 @@ export declare class MixCustom {
386
480
  getDefaultConfig(customConfig?: Record<string, unknown>): Record<string, unknown>;
387
481
  getDefaultHeaders(customHeaders?: Record<string, string>): Record<string, string>;
388
482
  convertMessages(messages: ChatMessage[], config?: ModelMixConfig): ChatMessage[];
483
+ sanitizeCacheOptions(options: ModelMixOptions): void;
389
484
 
390
485
  static stripContentTypeHeader(headers?: Record<string, string>): Record<string, string>;
391
486
  static createMultipartFormData(args?: {
@@ -402,16 +497,11 @@ export declare class MixCustom {
402
497
  static extractTokens(data: unknown): TokenUsage;
403
498
 
404
499
  create(args?: CreateArgs): Promise<ModelMixResult>;
405
- handleError(
406
- error: unknown,
407
- context: CreateArgs
408
- ): {
500
+ handleError(error: unknown): {
409
501
  message: string;
410
502
  statusCode: number | null;
411
503
  details: unknown;
412
504
  stack?: string;
413
- config?: ModelMixConfig;
414
- options?: ModelMixOptions;
415
505
  };
416
506
  processStream(response: { data: NodeJS.ReadableStream }): Promise<ModelMixResult>;
417
507
  extractDelta(data: unknown): string;