@ai-sdk/openai-compatible 3.0.74 → 3.0.76

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.
@@ -11,6 +11,9 @@ import {
11
11
  warnIfDeprecatedProviderOptionsKey,
12
12
  } from '../utils/to-camel-case';
13
13
  import {
14
+ lazySchema,
15
+ zodSchema,
16
+ type InferSchema,
14
17
  combineHeaders,
15
18
  convertBase64ToUint8Array,
16
19
  convertToFormData,
@@ -213,7 +216,7 @@ export class OpenAICompatibleImageModel implements ImageModelV4 {
213
216
  }
214
217
 
215
218
  private async getImages(
216
- data: z.infer<typeof openaiCompatibleImageResponseSchema>['data'],
219
+ data: InferSchema<typeof openaiCompatibleImageResponseSchema>['data'],
217
220
  options: {
218
221
  url: string;
219
222
  headers: Record<string, string | undefined>;
@@ -258,7 +261,7 @@ export class OpenAICompatibleImageModel implements ImageModelV4 {
258
261
  // Providers that omit `usage` are not warned about: many OpenAI-compatible
259
262
  // backends legitimately do not report token counts for image generation.
260
263
  function mapImageUsage(
261
- usage: z.infer<typeof openaiCompatibleImageResponseSchema>['usage'],
264
+ usage: InferSchema<typeof openaiCompatibleImageResponseSchema>['usage'],
262
265
  ): ImageModelV4Usage | undefined {
263
266
  return usage == null
264
267
  ? undefined
@@ -271,25 +274,29 @@ function mapImageUsage(
271
274
 
272
275
  // minimal version of the schema, focussed on what is needed for the implementation
273
276
  // this approach limits breakages when the API changes and increases efficiency
274
- const openaiCompatibleImageResponseSchema = z.object({
275
- data: z.array(
276
- z
277
- .object({
278
- b64_json: z.string().nullish(),
279
- url: z.string().nullish(),
280
- })
281
- .refine(image => image.b64_json != null || image.url != null, {
282
- message: 'Expected b64_json or url in the image response',
283
- }),
277
+ const openaiCompatibleImageResponseSchema = lazySchema(() =>
278
+ zodSchema(
279
+ z.object({
280
+ data: z.array(
281
+ z
282
+ .object({
283
+ b64_json: z.string().nullish(),
284
+ url: z.string().nullish(),
285
+ })
286
+ .refine(image => image.b64_json != null || image.url != null, {
287
+ message: 'Expected b64_json or url in the image response',
288
+ }),
289
+ ),
290
+ usage: z
291
+ .object({
292
+ input_tokens: z.number().nullish(),
293
+ output_tokens: z.number().nullish(),
294
+ total_tokens: z.number().nullish(),
295
+ })
296
+ .nullish(),
297
+ }),
284
298
  ),
285
- usage: z
286
- .object({
287
- input_tokens: z.number().nullish(),
288
- output_tokens: z.number().nullish(),
289
- total_tokens: z.number().nullish(),
290
- })
291
- .nullish(),
292
- });
299
+ );
293
300
 
294
301
  type OpenAICompatibleFormDataInput = {
295
302
  model: string;