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