@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.
@@ -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) {
@@ -2825,11 +2832,12 @@ var BedrockAdapter = class {
2825
2832
  if (Object.keys(inferenceConfig).length > 0) {
2826
2833
  commandInput.inferenceConfig = inferenceConfig;
2827
2834
  }
2828
- if (req.cacheKey) {
2835
+ const caching = req.cacheKey ? cachePointSupport(req.model) : void 0;
2836
+ if (caching) {
2829
2837
  if (commandInput.system) {
2830
2838
  commandInput.system.push({ cachePoint: { type: "default" } });
2831
2839
  }
2832
- if (tools) {
2840
+ if (tools && caching.tools) {
2833
2841
  tools.tools.push({ cachePoint: { type: "default" } });
2834
2842
  }
2835
2843
  markLastMessageForCaching2(messages);
@@ -3053,6 +3061,11 @@ function buildWireMessages3(req) {
3053
3061
  }
3054
3062
  return out;
3055
3063
  }
3064
+ function cachePointSupport(model) {
3065
+ if (model.includes("anthropic.claude")) return { tools: true };
3066
+ if (model.includes("amazon.nova")) return { tools: false };
3067
+ return void 0;
3068
+ }
3056
3069
  function markLastMessageForCaching2(messages) {
3057
3070
  if (messages.length === 0) return;
3058
3071
  const last = messages[messages.length - 1];