@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.
@@ -118,6 +118,9 @@ async function* streamFromOpenAI(client, req, options) {
118
118
  if (req.cacheKey && options.includeCacheKey !== false) {
119
119
  body.prompt_cache_key = req.cacheKey;
120
120
  }
121
+ if (req.cacheKey && options.openRouterAutoCache && /^~?anthropic\//.test(req.model)) {
122
+ body.cache_control = { type: "ephemeral" };
123
+ }
121
124
  const effectiveMaxTokens = req.maxTokens ?? options.defaultMaxTokens;
122
125
  if (effectiveMaxTokens !== void 0) {
123
126
  const param = options.tokensParam ?? (needsMaxCompletionTokens(req.model) ? "max_completion_tokens" : "max_tokens");
@@ -542,10 +545,13 @@ var OpenAIAdapter = class {
542
545
  vendor = openAIManifest.vendor;
543
546
  acceptedAuth = ["apiKey"];
544
547
  client;
548
+ /** baseURL is OpenRouter: enables its automatic prompt caching for Anthropic models. */
549
+ isOpenRouter = false;
545
550
  init(auth, client) {
546
551
  if (!auth.apiKey) {
547
552
  throw new Error("OpenAIAdapter: apiKey is required");
548
553
  }
554
+ this.isOpenRouter = /(^|\/\/|\.)openrouter\.ai(\/|:|$)/i.test(auth.baseURL ?? "");
549
555
  this.client = new import_openai.default({
550
556
  apiKey: auth.apiKey,
551
557
  ...auth.baseURL ? { baseURL: auth.baseURL } : {},
@@ -557,7 +563,8 @@ var OpenAIAdapter = class {
557
563
  return streamFromOpenAI(this.ensureClient(), req, {
558
564
  knownModels: this.knownModels(),
559
565
  vendorMetadataExtractor: OPENAI_METADATA_EXTRACTOR,
560
- includeCacheKey: this.forwardCacheKey()
566
+ includeCacheKey: this.forwardCacheKey(),
567
+ openRouterAutoCache: this.isOpenRouter
561
568
  });
562
569
  }
563
570
  appendAssistantToolCall(history, toolCalls, assistantText) {