@openrouter/ai-sdk-provider 2.0.4 → 2.1.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.
@@ -1,7 +1,7 @@
1
- import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3Content, LanguageModelV3FinishReason, LanguageModelV3Usage, SharedV3Warning, LanguageModelV3ResponseMetadata, SharedV3Headers, LanguageModelV3StreamPart } from '@ai-sdk/provider';
1
+ import * as _ai_sdk_provider from '@ai-sdk/provider';
2
+ import { LanguageModelV3, LanguageModelV3CallOptions, EmbeddingModelV3, SharedV3ProviderMetadata, SharedV3Headers, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning, ImageModelV3ProviderMetadata, ImageModelV3Usage, LanguageModelV3Content, LanguageModelV3FinishReason, LanguageModelV3Usage, LanguageModelV3ResponseMetadata, LanguageModelV3StreamPart } from '@ai-sdk/provider';
2
3
  export { LanguageModelV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
3
4
  import { z } from 'zod/v4';
4
- import * as models from '@openrouter/sdk/models';
5
5
 
6
6
  declare enum ReasoningFormat {
7
7
  Unknown = "unknown",
@@ -38,6 +38,50 @@ declare const ReasoningDetailUnionSchema: z.ZodUnion<readonly [z.ZodObject<{
38
38
  }, z.core.$strip>]>;
39
39
  type ReasoningDetailUnion = z.infer<typeof ReasoningDetailUnionSchema>;
40
40
 
41
+ /**
42
+ * Plugin identifier for web search functionality.
43
+ */
44
+ type IdWeb = 'web';
45
+ /**
46
+ * Plugin identifier for file parsing functionality.
47
+ */
48
+ type IdFileParser = 'file-parser';
49
+ /**
50
+ * Plugin identifier for content moderation.
51
+ */
52
+ type IdModeration = 'moderation';
53
+ /**
54
+ * Plugin identifier for response healing.
55
+ * Automatically validates and repairs malformed JSON responses.
56
+ * @see https://openrouter.ai/docs/guides/features/plugins/response-healing
57
+ */
58
+ type IdResponseHealing = 'response-healing';
59
+ /**
60
+ * Search engine options for web search.
61
+ * Open enum - accepts known values or any string for forward compatibility.
62
+ */
63
+ type Engine = 'native' | 'exa' | (string & {});
64
+ /**
65
+ * PDF processing engine options.
66
+ * Open enum - accepts known values or any string for forward compatibility.
67
+ */
68
+ type PdfEngine = 'mistral-ocr' | 'pdf-text' | 'native' | (string & {});
69
+ /**
70
+ * Data collection preference for provider routing.
71
+ * Open enum - accepts known values or any string for forward compatibility.
72
+ */
73
+ type DataCollection = 'deny' | 'allow' | (string & {});
74
+ /**
75
+ * Model quantization levels for provider filtering.
76
+ * Open enum - accepts known values or any string for forward compatibility.
77
+ */
78
+ type Quantization = 'int4' | 'int8' | 'fp4' | 'fp6' | 'fp8' | 'fp16' | 'bf16' | 'fp32' | 'unknown' | (string & {});
79
+ /**
80
+ * Provider sorting strategy options.
81
+ * Open enum - accepts known values or any string for forward compatibility.
82
+ */
83
+ type ProviderSort = 'price' | 'throughput' | 'latency' | (string & {});
84
+
41
85
  type OpenRouterChatModelId = string;
42
86
  type OpenRouterChatSettings = {
43
87
  /**
@@ -80,18 +124,29 @@ type OpenRouterChatSettings = {
80
124
  * Plugin configurations for enabling various capabilities
81
125
  */
82
126
  plugins?: Array<{
83
- id: models.IdWeb;
127
+ id: IdWeb;
84
128
  max_results?: number;
85
129
  search_prompt?: string;
86
- engine?: models.Engine;
130
+ engine?: Engine;
87
131
  } | {
88
- id: models.IdFileParser;
132
+ id: IdFileParser;
89
133
  max_files?: number;
90
134
  pdf?: {
91
- engine?: models.PdfEngine;
135
+ engine?: PdfEngine;
92
136
  };
93
137
  } | {
94
- id: models.IdModeration;
138
+ id: IdModeration;
139
+ } | {
140
+ /**
141
+ * Response healing plugin - automatically validates and repairs malformed JSON responses.
142
+ *
143
+ * **Important:** This plugin only works with non-streaming requests (e.g., `generateObject`).
144
+ * It has no effect when used with streaming methods like `streamObject` or `streamText`.
145
+ * The plugin activates when using `response_format` with `json_schema` or `json_object`.
146
+ *
147
+ * @see https://openrouter.ai/docs/guides/features/plugins/response-healing
148
+ */
149
+ id: IdResponseHealing;
95
150
  }>;
96
151
  /**
97
152
  * Built-in web search options for models that support native web search
@@ -112,7 +167,7 @@ type OpenRouterChatSettings = {
112
167
  * - undefined: Native if supported, otherwise Exa
113
168
  * @see https://openrouter.ai/docs/features/web-search
114
169
  */
115
- engine?: models.Engine;
170
+ engine?: Engine;
116
171
  };
117
172
  /**
118
173
  * Debug options for troubleshooting API requests.
@@ -146,7 +201,7 @@ type OpenRouterChatSettings = {
146
201
  /**
147
202
  * Control whether to use providers that may store data
148
203
  */
149
- data_collection?: models.DataCollection;
204
+ data_collection?: DataCollection;
150
205
  /**
151
206
  * List of provider slugs to allow for this request
152
207
  */
@@ -158,11 +213,11 @@ type OpenRouterChatSettings = {
158
213
  /**
159
214
  * List of quantization levels to filter by (e.g. ["int4", "int8"])
160
215
  */
161
- quantizations?: Array<models.Quantization>;
216
+ quantizations?: Array<Quantization>;
162
217
  /**
163
218
  * Sort providers by price, throughput, or latency
164
219
  */
165
- sort?: models.ProviderSort;
220
+ sort?: ProviderSort;
166
221
  /**
167
222
  * Maximum pricing you want to pay for this request
168
223
  */
@@ -216,6 +271,52 @@ type OpenRouterCompletionSettings = {
216
271
  suffix?: string;
217
272
  } & OpenRouterSharedSettings;
218
273
 
274
+ type OpenRouterImageModelId = string;
275
+ type OpenRouterImageSettings = {
276
+ /**
277
+ * Provider routing preferences to control request routing behavior
278
+ */
279
+ provider?: {
280
+ /**
281
+ * List of provider slugs to try in order (e.g. ["google", "black-forest-labs"])
282
+ */
283
+ order?: string[];
284
+ /**
285
+ * Whether to allow backup providers when primary is unavailable (default: true)
286
+ */
287
+ allow_fallbacks?: boolean;
288
+ /**
289
+ * Only use providers that support all parameters in your request (default: false)
290
+ */
291
+ require_parameters?: boolean;
292
+ /**
293
+ * Control whether to use providers that may store data
294
+ */
295
+ data_collection?: 'allow' | 'deny';
296
+ /**
297
+ * List of provider slugs to allow for this request
298
+ */
299
+ only?: string[];
300
+ /**
301
+ * List of provider slugs to skip for this request
302
+ */
303
+ ignore?: string[];
304
+ /**
305
+ * Sort providers by price, throughput, or latency
306
+ */
307
+ sort?: 'price' | 'throughput' | 'latency';
308
+ /**
309
+ * Maximum pricing you want to pay for this request
310
+ */
311
+ max_price?: {
312
+ prompt?: number | string;
313
+ completion?: number | string;
314
+ image?: number | string;
315
+ request?: number | string;
316
+ };
317
+ };
318
+ } & OpenRouterSharedSettings;
319
+
219
320
  type OpenRouterCompletionConfig = {
220
321
  provider: string;
221
322
  compatibility: 'strict' | 'compatible';
@@ -242,6 +343,74 @@ declare class OpenRouterCompletionLanguageModel implements LanguageModelV3 {
242
343
  doStream(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
243
344
  }
244
345
 
346
+ type OpenRouterEmbeddingConfig = {
347
+ provider: string;
348
+ headers: () => Record<string, string | undefined>;
349
+ url: (options: {
350
+ modelId: string;
351
+ path: string;
352
+ }) => string;
353
+ fetch?: typeof fetch;
354
+ extraBody?: Record<string, unknown>;
355
+ };
356
+ declare class OpenRouterEmbeddingModel implements EmbeddingModelV3 {
357
+ readonly specificationVersion: "v3";
358
+ readonly provider = "openrouter";
359
+ readonly modelId: OpenRouterEmbeddingModelId;
360
+ readonly settings: OpenRouterEmbeddingSettings;
361
+ readonly maxEmbeddingsPerCall: undefined;
362
+ readonly supportsParallelCalls = true;
363
+ private readonly config;
364
+ constructor(modelId: OpenRouterEmbeddingModelId, settings: OpenRouterEmbeddingSettings, config: OpenRouterEmbeddingConfig);
365
+ doEmbed(options: {
366
+ values: Array<string>;
367
+ abortSignal?: AbortSignal;
368
+ headers?: Record<string, string | undefined>;
369
+ }): Promise<{
370
+ embeddings: Array<Array<number>>;
371
+ usage?: {
372
+ tokens: number;
373
+ };
374
+ providerMetadata?: SharedV3ProviderMetadata;
375
+ response?: {
376
+ headers?: SharedV3Headers;
377
+ body?: unknown;
378
+ };
379
+ warnings: Array<_ai_sdk_provider.SharedV3Warning>;
380
+ }>;
381
+ }
382
+
383
+ type OpenRouterImageConfig = {
384
+ provider: string;
385
+ headers: () => Record<string, string | undefined>;
386
+ url: (options: {
387
+ modelId: string;
388
+ path: string;
389
+ }) => string;
390
+ fetch?: typeof fetch;
391
+ extraBody?: Record<string, unknown>;
392
+ };
393
+ declare class OpenRouterImageModel implements ImageModelV3 {
394
+ readonly specificationVersion: "v3";
395
+ readonly provider = "openrouter";
396
+ readonly modelId: OpenRouterImageModelId;
397
+ readonly settings: OpenRouterImageSettings;
398
+ readonly maxImagesPerCall = 1;
399
+ private readonly config;
400
+ constructor(modelId: OpenRouterImageModelId, settings: OpenRouterImageSettings, config: OpenRouterImageConfig);
401
+ doGenerate(options: ImageModelV3CallOptions): Promise<{
402
+ images: Array<string>;
403
+ warnings: Array<SharedV3Warning>;
404
+ providerMetadata?: ImageModelV3ProviderMetadata;
405
+ response: {
406
+ timestamp: Date;
407
+ modelId: string;
408
+ headers: Record<string, string> | undefined;
409
+ };
410
+ usage?: ImageModelV3Usage;
411
+ }>;
412
+ }
413
+
245
414
  type OpenRouterEmbeddingModelId = string;
246
415
  type OpenRouterEmbeddingSettings = {
247
416
  /**
@@ -407,4 +576,4 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV3 {
407
576
  }>;
408
577
  }
409
578
 
410
- export { OpenRouterChatLanguageModel, type OpenRouterChatModelId, type OpenRouterChatSettings, OpenRouterCompletionLanguageModel, type OpenRouterCompletionModelId, type OpenRouterCompletionSettings, type OpenRouterEmbeddingModelId, type OpenRouterEmbeddingSettings, type OpenRouterProviderOptions, type OpenRouterSharedSettings, type OpenRouterUsageAccounting };
579
+ export { OpenRouterChatLanguageModel, type OpenRouterChatModelId, type OpenRouterChatSettings, OpenRouterCompletionLanguageModel, type OpenRouterCompletionModelId, type OpenRouterCompletionSettings, OpenRouterEmbeddingModel, type OpenRouterEmbeddingModelId, type OpenRouterEmbeddingSettings, OpenRouterImageModel, type OpenRouterImageModelId, type OpenRouterImageSettings, type OpenRouterProviderOptions, type OpenRouterSharedSettings, type OpenRouterUsageAccounting };
@@ -1,7 +1,7 @@
1
- import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3Content, LanguageModelV3FinishReason, LanguageModelV3Usage, SharedV3Warning, LanguageModelV3ResponseMetadata, SharedV3Headers, LanguageModelV3StreamPart } from '@ai-sdk/provider';
1
+ import * as _ai_sdk_provider from '@ai-sdk/provider';
2
+ import { LanguageModelV3, LanguageModelV3CallOptions, EmbeddingModelV3, SharedV3ProviderMetadata, SharedV3Headers, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning, ImageModelV3ProviderMetadata, ImageModelV3Usage, LanguageModelV3Content, LanguageModelV3FinishReason, LanguageModelV3Usage, LanguageModelV3ResponseMetadata, LanguageModelV3StreamPart } from '@ai-sdk/provider';
2
3
  export { LanguageModelV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
3
4
  import { z } from 'zod/v4';
4
- import * as models from '@openrouter/sdk/models';
5
5
 
6
6
  declare enum ReasoningFormat {
7
7
  Unknown = "unknown",
@@ -38,6 +38,50 @@ declare const ReasoningDetailUnionSchema: z.ZodUnion<readonly [z.ZodObject<{
38
38
  }, z.core.$strip>]>;
39
39
  type ReasoningDetailUnion = z.infer<typeof ReasoningDetailUnionSchema>;
40
40
 
41
+ /**
42
+ * Plugin identifier for web search functionality.
43
+ */
44
+ type IdWeb = 'web';
45
+ /**
46
+ * Plugin identifier for file parsing functionality.
47
+ */
48
+ type IdFileParser = 'file-parser';
49
+ /**
50
+ * Plugin identifier for content moderation.
51
+ */
52
+ type IdModeration = 'moderation';
53
+ /**
54
+ * Plugin identifier for response healing.
55
+ * Automatically validates and repairs malformed JSON responses.
56
+ * @see https://openrouter.ai/docs/guides/features/plugins/response-healing
57
+ */
58
+ type IdResponseHealing = 'response-healing';
59
+ /**
60
+ * Search engine options for web search.
61
+ * Open enum - accepts known values or any string for forward compatibility.
62
+ */
63
+ type Engine = 'native' | 'exa' | (string & {});
64
+ /**
65
+ * PDF processing engine options.
66
+ * Open enum - accepts known values or any string for forward compatibility.
67
+ */
68
+ type PdfEngine = 'mistral-ocr' | 'pdf-text' | 'native' | (string & {});
69
+ /**
70
+ * Data collection preference for provider routing.
71
+ * Open enum - accepts known values or any string for forward compatibility.
72
+ */
73
+ type DataCollection = 'deny' | 'allow' | (string & {});
74
+ /**
75
+ * Model quantization levels for provider filtering.
76
+ * Open enum - accepts known values or any string for forward compatibility.
77
+ */
78
+ type Quantization = 'int4' | 'int8' | 'fp4' | 'fp6' | 'fp8' | 'fp16' | 'bf16' | 'fp32' | 'unknown' | (string & {});
79
+ /**
80
+ * Provider sorting strategy options.
81
+ * Open enum - accepts known values or any string for forward compatibility.
82
+ */
83
+ type ProviderSort = 'price' | 'throughput' | 'latency' | (string & {});
84
+
41
85
  type OpenRouterChatModelId = string;
42
86
  type OpenRouterChatSettings = {
43
87
  /**
@@ -80,18 +124,29 @@ type OpenRouterChatSettings = {
80
124
  * Plugin configurations for enabling various capabilities
81
125
  */
82
126
  plugins?: Array<{
83
- id: models.IdWeb;
127
+ id: IdWeb;
84
128
  max_results?: number;
85
129
  search_prompt?: string;
86
- engine?: models.Engine;
130
+ engine?: Engine;
87
131
  } | {
88
- id: models.IdFileParser;
132
+ id: IdFileParser;
89
133
  max_files?: number;
90
134
  pdf?: {
91
- engine?: models.PdfEngine;
135
+ engine?: PdfEngine;
92
136
  };
93
137
  } | {
94
- id: models.IdModeration;
138
+ id: IdModeration;
139
+ } | {
140
+ /**
141
+ * Response healing plugin - automatically validates and repairs malformed JSON responses.
142
+ *
143
+ * **Important:** This plugin only works with non-streaming requests (e.g., `generateObject`).
144
+ * It has no effect when used with streaming methods like `streamObject` or `streamText`.
145
+ * The plugin activates when using `response_format` with `json_schema` or `json_object`.
146
+ *
147
+ * @see https://openrouter.ai/docs/guides/features/plugins/response-healing
148
+ */
149
+ id: IdResponseHealing;
95
150
  }>;
96
151
  /**
97
152
  * Built-in web search options for models that support native web search
@@ -112,7 +167,7 @@ type OpenRouterChatSettings = {
112
167
  * - undefined: Native if supported, otherwise Exa
113
168
  * @see https://openrouter.ai/docs/features/web-search
114
169
  */
115
- engine?: models.Engine;
170
+ engine?: Engine;
116
171
  };
117
172
  /**
118
173
  * Debug options for troubleshooting API requests.
@@ -146,7 +201,7 @@ type OpenRouterChatSettings = {
146
201
  /**
147
202
  * Control whether to use providers that may store data
148
203
  */
149
- data_collection?: models.DataCollection;
204
+ data_collection?: DataCollection;
150
205
  /**
151
206
  * List of provider slugs to allow for this request
152
207
  */
@@ -158,11 +213,11 @@ type OpenRouterChatSettings = {
158
213
  /**
159
214
  * List of quantization levels to filter by (e.g. ["int4", "int8"])
160
215
  */
161
- quantizations?: Array<models.Quantization>;
216
+ quantizations?: Array<Quantization>;
162
217
  /**
163
218
  * Sort providers by price, throughput, or latency
164
219
  */
165
- sort?: models.ProviderSort;
220
+ sort?: ProviderSort;
166
221
  /**
167
222
  * Maximum pricing you want to pay for this request
168
223
  */
@@ -216,6 +271,52 @@ type OpenRouterCompletionSettings = {
216
271
  suffix?: string;
217
272
  } & OpenRouterSharedSettings;
218
273
 
274
+ type OpenRouterImageModelId = string;
275
+ type OpenRouterImageSettings = {
276
+ /**
277
+ * Provider routing preferences to control request routing behavior
278
+ */
279
+ provider?: {
280
+ /**
281
+ * List of provider slugs to try in order (e.g. ["google", "black-forest-labs"])
282
+ */
283
+ order?: string[];
284
+ /**
285
+ * Whether to allow backup providers when primary is unavailable (default: true)
286
+ */
287
+ allow_fallbacks?: boolean;
288
+ /**
289
+ * Only use providers that support all parameters in your request (default: false)
290
+ */
291
+ require_parameters?: boolean;
292
+ /**
293
+ * Control whether to use providers that may store data
294
+ */
295
+ data_collection?: 'allow' | 'deny';
296
+ /**
297
+ * List of provider slugs to allow for this request
298
+ */
299
+ only?: string[];
300
+ /**
301
+ * List of provider slugs to skip for this request
302
+ */
303
+ ignore?: string[];
304
+ /**
305
+ * Sort providers by price, throughput, or latency
306
+ */
307
+ sort?: 'price' | 'throughput' | 'latency';
308
+ /**
309
+ * Maximum pricing you want to pay for this request
310
+ */
311
+ max_price?: {
312
+ prompt?: number | string;
313
+ completion?: number | string;
314
+ image?: number | string;
315
+ request?: number | string;
316
+ };
317
+ };
318
+ } & OpenRouterSharedSettings;
319
+
219
320
  type OpenRouterCompletionConfig = {
220
321
  provider: string;
221
322
  compatibility: 'strict' | 'compatible';
@@ -242,6 +343,74 @@ declare class OpenRouterCompletionLanguageModel implements LanguageModelV3 {
242
343
  doStream(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
243
344
  }
244
345
 
346
+ type OpenRouterEmbeddingConfig = {
347
+ provider: string;
348
+ headers: () => Record<string, string | undefined>;
349
+ url: (options: {
350
+ modelId: string;
351
+ path: string;
352
+ }) => string;
353
+ fetch?: typeof fetch;
354
+ extraBody?: Record<string, unknown>;
355
+ };
356
+ declare class OpenRouterEmbeddingModel implements EmbeddingModelV3 {
357
+ readonly specificationVersion: "v3";
358
+ readonly provider = "openrouter";
359
+ readonly modelId: OpenRouterEmbeddingModelId;
360
+ readonly settings: OpenRouterEmbeddingSettings;
361
+ readonly maxEmbeddingsPerCall: undefined;
362
+ readonly supportsParallelCalls = true;
363
+ private readonly config;
364
+ constructor(modelId: OpenRouterEmbeddingModelId, settings: OpenRouterEmbeddingSettings, config: OpenRouterEmbeddingConfig);
365
+ doEmbed(options: {
366
+ values: Array<string>;
367
+ abortSignal?: AbortSignal;
368
+ headers?: Record<string, string | undefined>;
369
+ }): Promise<{
370
+ embeddings: Array<Array<number>>;
371
+ usage?: {
372
+ tokens: number;
373
+ };
374
+ providerMetadata?: SharedV3ProviderMetadata;
375
+ response?: {
376
+ headers?: SharedV3Headers;
377
+ body?: unknown;
378
+ };
379
+ warnings: Array<_ai_sdk_provider.SharedV3Warning>;
380
+ }>;
381
+ }
382
+
383
+ type OpenRouterImageConfig = {
384
+ provider: string;
385
+ headers: () => Record<string, string | undefined>;
386
+ url: (options: {
387
+ modelId: string;
388
+ path: string;
389
+ }) => string;
390
+ fetch?: typeof fetch;
391
+ extraBody?: Record<string, unknown>;
392
+ };
393
+ declare class OpenRouterImageModel implements ImageModelV3 {
394
+ readonly specificationVersion: "v3";
395
+ readonly provider = "openrouter";
396
+ readonly modelId: OpenRouterImageModelId;
397
+ readonly settings: OpenRouterImageSettings;
398
+ readonly maxImagesPerCall = 1;
399
+ private readonly config;
400
+ constructor(modelId: OpenRouterImageModelId, settings: OpenRouterImageSettings, config: OpenRouterImageConfig);
401
+ doGenerate(options: ImageModelV3CallOptions): Promise<{
402
+ images: Array<string>;
403
+ warnings: Array<SharedV3Warning>;
404
+ providerMetadata?: ImageModelV3ProviderMetadata;
405
+ response: {
406
+ timestamp: Date;
407
+ modelId: string;
408
+ headers: Record<string, string> | undefined;
409
+ };
410
+ usage?: ImageModelV3Usage;
411
+ }>;
412
+ }
413
+
245
414
  type OpenRouterEmbeddingModelId = string;
246
415
  type OpenRouterEmbeddingSettings = {
247
416
  /**
@@ -407,4 +576,4 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV3 {
407
576
  }>;
408
577
  }
409
578
 
410
- export { OpenRouterChatLanguageModel, type OpenRouterChatModelId, type OpenRouterChatSettings, OpenRouterCompletionLanguageModel, type OpenRouterCompletionModelId, type OpenRouterCompletionSettings, type OpenRouterEmbeddingModelId, type OpenRouterEmbeddingSettings, type OpenRouterProviderOptions, type OpenRouterSharedSettings, type OpenRouterUsageAccounting };
579
+ export { OpenRouterChatLanguageModel, type OpenRouterChatModelId, type OpenRouterChatSettings, OpenRouterCompletionLanguageModel, type OpenRouterCompletionModelId, type OpenRouterCompletionSettings, OpenRouterEmbeddingModel, type OpenRouterEmbeddingModelId, type OpenRouterEmbeddingSettings, OpenRouterImageModel, type OpenRouterImageModelId, type OpenRouterImageSettings, type OpenRouterProviderOptions, type OpenRouterSharedSettings, type OpenRouterUsageAccounting };