@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.
package/dist/index.d.mts CHANGED
@@ -277,6 +277,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
277
277
  readonly provider = "openrouter";
278
278
  readonly defaultObjectGenerationMode: "tool";
279
279
  readonly modelId: OpenRouterChatModelId;
280
+ readonly supportsImageUrls = true;
280
281
  readonly supportedUrls: Record<string, RegExp[]>;
281
282
  readonly settings: OpenRouterChatSettings;
282
283
  private readonly config;
@@ -330,6 +331,7 @@ declare class OpenRouterCompletionLanguageModel implements LanguageModelV2 {
330
331
  readonly specificationVersion: "v2";
331
332
  readonly provider = "openrouter";
332
333
  readonly modelId: OpenRouterCompletionModelId;
334
+ readonly supportsImageUrls = true;
333
335
  readonly supportedUrls: Record<string, RegExp[]>;
334
336
  readonly defaultObjectGenerationMode: undefined;
335
337
  readonly settings: OpenRouterCompletionSettings;
package/dist/index.d.ts CHANGED
@@ -277,6 +277,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
277
277
  readonly provider = "openrouter";
278
278
  readonly defaultObjectGenerationMode: "tool";
279
279
  readonly modelId: OpenRouterChatModelId;
280
+ readonly supportsImageUrls = true;
280
281
  readonly supportedUrls: Record<string, RegExp[]>;
281
282
  readonly settings: OpenRouterChatSettings;
282
283
  private readonly config;
@@ -330,6 +331,7 @@ declare class OpenRouterCompletionLanguageModel implements LanguageModelV2 {
330
331
  readonly specificationVersion: "v2";
331
332
  readonly provider = "openrouter";
332
333
  readonly modelId: OpenRouterCompletionModelId;
334
+ readonly supportsImageUrls = true;
333
335
  readonly supportedUrls: Record<string, RegExp[]>;
334
336
  readonly defaultObjectGenerationMode: undefined;
335
337
  readonly settings: OpenRouterCompletionSettings;
package/dist/index.js CHANGED
@@ -1014,9 +1014,23 @@ var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
1014
1014
 
1015
1015
  // src/schemas/provider-metadata.ts
1016
1016
  var import_v43 = require("zod/v4");
1017
+ var FileAnnotationSchema = import_v43.z.object({
1018
+ type: import_v43.z.literal("file"),
1019
+ file: import_v43.z.object({
1020
+ hash: import_v43.z.string(),
1021
+ name: import_v43.z.string(),
1022
+ content: import_v43.z.array(
1023
+ import_v43.z.object({
1024
+ type: import_v43.z.string(),
1025
+ text: import_v43.z.string().optional()
1026
+ }).passthrough()
1027
+ ).optional()
1028
+ }).passthrough()
1029
+ });
1017
1030
  var OpenRouterProviderMetadataSchema = import_v43.z.object({
1018
1031
  provider: import_v43.z.string(),
1019
1032
  reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional(),
1033
+ annotations: import_v43.z.array(FileAnnotationSchema).optional(),
1020
1034
  usage: import_v43.z.object({
1021
1035
  promptTokens: import_v43.z.number(),
1022
1036
  promptTokensDetails: import_v43.z.object({
@@ -1035,7 +1049,8 @@ var OpenRouterProviderMetadataSchema = import_v43.z.object({
1035
1049
  }).passthrough();
1036
1050
  var OpenRouterProviderOptionsSchema = import_v43.z.object({
1037
1051
  openrouter: import_v43.z.object({
1038
- reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional()
1052
+ reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional(),
1053
+ annotations: import_v43.z.array(FileAnnotationSchema).optional()
1039
1054
  }).optional()
1040
1055
  }).optional();
1041
1056
 
@@ -1149,7 +1164,7 @@ function getCacheControl(providerMetadata) {
1149
1164
  return (_c = (_b = (_a15 = openrouter2 == null ? void 0 : openrouter2.cacheControl) != null ? _a15 : openrouter2 == null ? void 0 : openrouter2.cache_control) != null ? _b : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
1150
1165
  }
1151
1166
  function convertToOpenRouterChatMessages(prompt) {
1152
- var _a15, _b, _c, _d, _e, _f, _g, _h;
1167
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1153
1168
  const messages = [];
1154
1169
  for (const { role, content, providerOptions } of prompt) {
1155
1170
  switch (role) {
@@ -1303,6 +1318,7 @@ function convertToOpenRouterChatMessages(prompt) {
1303
1318
  }
1304
1319
  const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
1305
1320
  const messageReasoningDetails = parsedProviderOptions.success ? (_g = (_f = parsedProviderOptions.data) == null ? void 0 : _f.openrouter) == null ? void 0 : _g.reasoning_details : void 0;
1321
+ const messageAnnotations = parsedProviderOptions.success ? (_i = (_h = parsedProviderOptions.data) == null ? void 0 : _h.openrouter) == null ? void 0 : _i.annotations : void 0;
1306
1322
  const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : accumulatedReasoningDetails.length > 0 ? accumulatedReasoningDetails : void 0;
1307
1323
  messages.push({
1308
1324
  role: "assistant",
@@ -1310,6 +1326,7 @@ function convertToOpenRouterChatMessages(prompt) {
1310
1326
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
1311
1327
  reasoning: reasoning || void 0,
1312
1328
  reasoning_details: finalReasoningDetails,
1329
+ annotations: messageAnnotations,
1313
1330
  cache_control: getCacheControl(providerOptions)
1314
1331
  });
1315
1332
  break;
@@ -1321,7 +1338,7 @@ function convertToOpenRouterChatMessages(prompt) {
1321
1338
  role: "tool",
1322
1339
  tool_call_id: toolResponse.toolCallId,
1323
1340
  content: content2,
1324
- cache_control: (_h = getCacheControl(providerOptions)) != null ? _h : getCacheControl(toolResponse.providerOptions)
1341
+ cache_control: (_j = getCacheControl(providerOptions)) != null ? _j : getCacheControl(toolResponse.providerOptions)
1325
1342
  });
1326
1343
  }
1327
1344
  break;
@@ -1580,6 +1597,7 @@ var OpenRouterChatLanguageModel = class {
1580
1597
  this.specificationVersion = "v2";
1581
1598
  this.provider = "openrouter";
1582
1599
  this.defaultObjectGenerationMode = "tool";
1600
+ this.supportsImageUrls = true;
1583
1601
  this.supportedUrls = {
1584
1602
  "image/*": [
1585
1603
  /^data:image\/[a-zA-Z]+;base64,/,
@@ -1674,7 +1692,7 @@ var OpenRouterChatLanguageModel = class {
1674
1692
  return baseArgs;
1675
1693
  }
1676
1694
  async doGenerate(options) {
1677
- var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
1695
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1678
1696
  const providerOptions = options.providerOptions || {};
1679
1697
  const openrouterOptions = providerOptions.openrouter || {};
1680
1698
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
@@ -1832,6 +1850,9 @@ var OpenRouterChatLanguageModel = class {
1832
1850
  }
1833
1851
  }
1834
1852
  }
1853
+ const fileAnnotations = (_k = choice.message.annotations) == null ? void 0 : _k.filter(
1854
+ (a) => a.type === "file"
1855
+ );
1835
1856
  return {
1836
1857
  content,
1837
1858
  finishReason: mapOpenRouterFinishReason(choice.finish_reason),
@@ -1839,22 +1860,23 @@ var OpenRouterChatLanguageModel = class {
1839
1860
  warnings: [],
1840
1861
  providerMetadata: {
1841
1862
  openrouter: OpenRouterProviderMetadataSchema.parse({
1842
- provider: (_k = response.provider) != null ? _k : "",
1843
- reasoning_details: (_l = choice.message.reasoning_details) != null ? _l : [],
1863
+ provider: (_l = response.provider) != null ? _l : "",
1864
+ reasoning_details: (_m = choice.message.reasoning_details) != null ? _m : [],
1865
+ annotations: fileAnnotations && fileAnnotations.length > 0 ? fileAnnotations : void 0,
1844
1866
  usage: __spreadValues(__spreadValues(__spreadValues({
1845
- promptTokens: (_m = usageInfo.inputTokens) != null ? _m : 0,
1846
- completionTokens: (_n = usageInfo.outputTokens) != null ? _n : 0,
1847
- totalTokens: (_o = usageInfo.totalTokens) != null ? _o : 0,
1848
- cost: (_p = response.usage) == null ? void 0 : _p.cost
1849
- }, ((_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? {
1867
+ promptTokens: (_n = usageInfo.inputTokens) != null ? _n : 0,
1868
+ completionTokens: (_o = usageInfo.outputTokens) != null ? _o : 0,
1869
+ totalTokens: (_p = usageInfo.totalTokens) != null ? _p : 0,
1870
+ cost: (_q = response.usage) == null ? void 0 : _q.cost
1871
+ }, ((_s = (_r = response.usage) == null ? void 0 : _r.prompt_tokens_details) == null ? void 0 : _s.cached_tokens) != null ? {
1850
1872
  promptTokensDetails: {
1851
1873
  cachedTokens: response.usage.prompt_tokens_details.cached_tokens
1852
1874
  }
1853
- } : {}), ((_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? {
1875
+ } : {}), ((_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? {
1854
1876
  completionTokensDetails: {
1855
1877
  reasoningTokens: response.usage.completion_tokens_details.reasoning_tokens
1856
1878
  }
1857
- } : {}), ((_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? {
1879
+ } : {}), ((_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? {
1858
1880
  costDetails: {
1859
1881
  upstreamInferenceCost: response.usage.cost_details.upstream_inference_cost
1860
1882
  }
@@ -2416,6 +2438,7 @@ var OpenRouterCompletionLanguageModel = class {
2416
2438
  constructor(modelId, settings, config) {
2417
2439
  this.specificationVersion = "v2";
2418
2440
  this.provider = "openrouter";
2441
+ this.supportsImageUrls = true;
2419
2442
  this.supportedUrls = {
2420
2443
  "image/*": [
2421
2444
  /^data:image\/[a-zA-Z]+;base64,/,
@@ -2713,7 +2736,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
2713
2736
  }
2714
2737
 
2715
2738
  // src/version.ts
2716
- var VERSION = false ? "0.0.0-test" : "1.3.0";
2739
+ var VERSION = false ? "0.0.0-test" : "1.4.0";
2717
2740
 
2718
2741
  // src/provider.ts
2719
2742
  function createOpenRouter(options = {}) {