@openrouter/ai-sdk-provider 2.9.1 → 2.10.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.mjs CHANGED
@@ -4859,26 +4859,10 @@ var OpenRouter = class {
4859
4859
  // src/image/schemas.ts
4860
4860
  import { z as z10 } from "zod/v4";
4861
4861
  var OpenRouterImageResponseSchema = z10.object({
4862
- id: z10.string().optional(),
4863
- object: z10.string().optional(),
4864
4862
  created: z10.number().optional(),
4865
- model: z10.string(),
4866
- choices: z10.array(
4863
+ data: z10.array(
4867
4864
  z10.object({
4868
- index: z10.number(),
4869
- message: z10.object({
4870
- role: z10.string(),
4871
- content: z10.string().nullable().optional(),
4872
- images: z10.array(
4873
- z10.object({
4874
- type: z10.literal("image_url"),
4875
- image_url: z10.object({
4876
- url: z10.string()
4877
- })
4878
- }).passthrough()
4879
- ).optional()
4880
- }).passthrough(),
4881
- finish_reason: z10.string().nullable().optional()
4865
+ b64_json: z10.string()
4882
4866
  }).passthrough()
4883
4867
  ),
4884
4868
  usage: z10.object({
@@ -4893,13 +4877,12 @@ var OpenRouterImageModel = class {
4893
4877
  constructor(modelId, settings, config) {
4894
4878
  this.specificationVersion = "v3";
4895
4879
  this.provider = "openrouter";
4896
- this.maxImagesPerCall = 1;
4880
+ this.maxImagesPerCall = 10;
4897
4881
  this.modelId = modelId;
4898
4882
  this.settings = settings;
4899
4883
  this.config = config;
4900
4884
  }
4901
4885
  async doGenerate(options) {
4902
- var _a16;
4903
4886
  const {
4904
4887
  prompt,
4905
4888
  n,
@@ -4919,43 +4902,19 @@ var OpenRouterImageModel = class {
4919
4902
  functionality: "image inpainting (mask parameter)"
4920
4903
  });
4921
4904
  }
4922
- if (n > 1) {
4923
- warnings.push({
4924
- type: "unsupported",
4925
- feature: "n > 1",
4926
- details: `OpenRouter image generation returns 1 image per call. Requested ${n} images.`
4927
- });
4928
- }
4929
- if (size !== void 0) {
4930
- warnings.push({
4931
- type: "unsupported",
4932
- feature: "size",
4933
- details: "Use aspectRatio instead. Size parameter is not supported by OpenRouter image generation."
4934
- });
4935
- }
4936
- const imageConfig = aspectRatio !== void 0 ? { aspect_ratio: aspectRatio } : void 0;
4937
4905
  const hasFiles = files !== void 0 && files.length > 0;
4938
- const userContent = hasFiles ? [
4939
- ...files.map(
4940
- (file) => convertImageFileToContentPart(file)
4941
- ),
4942
- { type: "text", text: prompt != null ? prompt : "" }
4943
- ] : prompt != null ? prompt : "";
4944
- const body = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
4906
+ const inputReferences = hasFiles ? files.map((file) => convertFileToInputReference(file)) : void 0;
4907
+ const body = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
4945
4908
  model: this.modelId,
4946
- messages: [
4947
- {
4948
- role: "user",
4949
- content: userContent
4950
- }
4951
- ],
4952
- modalities: ["image", "text"]
4953
- }, imageConfig !== void 0 && { image_config: imageConfig }), seed !== void 0 && { seed }), this.settings.user !== void 0 && { user: this.settings.user }), this.settings.provider !== void 0 && {
4909
+ prompt: prompt != null ? prompt : ""
4910
+ }, n !== void 0 && { n }), size !== void 0 && { size }), aspectRatio !== void 0 && { aspect_ratio: aspectRatio }), seed !== void 0 && { seed }), inputReferences !== void 0 && {
4911
+ input_references: inputReferences
4912
+ }), this.settings.user !== void 0 && { user: this.settings.user }), this.settings.provider !== void 0 && {
4954
4913
  provider: this.settings.provider
4955
4914
  }), this.config.extraBody), this.settings.extraBody), openrouterOptions);
4956
4915
  const { value: responseValue, responseHeaders } = await postJsonToApi({
4957
4916
  url: this.config.url({
4958
- path: "/chat/completions",
4917
+ path: "/images",
4959
4918
  modelId: this.modelId
4960
4919
  }),
4961
4920
  headers: combineHeaders(this.config.headers(), headers),
@@ -4967,19 +4926,12 @@ var OpenRouterImageModel = class {
4967
4926
  abortSignal,
4968
4927
  fetch: this.config.fetch
4969
4928
  });
4970
- const choice = responseValue.choices[0];
4971
- if (!choice) {
4929
+ if (!responseValue.data || responseValue.data.length === 0) {
4972
4930
  throw new NoContentGeneratedError({
4973
- message: "No choice in response"
4931
+ message: "No images in response"
4974
4932
  });
4975
4933
  }
4976
- const images = [];
4977
- if ((_a16 = choice.message) == null ? void 0 : _a16.images) {
4978
- for (const image of choice.message.images) {
4979
- const dataUrl = image.image_url.url;
4980
- images.push(getBase64FromDataUrl(dataUrl));
4981
- }
4982
- }
4934
+ const images = responseValue.data.map((item) => item.b64_json);
4983
4935
  const usage = responseValue.usage ? {
4984
4936
  inputTokens: responseValue.usage.prompt_tokens,
4985
4937
  outputTokens: responseValue.usage.completion_tokens,
@@ -4990,7 +4942,7 @@ var OpenRouterImageModel = class {
4990
4942
  warnings,
4991
4943
  response: {
4992
4944
  timestamp: /* @__PURE__ */ new Date(),
4993
- modelId: responseValue.model,
4945
+ modelId: this.modelId,
4994
4946
  headers: responseHeaders
4995
4947
  },
4996
4948
  usage
@@ -4998,7 +4950,7 @@ var OpenRouterImageModel = class {
4998
4950
  }
4999
4951
  };
5000
4952
  var DEFAULT_IMAGE_MEDIA_TYPE = "image/png";
5001
- function convertImageFileToContentPart(file) {
4953
+ function convertFileToInputReference(file) {
5002
4954
  if (file.type === "url") {
5003
4955
  return {
5004
4956
  type: "image_url",
@@ -5068,7 +5020,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
5068
5020
  }
5069
5021
 
5070
5022
  // src/version.ts
5071
- var VERSION2 = false ? "0.0.0-test" : "2.9.1";
5023
+ var VERSION2 = false ? "0.0.0-test" : "2.10.0";
5072
5024
 
5073
5025
  // src/video/schemas.ts
5074
5026
  import { z as z12 } from "zod/v4";