@openrouter/ai-sdk-provider 1.2.8 → 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.
@@ -91,7 +91,7 @@ type OpenRouterUsageAccounting = {
91
91
  };
92
92
  totalTokens: number;
93
93
  cost?: number;
94
- costDetails: {
94
+ costDetails?: {
95
95
  upstreamInferenceCost: number;
96
96
  };
97
97
  };
@@ -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;
@@ -224,6 +225,19 @@ type OpenRouterChatSettings = {
224
225
  */
225
226
  search_prompt?: string;
226
227
  };
228
+ /**
229
+ * Debug options for troubleshooting API requests.
230
+ * Only works with streaming requests.
231
+ * @see https://openrouter.ai/docs/api-reference/debugging
232
+ */
233
+ debug?: {
234
+ /**
235
+ * When true, echoes back the request body that was sent to the upstream provider.
236
+ * The debug data will be returned as the first chunk in the stream with a `debug.echo_upstream_body` field.
237
+ * Sensitive data like user IDs and base64 content will be redacted.
238
+ */
239
+ echo_upstream_body?: boolean;
240
+ };
227
241
  /**
228
242
  * Provider routing preferences to control request routing behavior
229
243
  */
@@ -259,7 +273,7 @@ type OpenRouterChatSettings = {
259
273
  /**
260
274
  * Sort providers by price, throughput, or latency
261
275
  */
262
- sort?: models.Sort;
276
+ sort?: models.ProviderSort;
263
277
  /**
264
278
  * Maximum pricing you want to pay for this request
265
279
  */
@@ -289,6 +303,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
289
303
  readonly provider = "openrouter";
290
304
  readonly defaultObjectGenerationMode: "tool";
291
305
  readonly modelId: OpenRouterChatModelId;
306
+ readonly supportsImageUrls = true;
292
307
  readonly supportedUrls: Record<string, RegExp[]>;
293
308
  readonly settings: OpenRouterChatSettings;
294
309
  private readonly config;
@@ -91,7 +91,7 @@ type OpenRouterUsageAccounting = {
91
91
  };
92
92
  totalTokens: number;
93
93
  cost?: number;
94
- costDetails: {
94
+ costDetails?: {
95
95
  upstreamInferenceCost: number;
96
96
  };
97
97
  };
@@ -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;
@@ -224,6 +225,19 @@ type OpenRouterChatSettings = {
224
225
  */
225
226
  search_prompt?: string;
226
227
  };
228
+ /**
229
+ * Debug options for troubleshooting API requests.
230
+ * Only works with streaming requests.
231
+ * @see https://openrouter.ai/docs/api-reference/debugging
232
+ */
233
+ debug?: {
234
+ /**
235
+ * When true, echoes back the request body that was sent to the upstream provider.
236
+ * The debug data will be returned as the first chunk in the stream with a `debug.echo_upstream_body` field.
237
+ * Sensitive data like user IDs and base64 content will be redacted.
238
+ */
239
+ echo_upstream_body?: boolean;
240
+ };
227
241
  /**
228
242
  * Provider routing preferences to control request routing behavior
229
243
  */
@@ -259,7 +273,7 @@ type OpenRouterChatSettings = {
259
273
  /**
260
274
  * Sort providers by price, throughput, or latency
261
275
  */
262
- sort?: models.Sort;
276
+ sort?: models.ProviderSort;
263
277
  /**
264
278
  * Maximum pricing you want to pay for this request
265
279
  */
@@ -289,6 +303,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
289
303
  readonly provider = "openrouter";
290
304
  readonly defaultObjectGenerationMode: "tool";
291
305
  readonly modelId: OpenRouterChatModelId;
306
+ readonly supportsImageUrls = true;
292
307
  readonly supportedUrls: Record<string, RegExp[]>;
293
308
  readonly settings: OpenRouterChatSettings;
294
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({
@@ -984,12 +998,13 @@ var OpenRouterProviderMetadataSchema = import_v43.z.object({
984
998
  cost: import_v43.z.number().optional(),
985
999
  costDetails: import_v43.z.object({
986
1000
  upstreamInferenceCost: import_v43.z.number()
987
- }).passthrough()
1001
+ }).passthrough().optional()
988
1002
  }).passthrough()
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,9 +1118,8 @@ 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;
1121
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1107
1122
  const messages = [];
1108
- const accumulatedReasoningDetails = [];
1109
1123
  for (const { role, content, providerOptions } of prompt) {
1110
1124
  switch (role) {
1111
1125
  case "system": {
@@ -1135,7 +1149,7 @@ function convertToOpenRouterChatMessages(prompt) {
1135
1149
  const messageCacheControl = getCacheControl(providerOptions);
1136
1150
  const contentParts = content.map(
1137
1151
  (part) => {
1138
- var _a16, _b2, _c2, _d2, _e2, _f2, _g;
1152
+ var _a16, _b2, _c2, _d2, _e2, _f2, _g2;
1139
1153
  const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
1140
1154
  switch (part.type) {
1141
1155
  case "text":
@@ -1168,7 +1182,7 @@ function convertToOpenRouterChatMessages(prompt) {
1168
1182
  };
1169
1183
  }
1170
1184
  const fileName = String(
1171
- (_g = (_f2 = (_e2 = (_d2 = part.providerOptions) == null ? void 0 : _d2.openrouter) == null ? void 0 : _e2.filename) != null ? _f2 : part.filename) != null ? _g : ""
1185
+ (_g2 = (_f2 = (_e2 = (_d2 = part.providerOptions) == null ? void 0 : _d2.openrouter) == null ? void 0 : _e2.filename) != null ? _f2 : part.filename) != null ? _g2 : ""
1172
1186
  );
1173
1187
  const fileData = getFileUrl({
1174
1188
  part,
@@ -1215,6 +1229,7 @@ function convertToOpenRouterChatMessages(prompt) {
1215
1229
  let text = "";
1216
1230
  let reasoning = "";
1217
1231
  const toolCalls = [];
1232
+ const accumulatedReasoningDetails = [];
1218
1233
  for (const part of content) {
1219
1234
  switch (part.type) {
1220
1235
  case "text": {
@@ -1240,6 +1255,12 @@ function convertToOpenRouterChatMessages(prompt) {
1240
1255
  }
1241
1256
  case "reasoning": {
1242
1257
  reasoning += part.text;
1258
+ const parsedPartProviderOptions = OpenRouterProviderOptionsSchema.safeParse(part.providerOptions);
1259
+ if (parsedPartProviderOptions.success && ((_e = (_d = parsedPartProviderOptions.data) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.reasoning_details)) {
1260
+ accumulatedReasoningDetails.push(
1261
+ ...parsedPartProviderOptions.data.openrouter.reasoning_details
1262
+ );
1263
+ }
1243
1264
  break;
1244
1265
  }
1245
1266
  case "file":
@@ -1250,7 +1271,8 @@ function convertToOpenRouterChatMessages(prompt) {
1250
1271
  }
1251
1272
  }
1252
1273
  const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
1253
- const messageReasoningDetails = parsedProviderOptions.success ? (_e = (_d = parsedProviderOptions.data) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.reasoning_details : void 0;
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;
1254
1276
  const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : accumulatedReasoningDetails.length > 0 ? accumulatedReasoningDetails : void 0;
1255
1277
  messages.push({
1256
1278
  role: "assistant",
@@ -1258,6 +1280,7 @@ function convertToOpenRouterChatMessages(prompt) {
1258
1280
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
1259
1281
  reasoning: reasoning || void 0,
1260
1282
  reasoning_details: finalReasoningDetails,
1283
+ annotations: messageAnnotations,
1261
1284
  cache_control: getCacheControl(providerOptions)
1262
1285
  });
1263
1286
  break;
@@ -1269,7 +1292,7 @@ function convertToOpenRouterChatMessages(prompt) {
1269
1292
  role: "tool",
1270
1293
  tool_call_id: toolResponse.toolCallId,
1271
1294
  content: content2,
1272
- cache_control: (_f = getCacheControl(providerOptions)) != null ? _f : getCacheControl(toolResponse.providerOptions)
1295
+ cache_control: (_j = getCacheControl(providerOptions)) != null ? _j : getCacheControl(toolResponse.providerOptions)
1273
1296
  });
1274
1297
  }
1275
1298
  break;
@@ -1528,6 +1551,7 @@ var OpenRouterChatLanguageModel = class {
1528
1551
  this.specificationVersion = "v2";
1529
1552
  this.provider = "openrouter";
1530
1553
  this.defaultObjectGenerationMode = "tool";
1554
+ this.supportsImageUrls = true;
1531
1555
  this.supportedUrls = {
1532
1556
  "image/*": [
1533
1557
  /^data:image\/[a-zA-Z]+;base64,/,
@@ -1585,7 +1609,9 @@ var OpenRouterChatLanguageModel = class {
1585
1609
  plugins: this.settings.plugins,
1586
1610
  web_search_options: this.settings.web_search_options,
1587
1611
  // Provider routing settings:
1588
- provider: this.settings.provider
1612
+ provider: this.settings.provider,
1613
+ // Debug settings:
1614
+ debug: this.settings.debug
1589
1615
  }, this.config.extraBody), this.settings.extraBody);
1590
1616
  if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
1591
1617
  return __spreadProps(__spreadValues({}, baseArgs), {
@@ -1620,7 +1646,7 @@ var OpenRouterChatLanguageModel = class {
1620
1646
  return baseArgs;
1621
1647
  }
1622
1648
  async doGenerate(options) {
1623
- var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
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;
1624
1650
  const providerOptions = options.providerOptions || {};
1625
1651
  const openrouterOptions = providerOptions.openrouter || {};
1626
1652
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
@@ -1778,6 +1804,9 @@ var OpenRouterChatLanguageModel = class {
1778
1804
  }
1779
1805
  }
1780
1806
  }
1807
+ const fileAnnotations = (_k = choice.message.annotations) == null ? void 0 : _k.filter(
1808
+ (a) => a.type === "file"
1809
+ );
1781
1810
  return {
1782
1811
  content,
1783
1812
  finishReason: mapOpenRouterFinishReason(choice.finish_reason),
@@ -1785,23 +1814,27 @@ var OpenRouterChatLanguageModel = class {
1785
1814
  warnings: [],
1786
1815
  providerMetadata: {
1787
1816
  openrouter: OpenRouterProviderMetadataSchema.parse({
1788
- provider: (_k = response.provider) != null ? _k : "",
1789
- reasoning_details: (_l = choice.message.reasoning_details) != null ? _l : [],
1790
- usage: {
1791
- promptTokens: (_m = usageInfo.inputTokens) != null ? _m : 0,
1792
- completionTokens: (_n = usageInfo.outputTokens) != null ? _n : 0,
1793
- totalTokens: (_o = usageInfo.totalTokens) != null ? _o : 0,
1794
- cost: (_p = response.usage) == null ? void 0 : _p.cost,
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,
1820
+ usage: __spreadValues(__spreadValues(__spreadValues({
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 ? {
1795
1826
  promptTokensDetails: {
1796
- cachedTokens: (_s = (_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : 0
1797
- },
1827
+ cachedTokens: response.usage.prompt_tokens_details.cached_tokens
1828
+ }
1829
+ } : {}), ((_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? {
1798
1830
  completionTokensDetails: {
1799
- reasoningTokens: (_v = (_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? _v : 0
1800
- },
1831
+ reasoningTokens: response.usage.completion_tokens_details.reasoning_tokens
1832
+ }
1833
+ } : {}), ((_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? {
1801
1834
  costDetails: {
1802
- upstreamInferenceCost: (_y = (_x = (_w = response.usage) == null ? void 0 : _w.cost_details) == null ? void 0 : _x.upstream_inference_cost) != null ? _y : 0
1835
+ upstreamInferenceCost: response.usage.cost_details.upstream_inference_cost
1803
1836
  }
1804
- }
1837
+ } : {})
1805
1838
  })
1806
1839
  },
1807
1840
  request: { body: args },
@@ -1858,7 +1891,7 @@ var OpenRouterChatLanguageModel = class {
1858
1891
  stream: response.pipeThrough(
1859
1892
  new TransformStream({
1860
1893
  transform(chunk, controller) {
1861
- var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1894
+ var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1862
1895
  if (!chunk.success) {
1863
1896
  finishReason = "error";
1864
1897
  controller.enqueue({ type: "error", error: chunk.error });
@@ -1908,6 +1941,12 @@ var OpenRouterChatLanguageModel = class {
1908
1941
  }
1909
1942
  openrouterUsage.cost = value.usage.cost;
1910
1943
  openrouterUsage.totalTokens = value.usage.total_tokens;
1944
+ const upstreamInferenceCost = (_c = value.usage.cost_details) == null ? void 0 : _c.upstream_inference_cost;
1945
+ if (upstreamInferenceCost != null) {
1946
+ openrouterUsage.costDetails = {
1947
+ upstreamInferenceCost
1948
+ };
1949
+ }
1911
1950
  }
1912
1951
  const choice = value.choices[0];
1913
1952
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
@@ -1917,16 +1956,18 @@ var OpenRouterChatLanguageModel = class {
1917
1956
  return;
1918
1957
  }
1919
1958
  const delta = choice.delta;
1920
- const emitReasoningChunk = (chunkText) => {
1959
+ const emitReasoningChunk = (chunkText, providerMetadata) => {
1921
1960
  if (!reasoningStarted) {
1922
1961
  reasoningId = openrouterResponseId || generateId();
1923
1962
  controller.enqueue({
1963
+ providerMetadata,
1924
1964
  type: "reasoning-start",
1925
1965
  id: reasoningId
1926
1966
  });
1927
1967
  reasoningStarted = true;
1928
1968
  }
1929
1969
  controller.enqueue({
1970
+ providerMetadata,
1930
1971
  type: "reasoning-delta",
1931
1972
  delta: chunkText,
1932
1973
  id: reasoningId || generateId()
@@ -1947,23 +1988,28 @@ var OpenRouterChatLanguageModel = class {
1947
1988
  accumulatedReasoningDetails.push(detail);
1948
1989
  }
1949
1990
  }
1991
+ const reasoningMetadata = {
1992
+ openrouter: {
1993
+ reasoning_details: delta.reasoning_details
1994
+ }
1995
+ };
1950
1996
  for (const detail of delta.reasoning_details) {
1951
1997
  switch (detail.type) {
1952
1998
  case "reasoning.text" /* Text */: {
1953
1999
  if (detail.text) {
1954
- emitReasoningChunk(detail.text);
2000
+ emitReasoningChunk(detail.text, reasoningMetadata);
1955
2001
  }
1956
2002
  break;
1957
2003
  }
1958
2004
  case "reasoning.encrypted" /* Encrypted */: {
1959
2005
  if (detail.data) {
1960
- emitReasoningChunk("[REDACTED]");
2006
+ emitReasoningChunk("[REDACTED]", reasoningMetadata);
1961
2007
  }
1962
2008
  break;
1963
2009
  }
1964
2010
  case "reasoning.summary" /* Summary */: {
1965
2011
  if (detail.summary) {
1966
- emitReasoningChunk(detail.summary);
2012
+ emitReasoningChunk(detail.summary, reasoningMetadata);
1967
2013
  }
1968
2014
  break;
1969
2015
  }
@@ -2018,7 +2064,7 @@ var OpenRouterChatLanguageModel = class {
2018
2064
  }
2019
2065
  if (delta.tool_calls != null) {
2020
2066
  for (const toolCallDelta of delta.tool_calls) {
2021
- const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
2067
+ const index = (_d = toolCallDelta.index) != null ? _d : toolCalls.length - 1;
2022
2068
  if (toolCalls[index] == null) {
2023
2069
  if (toolCallDelta.type !== "function") {
2024
2070
  throw new InvalidResponseDataError({
@@ -2032,7 +2078,7 @@ var OpenRouterChatLanguageModel = class {
2032
2078
  message: `Expected 'id' to be a string.`
2033
2079
  });
2034
2080
  }
2035
- if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
2081
+ if (((_e = toolCallDelta.function) == null ? void 0 : _e.name) == null) {
2036
2082
  throw new InvalidResponseDataError({
2037
2083
  data: toolCallDelta,
2038
2084
  message: `Expected 'function.name' to be a string.`
@@ -2043,7 +2089,7 @@ var OpenRouterChatLanguageModel = class {
2043
2089
  type: "function",
2044
2090
  function: {
2045
2091
  name: toolCallDelta.function.name,
2046
- arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
2092
+ arguments: (_f = toolCallDelta.function.arguments) != null ? _f : ""
2047
2093
  },
2048
2094
  inputStarted: false,
2049
2095
  sent: false
@@ -2055,7 +2101,7 @@ var OpenRouterChatLanguageModel = class {
2055
2101
  message: `Tool call at index ${index} is missing after creation.`
2056
2102
  });
2057
2103
  }
2058
- if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
2104
+ if (((_g = toolCall2.function) == null ? void 0 : _g.name) != null && ((_h = toolCall2.function) == null ? void 0 : _h.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
2059
2105
  toolCall2.inputStarted = true;
2060
2106
  controller.enqueue({
2061
2107
  type: "tool-input-start",
@@ -2105,18 +2151,18 @@ var OpenRouterChatLanguageModel = class {
2105
2151
  toolName: toolCall.function.name
2106
2152
  });
2107
2153
  }
2108
- if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
2109
- toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
2154
+ if (((_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null) {
2155
+ toolCall.function.arguments += (_k = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null ? _k : "";
2110
2156
  }
2111
2157
  controller.enqueue({
2112
2158
  type: "tool-input-delta",
2113
2159
  id: toolCall.id,
2114
- delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
2160
+ delta: (_l = toolCallDelta.function.arguments) != null ? _l : ""
2115
2161
  });
2116
- if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
2162
+ if (((_m = toolCall.function) == null ? void 0 : _m.name) != null && ((_n = toolCall.function) == null ? void 0 : _n.arguments) != null && isParsableJson(toolCall.function.arguments)) {
2117
2163
  controller.enqueue({
2118
2164
  type: "tool-call",
2119
- toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
2165
+ toolCallId: (_o = toolCall.id) != null ? _o : generateId(),
2120
2166
  toolName: toolCall.function.name,
2121
2167
  input: toolCall.function.arguments,
2122
2168
  providerMetadata: {
@@ -2332,7 +2378,10 @@ var OpenRouterCompletionChunkSchema = import_v47.z.union([
2332
2378
  reasoning_tokens: import_v47.z.number()
2333
2379
  }).passthrough().nullish(),
2334
2380
  total_tokens: import_v47.z.number(),
2335
- cost: import_v47.z.number().optional()
2381
+ cost: import_v47.z.number().optional(),
2382
+ cost_details: import_v47.z.object({
2383
+ upstream_inference_cost: import_v47.z.number().nullish()
2384
+ }).passthrough().nullish()
2336
2385
  }).passthrough().nullish()
2337
2386
  }).passthrough(),
2338
2387
  OpenRouterErrorResponseSchema
@@ -2343,6 +2392,7 @@ var OpenRouterCompletionLanguageModel = class {
2343
2392
  constructor(modelId, settings, config) {
2344
2393
  this.specificationVersion = "v2";
2345
2394
  this.provider = "openrouter";
2395
+ this.supportsImageUrls = true;
2346
2396
  this.supportedUrls = {
2347
2397
  "image/*": [
2348
2398
  /^data:image\/[a-zA-Z]+;base64,/,
@@ -2505,7 +2555,7 @@ var OpenRouterCompletionLanguageModel = class {
2505
2555
  stream: response.pipeThrough(
2506
2556
  new TransformStream({
2507
2557
  transform(chunk, controller) {
2508
- var _a15, _b;
2558
+ var _a15, _b, _c;
2509
2559
  if (!chunk.success) {
2510
2560
  finishReason = "error";
2511
2561
  controller.enqueue({ type: "error", error: chunk.error });
@@ -2539,6 +2589,12 @@ var OpenRouterCompletionLanguageModel = class {
2539
2589
  }
2540
2590
  openrouterUsage.cost = value.usage.cost;
2541
2591
  openrouterUsage.totalTokens = value.usage.total_tokens;
2592
+ const upstreamInferenceCost = (_c = value.usage.cost_details) == null ? void 0 : _c.upstream_inference_cost;
2593
+ if (upstreamInferenceCost != null) {
2594
+ openrouterUsage.costDetails = {
2595
+ upstreamInferenceCost
2596
+ };
2597
+ }
2542
2598
  }
2543
2599
  const choice = value.choices[0];
2544
2600
  if ((choice == null ? void 0 : choice.finish_reason) != null) {