@jambonz/llm 0.6.3 → 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) {
@@ -2792,11 +2799,12 @@ var BedrockAdapter = class {
2792
2799
  if (Object.keys(inferenceConfig).length > 0) {
2793
2800
  commandInput.inferenceConfig = inferenceConfig;
2794
2801
  }
2795
- if (req.cacheKey) {
2802
+ const caching = req.cacheKey ? cachePointSupport(req.model) : void 0;
2803
+ if (caching) {
2796
2804
  if (commandInput.system) {
2797
2805
  commandInput.system.push({ cachePoint: { type: "default" } });
2798
2806
  }
2799
- if (tools) {
2807
+ if (tools && caching.tools) {
2800
2808
  tools.tools.push({ cachePoint: { type: "default" } });
2801
2809
  }
2802
2810
  markLastMessageForCaching2(messages);
@@ -3020,6 +3028,11 @@ function buildWireMessages3(req) {
3020
3028
  }
3021
3029
  return out;
3022
3030
  }
3031
+ function cachePointSupport(model) {
3032
+ if (model.includes("anthropic.claude")) return { tools: true };
3033
+ if (model.includes("amazon.nova")) return { tools: false };
3034
+ return void 0;
3035
+ }
3023
3036
  function markLastMessageForCaching2(messages) {
3024
3037
  if (messages.length === 0) return;
3025
3038
  const last = messages[messages.length - 1];