@llmgateway/ai-sdk-provider 3.2.1 → 3.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.mjs CHANGED
@@ -3585,6 +3585,79 @@ var LLMGateway = class {
3585
3585
  }
3586
3586
  };
3587
3587
 
3588
+ // src/image/index.ts
3589
+ import { z as z8 } from "zod/v4";
3590
+ var LLMGatewayImageResponseSchema = z8.object({
3591
+ data: z8.array(
3592
+ z8.object({
3593
+ b64_json: z8.string().optional(),
3594
+ url: z8.string().optional(),
3595
+ revised_prompt: z8.string().optional()
3596
+ })
3597
+ )
3598
+ });
3599
+ var LLMGatewayImageModel = class {
3600
+ constructor(modelId, settings, config) {
3601
+ this.specificationVersion = "v3";
3602
+ this.maxImagesPerCall = void 0;
3603
+ this.modelId = modelId;
3604
+ this.settings = settings;
3605
+ this.config = config;
3606
+ this.provider = config.provider;
3607
+ }
3608
+ async doGenerate(options) {
3609
+ const warnings = [];
3610
+ if (options.seed != null) {
3611
+ warnings.push({
3612
+ type: "unsupported",
3613
+ feature: "seed"
3614
+ });
3615
+ }
3616
+ const body = {
3617
+ model: this.modelId,
3618
+ prompt: options.prompt,
3619
+ n: options.n,
3620
+ response_format: "b64_json"
3621
+ };
3622
+ if (options.size != null) {
3623
+ body.size = options.size;
3624
+ }
3625
+ if (options.aspectRatio != null) {
3626
+ body.aspect_ratio = options.aspectRatio;
3627
+ }
3628
+ const { value: response, responseHeaders } = await postJsonToApi({
3629
+ url: this.config.url({
3630
+ path: "/images/generations",
3631
+ modelId: this.modelId
3632
+ }),
3633
+ headers: combineHeaders(this.config.headers(), options.headers),
3634
+ body,
3635
+ failedResponseHandler: llmgatewayFailedResponseHandler,
3636
+ successfulResponseHandler: createJsonResponseHandler(
3637
+ LLMGatewayImageResponseSchema
3638
+ ),
3639
+ abortSignal: options.abortSignal,
3640
+ fetch: this.config.fetch
3641
+ });
3642
+ return {
3643
+ images: response.data.map((item) => {
3644
+ if (item.b64_json) {
3645
+ return item.b64_json;
3646
+ }
3647
+ throw new Error(
3648
+ "Expected b64_json in response but got url. Set response_format to b64_json."
3649
+ );
3650
+ }),
3651
+ warnings,
3652
+ response: {
3653
+ timestamp: /* @__PURE__ */ new Date(),
3654
+ modelId: this.modelId,
3655
+ headers: responseHeaders
3656
+ }
3657
+ };
3658
+ }
3659
+ };
3660
+
3588
3661
  // src/provider.ts
3589
3662
  function createLLMGateway(options = {}) {
3590
3663
  var _a16, _b16, _c, _d;
@@ -3613,6 +3686,12 @@ function createLLMGateway(options = {}) {
3613
3686
  fetch: options.fetch,
3614
3687
  extraBody: options.extraBody
3615
3688
  });
3689
+ const createImageModel = (modelId, settings = {}) => new LLMGatewayImageModel(modelId, settings, {
3690
+ provider: "llmgateway.image",
3691
+ url: ({ path }) => `${baseURL}${path}`,
3692
+ headers: getHeaders,
3693
+ fetch: options.fetch
3694
+ });
3616
3695
  const createLanguageModel = (modelId, settings) => {
3617
3696
  if (new.target) {
3618
3697
  throw new Error(
@@ -3631,6 +3710,8 @@ function createLLMGateway(options = {}) {
3631
3710
  provider.languageModel = createLanguageModel;
3632
3711
  provider.chat = createChatModel;
3633
3712
  provider.completion = createCompletionModel;
3713
+ provider.image = createImageModel;
3714
+ provider.imageModel = createImageModel;
3634
3715
  return provider;
3635
3716
  }
3636
3717
  var llmgateway = createLLMGateway({