modelmix 4.7.2 → 5.0.0

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
+ replace?: 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,7 @@ 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
+ replace(keyValues: Record<string, unknown>): this;
260
351
  effort(value: EffortValue): this;
261
352
  attach(key: string, provider: MixCustom): this;
262
353
 
@@ -285,11 +376,14 @@ export declare class ModelMix {
285
376
  gptOss(args?: ModelAttachArgs): this;
286
377
 
287
378
  // Anthropic
379
+ fable50(args?: ModelAttachArgs): this;
288
380
  fable5(args?: ModelAttachArgs): this;
381
+ opus50(args?: ModelAttachArgs): this;
289
382
  opus5(args?: ModelAttachArgs): this;
290
383
  opus48(args?: ModelAttachArgs): this;
291
384
  opus47(args?: ModelAttachArgs): this;
292
385
  opus46(args?: ModelAttachArgs): this;
386
+ sonnet50(args?: ModelAttachArgs): this;
293
387
  sonnet5(args?: ModelAttachArgs): this;
294
388
  sonnet46(args?: ModelAttachArgs): this;
295
389
  sonnet45(args?: ModelAttachArgs): this;
@@ -302,6 +396,7 @@ export declare class ModelMix {
302
396
  gemini3flash(args?: ModelAttachArgs): this;
303
397
  gemini36flash(args?: ModelAttachArgs): this;
304
398
  gemini35flash(args?: ModelAttachArgs): this;
399
+ gemini35flashLite(args?: ModelAttachArgs): this;
305
400
  gemini31flashLite(args?: ModelAttachArgs): this;
306
401
  gemini25pro(args?: ModelAttachArgs): this;
307
402
 
@@ -358,7 +453,6 @@ export declare class ModelMix {
358
453
 
359
454
  replaceKeyFromFile(key: string, filePath: string): this;
360
455
  groupByRoles(messages: ChatMessage[]): ChatMessage[];
361
- applyTemplate(): void;
362
456
  prepareMessages(): Promise<void>;
363
457
  readFile(filePath: string, options?: { encoding?: BufferEncoding | null }): string | Buffer;
364
458
  execute(args?: CreateArgs): Promise<ModelMixResult>;
@@ -385,6 +479,7 @@ export declare class MixCustom {
385
479
  getDefaultConfig(customConfig?: Record<string, unknown>): Record<string, unknown>;
386
480
  getDefaultHeaders(customHeaders?: Record<string, string>): Record<string, string>;
387
481
  convertMessages(messages: ChatMessage[], config?: ModelMixConfig): ChatMessage[];
482
+ sanitizeCacheOptions(options: ModelMixOptions): void;
388
483
 
389
484
  static stripContentTypeHeader(headers?: Record<string, string>): Record<string, string>;
390
485
  static createMultipartFormData(args?: {
@@ -401,16 +496,11 @@ export declare class MixCustom {
401
496
  static extractTokens(data: unknown): TokenUsage;
402
497
 
403
498
  create(args?: CreateArgs): Promise<ModelMixResult>;
404
- handleError(
405
- error: unknown,
406
- context: CreateArgs
407
- ): {
499
+ handleError(error: unknown): {
408
500
  message: string;
409
501
  statusCode: number | null;
410
502
  details: unknown;
411
503
  stack?: string;
412
- config?: ModelMixConfig;
413
- options?: ModelMixOptions;
414
504
  };
415
505
  processStream(response: { data: NodeJS.ReadableStream }): Promise<ModelMixResult>;
416
506
  extractDelta(data: unknown): string;