@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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -64
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +15 -63
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +15 -63
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -474,7 +474,7 @@ declare class OpenRouterImageModel implements ImageModelV3 {
|
|
|
474
474
|
readonly provider = "openrouter";
|
|
475
475
|
readonly modelId: OpenRouterImageModelId;
|
|
476
476
|
readonly settings: OpenRouterImageSettings;
|
|
477
|
-
readonly maxImagesPerCall =
|
|
477
|
+
readonly maxImagesPerCall = 10;
|
|
478
478
|
private readonly config;
|
|
479
479
|
constructor(modelId: OpenRouterImageModelId, settings: OpenRouterImageSettings, config: OpenRouterImageConfig);
|
|
480
480
|
doGenerate(options: ImageModelV3CallOptions): Promise<{
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -474,7 +474,7 @@ declare class OpenRouterImageModel implements ImageModelV3 {
|
|
|
474
474
|
readonly provider = "openrouter";
|
|
475
475
|
readonly modelId: OpenRouterImageModelId;
|
|
476
476
|
readonly settings: OpenRouterImageSettings;
|
|
477
|
-
readonly maxImagesPerCall =
|
|
477
|
+
readonly maxImagesPerCall = 10;
|
|
478
478
|
private readonly config;
|
|
479
479
|
constructor(modelId: OpenRouterImageModelId, settings: OpenRouterImageSettings, config: OpenRouterImageConfig);
|
|
480
480
|
doGenerate(options: ImageModelV3CallOptions): Promise<{
|
package/dist/internal/index.js
CHANGED
|
@@ -4760,26 +4760,10 @@ var OpenRouterEmbeddingModel = class {
|
|
|
4760
4760
|
// src/image/schemas.ts
|
|
4761
4761
|
var import_v49 = require("zod/v4");
|
|
4762
4762
|
var OpenRouterImageResponseSchema = import_v49.z.object({
|
|
4763
|
-
id: import_v49.z.string().optional(),
|
|
4764
|
-
object: import_v49.z.string().optional(),
|
|
4765
4763
|
created: import_v49.z.number().optional(),
|
|
4766
|
-
|
|
4767
|
-
choices: import_v49.z.array(
|
|
4764
|
+
data: import_v49.z.array(
|
|
4768
4765
|
import_v49.z.object({
|
|
4769
|
-
|
|
4770
|
-
message: import_v49.z.object({
|
|
4771
|
-
role: import_v49.z.string(),
|
|
4772
|
-
content: import_v49.z.string().nullable().optional(),
|
|
4773
|
-
images: import_v49.z.array(
|
|
4774
|
-
import_v49.z.object({
|
|
4775
|
-
type: import_v49.z.literal("image_url"),
|
|
4776
|
-
image_url: import_v49.z.object({
|
|
4777
|
-
url: import_v49.z.string()
|
|
4778
|
-
})
|
|
4779
|
-
}).passthrough()
|
|
4780
|
-
).optional()
|
|
4781
|
-
}).passthrough(),
|
|
4782
|
-
finish_reason: import_v49.z.string().nullable().optional()
|
|
4766
|
+
b64_json: import_v49.z.string()
|
|
4783
4767
|
}).passthrough()
|
|
4784
4768
|
),
|
|
4785
4769
|
usage: import_v49.z.object({
|
|
@@ -4794,13 +4778,12 @@ var OpenRouterImageModel = class {
|
|
|
4794
4778
|
constructor(modelId, settings, config) {
|
|
4795
4779
|
this.specificationVersion = "v3";
|
|
4796
4780
|
this.provider = "openrouter";
|
|
4797
|
-
this.maxImagesPerCall =
|
|
4781
|
+
this.maxImagesPerCall = 10;
|
|
4798
4782
|
this.modelId = modelId;
|
|
4799
4783
|
this.settings = settings;
|
|
4800
4784
|
this.config = config;
|
|
4801
4785
|
}
|
|
4802
4786
|
async doGenerate(options) {
|
|
4803
|
-
var _a16;
|
|
4804
4787
|
const {
|
|
4805
4788
|
prompt,
|
|
4806
4789
|
n,
|
|
@@ -4820,43 +4803,19 @@ var OpenRouterImageModel = class {
|
|
|
4820
4803
|
functionality: "image inpainting (mask parameter)"
|
|
4821
4804
|
});
|
|
4822
4805
|
}
|
|
4823
|
-
if (n > 1) {
|
|
4824
|
-
warnings.push({
|
|
4825
|
-
type: "unsupported",
|
|
4826
|
-
feature: "n > 1",
|
|
4827
|
-
details: `OpenRouter image generation returns 1 image per call. Requested ${n} images.`
|
|
4828
|
-
});
|
|
4829
|
-
}
|
|
4830
|
-
if (size !== void 0) {
|
|
4831
|
-
warnings.push({
|
|
4832
|
-
type: "unsupported",
|
|
4833
|
-
feature: "size",
|
|
4834
|
-
details: "Use aspectRatio instead. Size parameter is not supported by OpenRouter image generation."
|
|
4835
|
-
});
|
|
4836
|
-
}
|
|
4837
|
-
const imageConfig = aspectRatio !== void 0 ? { aspect_ratio: aspectRatio } : void 0;
|
|
4838
4806
|
const hasFiles = files !== void 0 && files.length > 0;
|
|
4839
|
-
const
|
|
4840
|
-
|
|
4841
|
-
(file) => convertImageFileToContentPart(file)
|
|
4842
|
-
),
|
|
4843
|
-
{ type: "text", text: prompt != null ? prompt : "" }
|
|
4844
|
-
] : prompt != null ? prompt : "";
|
|
4845
|
-
const body = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
4807
|
+
const inputReferences = hasFiles ? files.map((file) => convertFileToInputReference(file)) : void 0;
|
|
4808
|
+
const body = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
4846
4809
|
model: this.modelId,
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
}
|
|
4852
|
-
],
|
|
4853
|
-
modalities: ["image", "text"]
|
|
4854
|
-
}, imageConfig !== void 0 && { image_config: imageConfig }), seed !== void 0 && { seed }), this.settings.user !== void 0 && { user: this.settings.user }), this.settings.provider !== void 0 && {
|
|
4810
|
+
prompt: prompt != null ? prompt : ""
|
|
4811
|
+
}, n !== void 0 && { n }), size !== void 0 && { size }), aspectRatio !== void 0 && { aspect_ratio: aspectRatio }), seed !== void 0 && { seed }), inputReferences !== void 0 && {
|
|
4812
|
+
input_references: inputReferences
|
|
4813
|
+
}), this.settings.user !== void 0 && { user: this.settings.user }), this.settings.provider !== void 0 && {
|
|
4855
4814
|
provider: this.settings.provider
|
|
4856
4815
|
}), this.config.extraBody), this.settings.extraBody), openrouterOptions);
|
|
4857
4816
|
const { value: responseValue, responseHeaders } = await postJsonToApi({
|
|
4858
4817
|
url: this.config.url({
|
|
4859
|
-
path: "/
|
|
4818
|
+
path: "/images",
|
|
4860
4819
|
modelId: this.modelId
|
|
4861
4820
|
}),
|
|
4862
4821
|
headers: combineHeaders(this.config.headers(), headers),
|
|
@@ -4868,19 +4827,12 @@ var OpenRouterImageModel = class {
|
|
|
4868
4827
|
abortSignal,
|
|
4869
4828
|
fetch: this.config.fetch
|
|
4870
4829
|
});
|
|
4871
|
-
|
|
4872
|
-
if (!choice) {
|
|
4830
|
+
if (!responseValue.data || responseValue.data.length === 0) {
|
|
4873
4831
|
throw new NoContentGeneratedError({
|
|
4874
|
-
message: "No
|
|
4832
|
+
message: "No images in response"
|
|
4875
4833
|
});
|
|
4876
4834
|
}
|
|
4877
|
-
const images =
|
|
4878
|
-
if ((_a16 = choice.message) == null ? void 0 : _a16.images) {
|
|
4879
|
-
for (const image of choice.message.images) {
|
|
4880
|
-
const dataUrl = image.image_url.url;
|
|
4881
|
-
images.push(getBase64FromDataUrl(dataUrl));
|
|
4882
|
-
}
|
|
4883
|
-
}
|
|
4835
|
+
const images = responseValue.data.map((item) => item.b64_json);
|
|
4884
4836
|
const usage = responseValue.usage ? {
|
|
4885
4837
|
inputTokens: responseValue.usage.prompt_tokens,
|
|
4886
4838
|
outputTokens: responseValue.usage.completion_tokens,
|
|
@@ -4891,7 +4843,7 @@ var OpenRouterImageModel = class {
|
|
|
4891
4843
|
warnings,
|
|
4892
4844
|
response: {
|
|
4893
4845
|
timestamp: /* @__PURE__ */ new Date(),
|
|
4894
|
-
modelId:
|
|
4846
|
+
modelId: this.modelId,
|
|
4895
4847
|
headers: responseHeaders
|
|
4896
4848
|
},
|
|
4897
4849
|
usage
|
|
@@ -4899,7 +4851,7 @@ var OpenRouterImageModel = class {
|
|
|
4899
4851
|
}
|
|
4900
4852
|
};
|
|
4901
4853
|
var DEFAULT_IMAGE_MEDIA_TYPE = "image/png";
|
|
4902
|
-
function
|
|
4854
|
+
function convertFileToInputReference(file) {
|
|
4903
4855
|
if (file.type === "url") {
|
|
4904
4856
|
return {
|
|
4905
4857
|
type: "image_url",
|