@jambonz/llm 0.6.4 → 0.6.5

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/dist/index.js CHANGED
@@ -86,6 +86,9 @@ async function* streamFromOpenAI(client, req, options) {
86
86
  if (req.cacheKey && options.includeCacheKey !== false) {
87
87
  body.prompt_cache_key = req.cacheKey;
88
88
  }
89
+ if (req.cacheKey && options.openRouterAutoCache && /^~?anthropic\//.test(req.model)) {
90
+ body.cache_control = { type: "ephemeral" };
91
+ }
89
92
  const effectiveMaxTokens = req.maxTokens ?? options.defaultMaxTokens;
90
93
  if (effectiveMaxTokens !== void 0) {
91
94
  const param = options.tokensParam ?? (needsMaxCompletionTokens(req.model) ? "max_completion_tokens" : "max_tokens");
@@ -510,10 +513,13 @@ var OpenAIAdapter = class {
510
513
  vendor = openAIManifest.vendor;
511
514
  acceptedAuth = ["apiKey"];
512
515
  client;
516
+ /** baseURL is OpenRouter: enables its automatic prompt caching for Anthropic models. */
517
+ isOpenRouter = false;
513
518
  init(auth, client) {
514
519
  if (!auth.apiKey) {
515
520
  throw new Error("OpenAIAdapter: apiKey is required");
516
521
  }
522
+ this.isOpenRouter = /(^|\/\/|\.)openrouter\.ai(\/|:|$)/i.test(auth.baseURL ?? "");
517
523
  this.client = new OpenAI({
518
524
  apiKey: auth.apiKey,
519
525
  ...auth.baseURL ? { baseURL: auth.baseURL } : {},
@@ -525,7 +531,8 @@ var OpenAIAdapter = class {
525
531
  return streamFromOpenAI(this.ensureClient(), req, {
526
532
  knownModels: this.knownModels(),
527
533
  vendorMetadataExtractor: OPENAI_METADATA_EXTRACTOR,
528
- includeCacheKey: this.forwardCacheKey()
534
+ includeCacheKey: this.forwardCacheKey(),
535
+ openRouterAutoCache: this.isOpenRouter
529
536
  });
530
537
  }
531
538
  appendAssistantToolCall(history, toolCalls, assistantText) {