@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.
@@ -4725,26 +4725,10 @@ var OpenRouterEmbeddingModel = class {
4725
4725
  // src/image/schemas.ts
4726
4726
  import { z as z10 } from "zod/v4";
4727
4727
  var OpenRouterImageResponseSchema = z10.object({
4728
- id: z10.string().optional(),
4729
- object: z10.string().optional(),
4730
4728
  created: z10.number().optional(),
4731
- model: z10.string(),
4732
- choices: z10.array(
4729
+ data: z10.array(
4733
4730
  z10.object({
4734
- index: z10.number(),
4735
- message: z10.object({
4736
- role: z10.string(),
4737
- content: z10.string().nullable().optional(),
4738
- images: z10.array(
4739
- z10.object({
4740
- type: z10.literal("image_url"),
4741
- image_url: z10.object({
4742
- url: z10.string()
4743
- })
4744
- }).passthrough()
4745
- ).optional()
4746
- }).passthrough(),
4747
- finish_reason: z10.string().nullable().optional()
4731
+ b64_json: z10.string()
4748
4732
  }).passthrough()
4749
4733
  ),
4750
4734
  usage: z10.object({
@@ -4759,13 +4743,12 @@ var OpenRouterImageModel = class {
4759
4743
  constructor(modelId, settings, config) {
4760
4744
  this.specificationVersion = "v3";
4761
4745
  this.provider = "openrouter";
4762
- this.maxImagesPerCall = 1;
4746
+ this.maxImagesPerCall = 10;
4763
4747
  this.modelId = modelId;
4764
4748
  this.settings = settings;
4765
4749
  this.config = config;
4766
4750
  }
4767
4751
  async doGenerate(options) {
4768
- var _a16;
4769
4752
  const {
4770
4753
  prompt,
4771
4754
  n,
@@ -4785,43 +4768,19 @@ var OpenRouterImageModel = class {
4785
4768
  functionality: "image inpainting (mask parameter)"
4786
4769
  });
4787
4770
  }
4788
- if (n > 1) {
4789
- warnings.push({
4790
- type: "unsupported",
4791
- feature: "n > 1",
4792
- details: `OpenRouter image generation returns 1 image per call. Requested ${n} images.`
4793
- });
4794
- }
4795
- if (size !== void 0) {
4796
- warnings.push({
4797
- type: "unsupported",
4798
- feature: "size",
4799
- details: "Use aspectRatio instead. Size parameter is not supported by OpenRouter image generation."
4800
- });
4801
- }
4802
- const imageConfig = aspectRatio !== void 0 ? { aspect_ratio: aspectRatio } : void 0;
4803
4771
  const hasFiles = files !== void 0 && files.length > 0;
4804
- const userContent = hasFiles ? [
4805
- ...files.map(
4806
- (file) => convertImageFileToContentPart(file)
4807
- ),
4808
- { type: "text", text: prompt != null ? prompt : "" }
4809
- ] : prompt != null ? prompt : "";
4810
- const body = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
4772
+ const inputReferences = hasFiles ? files.map((file) => convertFileToInputReference(file)) : void 0;
4773
+ const body = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
4811
4774
  model: this.modelId,
4812
- messages: [
4813
- {
4814
- role: "user",
4815
- content: userContent
4816
- }
4817
- ],
4818
- modalities: ["image", "text"]
4819
- }, imageConfig !== void 0 && { image_config: imageConfig }), seed !== void 0 && { seed }), this.settings.user !== void 0 && { user: this.settings.user }), this.settings.provider !== void 0 && {
4775
+ prompt: prompt != null ? prompt : ""
4776
+ }, n !== void 0 && { n }), size !== void 0 && { size }), aspectRatio !== void 0 && { aspect_ratio: aspectRatio }), seed !== void 0 && { seed }), inputReferences !== void 0 && {
4777
+ input_references: inputReferences
4778
+ }), this.settings.user !== void 0 && { user: this.settings.user }), this.settings.provider !== void 0 && {
4820
4779
  provider: this.settings.provider
4821
4780
  }), this.config.extraBody), this.settings.extraBody), openrouterOptions);
4822
4781
  const { value: responseValue, responseHeaders } = await postJsonToApi({
4823
4782
  url: this.config.url({
4824
- path: "/chat/completions",
4783
+ path: "/images",
4825
4784
  modelId: this.modelId
4826
4785
  }),
4827
4786
  headers: combineHeaders(this.config.headers(), headers),
@@ -4833,19 +4792,12 @@ var OpenRouterImageModel = class {
4833
4792
  abortSignal,
4834
4793
  fetch: this.config.fetch
4835
4794
  });
4836
- const choice = responseValue.choices[0];
4837
- if (!choice) {
4795
+ if (!responseValue.data || responseValue.data.length === 0) {
4838
4796
  throw new NoContentGeneratedError({
4839
- message: "No choice in response"
4797
+ message: "No images in response"
4840
4798
  });
4841
4799
  }
4842
- const images = [];
4843
- if ((_a16 = choice.message) == null ? void 0 : _a16.images) {
4844
- for (const image of choice.message.images) {
4845
- const dataUrl = image.image_url.url;
4846
- images.push(getBase64FromDataUrl(dataUrl));
4847
- }
4848
- }
4800
+ const images = responseValue.data.map((item) => item.b64_json);
4849
4801
  const usage = responseValue.usage ? {
4850
4802
  inputTokens: responseValue.usage.prompt_tokens,
4851
4803
  outputTokens: responseValue.usage.completion_tokens,
@@ -4856,7 +4808,7 @@ var OpenRouterImageModel = class {
4856
4808
  warnings,
4857
4809
  response: {
4858
4810
  timestamp: /* @__PURE__ */ new Date(),
4859
- modelId: responseValue.model,
4811
+ modelId: this.modelId,
4860
4812
  headers: responseHeaders
4861
4813
  },
4862
4814
  usage
@@ -4864,7 +4816,7 @@ var OpenRouterImageModel = class {
4864
4816
  }
4865
4817
  };
4866
4818
  var DEFAULT_IMAGE_MEDIA_TYPE = "image/png";
4867
- function convertImageFileToContentPart(file) {
4819
+ function convertFileToInputReference(file) {
4868
4820
  if (file.type === "url") {
4869
4821
  return {
4870
4822
  type: "image_url",