@openrouter/ai-sdk-provider 1.3.0 → 1.4.0

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.
@@ -146,6 +146,7 @@ declare class OpenRouterCompletionLanguageModel implements LanguageModelV2 {
146
146
  readonly specificationVersion: "v2";
147
147
  readonly provider = "openrouter";
148
148
  readonly modelId: OpenRouterCompletionModelId;
149
+ readonly supportsImageUrls = true;
149
150
  readonly supportedUrls: Record<string, RegExp[]>;
150
151
  readonly defaultObjectGenerationMode: undefined;
151
152
  readonly settings: OpenRouterCompletionSettings;
@@ -302,6 +303,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
302
303
  readonly provider = "openrouter";
303
304
  readonly defaultObjectGenerationMode: "tool";
304
305
  readonly modelId: OpenRouterChatModelId;
306
+ readonly supportsImageUrls = true;
305
307
  readonly supportedUrls: Record<string, RegExp[]>;
306
308
  readonly settings: OpenRouterChatSettings;
307
309
  private readonly config;
@@ -146,6 +146,7 @@ declare class OpenRouterCompletionLanguageModel implements LanguageModelV2 {
146
146
  readonly specificationVersion: "v2";
147
147
  readonly provider = "openrouter";
148
148
  readonly modelId: OpenRouterCompletionModelId;
149
+ readonly supportsImageUrls = true;
149
150
  readonly supportedUrls: Record<string, RegExp[]>;
150
151
  readonly defaultObjectGenerationMode: undefined;
151
152
  readonly settings: OpenRouterCompletionSettings;
@@ -302,6 +303,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
302
303
  readonly provider = "openrouter";
303
304
  readonly defaultObjectGenerationMode: "tool";
304
305
  readonly modelId: OpenRouterChatModelId;
306
+ readonly supportsImageUrls = true;
305
307
  readonly supportedUrls: Record<string, RegExp[]>;
306
308
  readonly settings: OpenRouterChatSettings;
307
309
  private readonly config;
@@ -968,9 +968,23 @@ var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
968
968
 
969
969
  // src/schemas/provider-metadata.ts
970
970
  var import_v43 = require("zod/v4");
971
+ var FileAnnotationSchema = import_v43.z.object({
972
+ type: import_v43.z.literal("file"),
973
+ file: import_v43.z.object({
974
+ hash: import_v43.z.string(),
975
+ name: import_v43.z.string(),
976
+ content: import_v43.z.array(
977
+ import_v43.z.object({
978
+ type: import_v43.z.string(),
979
+ text: import_v43.z.string().optional()
980
+ }).passthrough()
981
+ ).optional()
982
+ }).passthrough()
983
+ });
971
984
  var OpenRouterProviderMetadataSchema = import_v43.z.object({
972
985
  provider: import_v43.z.string(),
973
986
  reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional(),
987
+ annotations: import_v43.z.array(FileAnnotationSchema).optional(),
974
988
  usage: import_v43.z.object({
975
989
  promptTokens: import_v43.z.number(),
976
990
  promptTokensDetails: import_v43.z.object({
@@ -989,7 +1003,8 @@ var OpenRouterProviderMetadataSchema = import_v43.z.object({
989
1003
  }).passthrough();
990
1004
  var OpenRouterProviderOptionsSchema = import_v43.z.object({
991
1005
  openrouter: import_v43.z.object({
992
- reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional()
1006
+ reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional(),
1007
+ annotations: import_v43.z.array(FileAnnotationSchema).optional()
993
1008
  }).optional()
994
1009
  }).optional();
995
1010
 
@@ -1103,7 +1118,7 @@ function getCacheControl(providerMetadata) {
1103
1118
  return (_c = (_b = (_a15 = openrouter == null ? void 0 : openrouter.cacheControl) != null ? _a15 : openrouter == null ? void 0 : openrouter.cache_control) != null ? _b : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
1104
1119
  }
1105
1120
  function convertToOpenRouterChatMessages(prompt) {
1106
- var _a15, _b, _c, _d, _e, _f, _g, _h;
1121
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1107
1122
  const messages = [];
1108
1123
  for (const { role, content, providerOptions } of prompt) {
1109
1124
  switch (role) {
@@ -1257,6 +1272,7 @@ function convertToOpenRouterChatMessages(prompt) {
1257
1272
  }
1258
1273
  const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
1259
1274
  const messageReasoningDetails = parsedProviderOptions.success ? (_g = (_f = parsedProviderOptions.data) == null ? void 0 : _f.openrouter) == null ? void 0 : _g.reasoning_details : void 0;
1275
+ const messageAnnotations = parsedProviderOptions.success ? (_i = (_h = parsedProviderOptions.data) == null ? void 0 : _h.openrouter) == null ? void 0 : _i.annotations : void 0;
1260
1276
  const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : accumulatedReasoningDetails.length > 0 ? accumulatedReasoningDetails : void 0;
1261
1277
  messages.push({
1262
1278
  role: "assistant",
@@ -1264,6 +1280,7 @@ function convertToOpenRouterChatMessages(prompt) {
1264
1280
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
1265
1281
  reasoning: reasoning || void 0,
1266
1282
  reasoning_details: finalReasoningDetails,
1283
+ annotations: messageAnnotations,
1267
1284
  cache_control: getCacheControl(providerOptions)
1268
1285
  });
1269
1286
  break;
@@ -1275,7 +1292,7 @@ function convertToOpenRouterChatMessages(prompt) {
1275
1292
  role: "tool",
1276
1293
  tool_call_id: toolResponse.toolCallId,
1277
1294
  content: content2,
1278
- cache_control: (_h = getCacheControl(providerOptions)) != null ? _h : getCacheControl(toolResponse.providerOptions)
1295
+ cache_control: (_j = getCacheControl(providerOptions)) != null ? _j : getCacheControl(toolResponse.providerOptions)
1279
1296
  });
1280
1297
  }
1281
1298
  break;
@@ -1534,6 +1551,7 @@ var OpenRouterChatLanguageModel = class {
1534
1551
  this.specificationVersion = "v2";
1535
1552
  this.provider = "openrouter";
1536
1553
  this.defaultObjectGenerationMode = "tool";
1554
+ this.supportsImageUrls = true;
1537
1555
  this.supportedUrls = {
1538
1556
  "image/*": [
1539
1557
  /^data:image\/[a-zA-Z]+;base64,/,
@@ -1628,7 +1646,7 @@ var OpenRouterChatLanguageModel = class {
1628
1646
  return baseArgs;
1629
1647
  }
1630
1648
  async doGenerate(options) {
1631
- var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
1649
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1632
1650
  const providerOptions = options.providerOptions || {};
1633
1651
  const openrouterOptions = providerOptions.openrouter || {};
1634
1652
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
@@ -1786,6 +1804,9 @@ var OpenRouterChatLanguageModel = class {
1786
1804
  }
1787
1805
  }
1788
1806
  }
1807
+ const fileAnnotations = (_k = choice.message.annotations) == null ? void 0 : _k.filter(
1808
+ (a) => a.type === "file"
1809
+ );
1789
1810
  return {
1790
1811
  content,
1791
1812
  finishReason: mapOpenRouterFinishReason(choice.finish_reason),
@@ -1793,22 +1814,23 @@ var OpenRouterChatLanguageModel = class {
1793
1814
  warnings: [],
1794
1815
  providerMetadata: {
1795
1816
  openrouter: OpenRouterProviderMetadataSchema.parse({
1796
- provider: (_k = response.provider) != null ? _k : "",
1797
- reasoning_details: (_l = choice.message.reasoning_details) != null ? _l : [],
1817
+ provider: (_l = response.provider) != null ? _l : "",
1818
+ reasoning_details: (_m = choice.message.reasoning_details) != null ? _m : [],
1819
+ annotations: fileAnnotations && fileAnnotations.length > 0 ? fileAnnotations : void 0,
1798
1820
  usage: __spreadValues(__spreadValues(__spreadValues({
1799
- promptTokens: (_m = usageInfo.inputTokens) != null ? _m : 0,
1800
- completionTokens: (_n = usageInfo.outputTokens) != null ? _n : 0,
1801
- totalTokens: (_o = usageInfo.totalTokens) != null ? _o : 0,
1802
- cost: (_p = response.usage) == null ? void 0 : _p.cost
1803
- }, ((_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? {
1821
+ promptTokens: (_n = usageInfo.inputTokens) != null ? _n : 0,
1822
+ completionTokens: (_o = usageInfo.outputTokens) != null ? _o : 0,
1823
+ totalTokens: (_p = usageInfo.totalTokens) != null ? _p : 0,
1824
+ cost: (_q = response.usage) == null ? void 0 : _q.cost
1825
+ }, ((_s = (_r = response.usage) == null ? void 0 : _r.prompt_tokens_details) == null ? void 0 : _s.cached_tokens) != null ? {
1804
1826
  promptTokensDetails: {
1805
1827
  cachedTokens: response.usage.prompt_tokens_details.cached_tokens
1806
1828
  }
1807
- } : {}), ((_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? {
1829
+ } : {}), ((_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? {
1808
1830
  completionTokensDetails: {
1809
1831
  reasoningTokens: response.usage.completion_tokens_details.reasoning_tokens
1810
1832
  }
1811
- } : {}), ((_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? {
1833
+ } : {}), ((_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? {
1812
1834
  costDetails: {
1813
1835
  upstreamInferenceCost: response.usage.cost_details.upstream_inference_cost
1814
1836
  }
@@ -2370,6 +2392,7 @@ var OpenRouterCompletionLanguageModel = class {
2370
2392
  constructor(modelId, settings, config) {
2371
2393
  this.specificationVersion = "v2";
2372
2394
  this.provider = "openrouter";
2395
+ this.supportsImageUrls = true;
2373
2396
  this.supportedUrls = {
2374
2397
  "image/*": [
2375
2398
  /^data:image\/[a-zA-Z]+;base64,/,