@openrouter/ai-sdk-provider 1.5.4 → 6.0.0-alpha.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.ts CHANGED
@@ -1,552 +1,390 @@
1
- import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart, EmbeddingModelV2, SharedV2ProviderMetadata, ProviderV2 } from '@ai-sdk/provider';
2
- export { LanguageModelV2, LanguageModelV2Prompt } from '@ai-sdk/provider';
3
- import * as models from '@openrouter/sdk/models';
4
- import { z } from 'zod/v4';
1
+ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, EmbeddingModelV3, EmbeddingModelV3CallOptions, EmbeddingModelV3Result, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning, ProviderV3 } from '@ai-sdk/provider';
5
2
 
6
- type OpenRouterChatModelId = string;
7
- type OpenRouterChatSettings = {
8
- /**
9
- Modify the likelihood of specified tokens appearing in the completion.
10
-
11
- Accepts a JSON object that maps tokens (specified by their token ID in
12
- the GPT tokenizer) to an associated bias value from -100 to 100. You
13
- can use this tokenizer tool to convert text to token IDs. Mathematically,
14
- the bias is added to the logits generated by the model prior to sampling.
15
- The exact effect will vary per model, but values between -1 and 1 should
16
- decrease or increase likelihood of selection; values like -100 or 100
17
- should result in a ban or exclusive selection of the relevant token.
18
-
19
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
20
- token from being generated.
21
- */
22
- logitBias?: Record<number, number>;
23
- /**
24
- Return the log probabilities of the tokens. Including logprobs will increase
25
- the response size and can slow down response times. However, it can
26
- be useful to understand better how the model is behaving.
27
-
28
- Setting to true will return the log probabilities of the tokens that
29
- were generated.
30
-
31
- Setting to a number will return the log probabilities of the top n
32
- tokens that were generated.
33
- */
34
- logprobs?: boolean | number;
35
- /**
36
- Whether to enable parallel function calling during tool use. Default to true.
37
- */
38
- parallelToolCalls?: boolean;
39
- /**
40
- A unique identifier representing your end-user, which can help OpenRouter to
41
- monitor and detect abuse. Learn more.
42
- */
43
- user?: string;
44
- /**
45
- * Plugin configurations for enabling various capabilities
46
- */
47
- plugins?: Array<{
48
- id: models.IdWeb;
49
- max_results?: number;
50
- search_prompt?: string;
51
- engine?: models.Engine;
52
- } | {
53
- id: models.IdFileParser;
54
- max_files?: number;
55
- pdf?: {
56
- engine?: models.PdfEngine;
57
- };
58
- } | {
59
- id: models.IdModeration;
60
- }>;
3
+ /**
4
+ * OpenRouter chat language model implementing AI SDK V3 LanguageModelV3 interface.
5
+ *
6
+ * Uses the OpenRouter Responses API for both streaming and non-streaming requests.
7
+ */
8
+ declare class OpenRouterChatLanguageModel implements LanguageModelV3 {
9
+ readonly specificationVersion: "v3";
10
+ readonly provider = "openrouter";
11
+ readonly modelId: string;
12
+ private readonly settings;
61
13
  /**
62
- * Built-in web search options for models that support native web search
14
+ * Supported URL patterns by media type.
15
+ * OpenRouter Chat API only supports image URLs natively.
16
+ * PDF URLs are not supported - use PDF data URIs or the Responses API instead.
63
17
  */
64
- web_search_options?: {
65
- /**
66
- * Maximum number of search results to include
67
- */
68
- max_results?: number;
69
- /**
70
- * Custom search prompt to guide the search query
71
- */
72
- search_prompt?: string;
73
- /**
74
- * Search engine to use for web search
75
- * - "native": Use provider's built-in web search
76
- * - "exa": Use Exa's search API
77
- * - undefined: Native if supported, otherwise Exa
78
- * @see https://openrouter.ai/docs/features/web-search
79
- */
80
- engine?: models.Engine;
81
- };
18
+ readonly supportedUrls: Record<string, RegExp[]>;
19
+ constructor(modelId: string, settings: OpenRouterModelSettings);
20
+ doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
21
+ doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
22
+ }
23
+
24
+ /**
25
+ * OpenRouter embedding model implementing AI SDK V3 EmbeddingModelV3 interface.
26
+ */
27
+ declare class OpenRouterEmbeddingModel implements EmbeddingModelV3 {
28
+ readonly specificationVersion: "v3";
29
+ readonly provider = "openrouter";
30
+ readonly modelId: string;
31
+ private readonly settings;
82
32
  /**
83
- * Debug options for troubleshooting API requests.
84
- * Only works with streaming requests.
85
- * @see https://openrouter.ai/docs/api-reference/debugging
33
+ * Maximum number of embeddings that can be generated in a single API call.
34
+ * Set to 2048 as a reasonable default for most embedding models.
86
35
  */
87
- debug?: {
88
- /**
89
- * When true, echoes back the request body that was sent to the upstream provider.
90
- * The debug data will be returned as the first chunk in the stream with a `debug.echo_upstream_body` field.
91
- * Sensitive data like user IDs and base64 content will be redacted.
92
- */
93
- echo_upstream_body?: boolean;
94
- };
36
+ readonly maxEmbeddingsPerCall = 2048;
95
37
  /**
96
- * Provider routing preferences to control request routing behavior
38
+ * Whether the model supports parallel calls.
97
39
  */
98
- provider?: {
99
- /**
100
- * List of provider slugs to try in order (e.g. ["anthropic", "openai"])
101
- */
102
- order?: string[];
103
- /**
104
- * Whether to allow backup providers when primary is unavailable (default: true)
105
- */
106
- allow_fallbacks?: boolean;
107
- /**
108
- * Only use providers that support all parameters in your request (default: false)
109
- */
110
- require_parameters?: boolean;
111
- /**
112
- * Control whether to use providers that may store data
113
- */
114
- data_collection?: models.DataCollection;
115
- /**
116
- * List of provider slugs to allow for this request
117
- */
118
- only?: string[];
119
- /**
120
- * List of provider slugs to skip for this request
121
- */
122
- ignore?: string[];
123
- /**
124
- * List of quantization levels to filter by (e.g. ["int4", "int8"])
125
- */
126
- quantizations?: Array<models.Quantization>;
127
- /**
128
- * Sort providers by price, throughput, or latency
129
- */
130
- sort?: models.ProviderSort;
131
- /**
132
- * Maximum pricing you want to pay for this request
133
- */
134
- max_price?: {
135
- prompt?: number | string;
136
- completion?: number | string;
137
- image?: number | string;
138
- audio?: number | string;
139
- request?: number | string;
40
+ readonly supportsParallelCalls = true;
41
+ constructor(modelId: string, settings: OpenRouterModelSettings);
42
+ doEmbed(options: EmbeddingModelV3CallOptions): Promise<EmbeddingModelV3Result>;
43
+ }
44
+
45
+ /**
46
+ * OpenRouter image model implementing AI SDK V3 ImageModelV3 interface.
47
+ *
48
+ * Note: Image generation is Tier 3 functionality. The doGenerate method
49
+ * throws an error with guidance on tracking progress.
50
+ */
51
+ declare class OpenRouterImageModel implements ImageModelV3 {
52
+ readonly specificationVersion: "v3";
53
+ readonly provider = "openrouter";
54
+ readonly modelId: string;
55
+ /**
56
+ * Maximum number of images that can be generated in a single API call.
57
+ */
58
+ readonly maxImagesPerCall = 1;
59
+ constructor(modelId: string, _settings: unknown);
60
+ doGenerate(_options: ImageModelV3CallOptions): Promise<{
61
+ images: Array<string> | Array<Uint8Array>;
62
+ warnings: Array<SharedV3Warning>;
63
+ response: {
64
+ timestamp: Date;
65
+ modelId: string;
66
+ headers: Record<string, string> | undefined;
140
67
  };
141
- /**
142
- * Whether to restrict routing to only ZDR (Zero Data Retention) endpoints.
143
- * When true, only endpoints that do not retain prompts will be used.
144
- */
145
- zdr?: boolean;
146
- };
147
- } & OpenRouterSharedSettings;
68
+ }>;
69
+ }
148
70
 
149
- type OpenRouterEmbeddingModelId = string;
150
- type OpenRouterEmbeddingSettings = {
71
+ /**
72
+ * Settings for configuring an OpenRouter provider instance.
73
+ *
74
+ * @description
75
+ * Configuration options passed to `createOpenRouter()` to customize the provider behavior.
76
+ * All settings are optional - the provider will use sensible defaults and environment
77
+ * variables when settings are not explicitly provided.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * import { createOpenRouter } from '@openrouter/ai-sdk-provider';
82
+ *
83
+ * const openrouter = createOpenRouter({
84
+ * apiKey: process.env.OPENROUTER_API_KEY,
85
+ * baseURL: 'https://openrouter.ai/api/v1',
86
+ * headers: {
87
+ * 'X-Title': 'My App',
88
+ * 'HTTP-Referer': 'https://myapp.com',
89
+ * },
90
+ * });
91
+ * ```
92
+ */
93
+ interface OpenRouterProviderSettings {
151
94
  /**
152
- * A unique identifier representing your end-user, which can help OpenRouter to
153
- * monitor and detect abuse.
95
+ * API key for OpenRouter. If not provided, will use OPENROUTER_API_KEY env var.
154
96
  */
155
- user?: string;
97
+ apiKey?: string;
156
98
  /**
157
- * Provider routing preferences to control request routing behavior
99
+ * Base URL for the OpenRouter API.
100
+ * @default 'https://openrouter.ai/api/v1'
158
101
  */
159
- provider?: {
160
- /**
161
- * List of provider slugs to try in order (e.g. ["openai", "voyageai"])
162
- */
163
- order?: string[];
164
- /**
165
- * Whether to allow backup providers when primary is unavailable (default: true)
166
- */
167
- allow_fallbacks?: boolean;
168
- /**
169
- * Only use providers that support all parameters in your request (default: false)
170
- */
171
- require_parameters?: boolean;
172
- /**
173
- * Control whether to use providers that may store data
174
- */
175
- data_collection?: 'allow' | 'deny';
176
- /**
177
- * List of provider slugs to allow for this request
178
- */
179
- only?: string[];
180
- /**
181
- * List of provider slugs to skip for this request
182
- */
183
- ignore?: string[];
184
- /**
185
- * Sort providers by price, throughput, or latency
186
- */
187
- sort?: 'price' | 'throughput' | 'latency';
188
- /**
189
- * Maximum pricing you want to pay for this request
190
- */
191
- max_price?: {
192
- prompt?: number | string;
193
- completion?: number | string;
194
- image?: number | string;
195
- audio?: number | string;
196
- request?: number | string;
197
- };
198
- };
199
- } & OpenRouterSharedSettings;
200
-
201
- type OpenRouterProviderOptions = {
202
- models?: string[];
102
+ baseURL?: string;
203
103
  /**
204
- * https://openrouter.ai/docs/use-cases/reasoning-tokens
205
- * One of `max_tokens` or `effort` is required.
206
- * If `exclude` is true, reasoning will be removed from the response. Default is false.
104
+ * Base URL for the OpenRouter API (alias for baseURL).
105
+ * @default 'https://openrouter.ai/api/v1'
106
+ * @deprecated Use baseURL instead.
207
107
  */
208
- reasoning?: {
209
- enabled?: boolean;
210
- exclude?: boolean;
211
- } & ({
212
- max_tokens: number;
213
- } | {
214
- effort: 'high' | 'medium' | 'low';
215
- });
108
+ baseUrl?: string;
216
109
  /**
217
- * A unique identifier representing your end-user, which can
218
- * help OpenRouter to monitor and detect abuse.
110
+ * Custom headers to include in all requests.
219
111
  */
220
- user?: string;
221
- };
222
- type OpenRouterSharedSettings = OpenRouterProviderOptions & {
112
+ headers?: Record<string, string>;
223
113
  /**
224
- * @deprecated use `reasoning` instead
114
+ * Custom fetch implementation.
225
115
  */
226
- includeReasoning?: boolean;
227
- extraBody?: Record<string, unknown>;
116
+ fetch?: typeof globalThis.fetch;
228
117
  /**
229
- * Enable usage accounting to get detailed token usage information.
230
- * https://openrouter.ai/docs/use-cases/usage-accounting
118
+ * Extra body parameters to include in all requests.
231
119
  */
232
- usage?: {
233
- /**
234
- * When true, includes token usage information in the response.
235
- */
236
- include: boolean;
237
- };
238
- };
239
- /**
240
- * Usage accounting response
241
- * @see https://openrouter.ai/docs/use-cases/usage-accounting
242
- */
243
- type OpenRouterUsageAccounting = {
244
- promptTokens: number;
245
- promptTokensDetails?: {
246
- cachedTokens: number;
247
- };
248
- completionTokens: number;
249
- completionTokensDetails?: {
250
- reasoningTokens: number;
251
- };
252
- totalTokens: number;
253
- cost?: number;
254
- costDetails?: {
255
- upstreamInferenceCost: number;
256
- };
257
- };
258
-
259
- type OpenRouterCompletionModelId = string;
260
- type OpenRouterCompletionSettings = {
261
- /**
262
- Modify the likelihood of specified tokens appearing in the completion.
263
-
264
- Accepts a JSON object that maps tokens (specified by their token ID in
265
- the GPT tokenizer) to an associated bias value from -100 to 100. You
266
- can use this tokenizer tool to convert text to token IDs. Mathematically,
267
- the bias is added to the logits generated by the model prior to sampling.
268
- The exact effect will vary per model, but values between -1 and 1 should
269
- decrease or increase likelihood of selection; values like -100 or 100
270
- should result in a ban or exclusive selection of the relevant token.
271
-
272
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
273
- token from being generated.
274
- */
275
- logitBias?: Record<number, number>;
276
- /**
277
- Return the log probabilities of the tokens. Including logprobs will increase
278
- the response size and can slow down response times. However, it can
279
- be useful to better understand how the model is behaving.
280
-
281
- Setting to true will return the log probabilities of the tokens that
282
- were generated.
283
-
284
- Setting to a number will return the log probabilities of the top n
285
- tokens that were generated.
286
- */
287
- logprobs?: boolean | number;
288
- /**
289
- The suffix that comes after a completion of inserted text.
290
- */
291
- suffix?: string;
292
- } & OpenRouterSharedSettings;
293
-
294
- declare enum ReasoningFormat {
295
- Unknown = "unknown",
296
- OpenAIResponsesV1 = "openai-responses-v1",
297
- XAIResponsesV1 = "xai-responses-v1",
298
- AnthropicClaudeV1 = "anthropic-claude-v1",
299
- GoogleGeminiV1 = "google-gemini-v1"
300
- }
301
-
302
- declare enum ReasoningDetailType {
303
- Summary = "reasoning.summary",
304
- Encrypted = "reasoning.encrypted",
305
- Text = "reasoning.text"
306
- }
307
- declare const ReasoningDetailUnionSchema: z.ZodUnion<readonly [z.ZodObject<{
308
- type: z.ZodLiteral<ReasoningDetailType.Summary>;
309
- summary: z.ZodString;
310
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
311
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
312
- index: z.ZodOptional<z.ZodNumber>;
313
- }, z.core.$strip>, z.ZodObject<{
314
- type: z.ZodLiteral<ReasoningDetailType.Encrypted>;
315
- data: z.ZodString;
316
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
317
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
318
- index: z.ZodOptional<z.ZodNumber>;
319
- }, z.core.$strip>, z.ZodObject<{
320
- type: z.ZodLiteral<ReasoningDetailType.Text>;
321
- text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
322
- signature: z.ZodOptional<z.ZodNullable<z.ZodString>>;
323
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
324
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
325
- index: z.ZodOptional<z.ZodNumber>;
326
- }, z.core.$strip>]>;
327
- type ReasoningDetailUnion = z.infer<typeof ReasoningDetailUnionSchema>;
328
-
329
- type OpenRouterChatConfig = {
330
- provider: string;
331
- compatibility: 'strict' | 'compatible';
332
- headers: () => Record<string, string | undefined>;
333
- url: (options: {
334
- modelId: string;
335
- path: string;
336
- }) => string;
337
- fetch?: typeof fetch;
338
120
  extraBody?: Record<string, unknown>;
339
- };
340
- declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
341
- readonly specificationVersion: "v2";
342
- readonly provider = "openrouter";
343
- readonly defaultObjectGenerationMode: "tool";
344
- readonly modelId: OpenRouterChatModelId;
345
- readonly supportsImageUrls = true;
346
- readonly supportedUrls: Record<string, RegExp[]>;
347
- readonly settings: OpenRouterChatSettings;
348
- private readonly config;
349
- constructor(modelId: OpenRouterChatModelId, settings: OpenRouterChatSettings, config: OpenRouterChatConfig);
350
- private getArgs;
351
- doGenerate(options: LanguageModelV2CallOptions): Promise<{
352
- content: Array<LanguageModelV2Content>;
353
- finishReason: LanguageModelV2FinishReason;
354
- usage: LanguageModelV2Usage;
355
- warnings: Array<LanguageModelV2CallWarning>;
356
- providerMetadata?: {
357
- openrouter: {
358
- provider: string;
359
- reasoning_details?: ReasoningDetailUnion[];
360
- usage: OpenRouterUsageAccounting;
361
- };
362
- };
363
- request?: {
364
- body?: unknown;
365
- };
366
- response?: LanguageModelV2ResponseMetadata & {
367
- headers?: SharedV2Headers;
368
- body?: unknown;
369
- };
370
- }>;
371
- doStream(options: LanguageModelV2CallOptions): Promise<{
372
- stream: ReadableStream<LanguageModelV2StreamPart>;
373
- warnings: Array<LanguageModelV2CallWarning>;
374
- request?: {
375
- body?: unknown;
376
- };
377
- response?: LanguageModelV2ResponseMetadata & {
378
- headers?: SharedV2Headers;
379
- body?: unknown;
380
- };
381
- }>;
382
121
  }
383
-
384
- type OpenRouterCompletionConfig = {
385
- provider: string;
386
- compatibility: 'strict' | 'compatible';
387
- headers: () => Record<string, string | undefined>;
388
- url: (options: {
389
- modelId: string;
390
- path: string;
391
- }) => string;
392
- fetch?: typeof fetch;
393
- extraBody?: Record<string, unknown>;
394
- };
395
- declare class OpenRouterCompletionLanguageModel implements LanguageModelV2 {
396
- readonly specificationVersion: "v2";
397
- readonly provider = "openrouter";
398
- readonly modelId: OpenRouterCompletionModelId;
399
- readonly supportsImageUrls = true;
400
- readonly supportedUrls: Record<string, RegExp[]>;
401
- readonly defaultObjectGenerationMode: undefined;
402
- readonly settings: OpenRouterCompletionSettings;
403
- private readonly config;
404
- constructor(modelId: OpenRouterCompletionModelId, settings: OpenRouterCompletionSettings, config: OpenRouterCompletionConfig);
405
- private getArgs;
406
- doGenerate(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
407
- doStream(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
408
- }
409
-
410
- type OpenRouterEmbeddingConfig = {
411
- provider: string;
412
- headers: () => Record<string, string | undefined>;
413
- url: (options: {
414
- modelId: string;
415
- path: string;
416
- }) => string;
417
- fetch?: typeof fetch;
418
- extraBody?: Record<string, unknown>;
419
- };
420
- declare class OpenRouterEmbeddingModel implements EmbeddingModelV2<string> {
421
- readonly specificationVersion: "v2";
422
- readonly provider = "openrouter";
423
- readonly modelId: OpenRouterEmbeddingModelId;
424
- readonly settings: OpenRouterEmbeddingSettings;
425
- readonly maxEmbeddingsPerCall: undefined;
426
- readonly supportsParallelCalls = true;
427
- private readonly config;
428
- constructor(modelId: OpenRouterEmbeddingModelId, settings: OpenRouterEmbeddingSettings, config: OpenRouterEmbeddingConfig);
429
- doEmbed(options: {
430
- values: Array<string>;
431
- abortSignal?: AbortSignal;
432
- headers?: Record<string, string | undefined>;
433
- }): Promise<{
434
- embeddings: Array<Array<number>>;
435
- usage?: {
436
- tokens: number;
437
- };
438
- providerMetadata?: SharedV2ProviderMetadata;
439
- response?: {
440
- headers?: SharedV2Headers;
441
- body?: unknown;
442
- };
443
- }>;
444
- }
445
-
446
- interface OpenRouterProvider extends ProviderV2 {
447
- (modelId: OpenRouterChatModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
448
- (modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
449
- languageModel(modelId: OpenRouterChatModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
450
- languageModel(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
122
+ /**
123
+ * Configuration for an OpenRouter plugin.
124
+ *
125
+ * @description
126
+ * Plugins extend OpenRouter functionality with features like web search, code execution,
127
+ * and more. Each plugin has a unique identifier and optional configuration parameters.
128
+ * Additional plugin-specific properties can be included as needed.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * const model = openrouter('anthropic/claude-3.5-sonnet', {
133
+ * plugins: [
134
+ * { id: 'web-search' },
135
+ * { id: 'code-interpreter', config: { timeout: 30000 } },
136
+ * ],
137
+ * });
138
+ * ```
139
+ */
140
+ interface OpenRouterPluginConfig {
141
+ /**
142
+ * The plugin identifier.
143
+ */
144
+ id: string;
145
+ /**
146
+ * Plugin-specific configuration.
147
+ */
148
+ config?: Record<string, unknown>;
451
149
  /**
452
- Creates an OpenRouter chat model for text generation.
150
+ * Allow any additional plugin-specific properties.
453
151
  */
454
- chat(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
152
+ [key: string]: unknown;
153
+ }
154
+ /**
155
+ * Configuration for OpenRouter's provider routing behavior.
156
+ *
157
+ * @description
158
+ * Controls how OpenRouter selects and falls back between different AI providers
159
+ * when routing requests. Use this to specify provider preferences, enable/disable
160
+ * fallbacks, and require specific provider parameters.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * const model = openrouter('openai/gpt-4', {
165
+ * provider: {
166
+ * order: ['Azure', 'OpenAI'],
167
+ * allowFallbacks: true,
168
+ * },
169
+ * });
170
+ * ```
171
+ */
172
+ interface OpenRouterProviderRoutingConfig {
455
173
  /**
456
- Creates an OpenRouter completion model for text generation.
174
+ * Provider order preference.
457
175
  */
458
- completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
176
+ order?: string[];
459
177
  /**
460
- Creates an OpenRouter text embedding model. (AI SDK v5)
178
+ * Allow fallbacks to other providers.
461
179
  */
462
- textEmbeddingModel(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
180
+ allowFallbacks?: boolean;
463
181
  /**
464
- Creates an OpenRouter text embedding model. (AI SDK v4 - deprecated, use textEmbeddingModel instead)
465
- @deprecated Use textEmbeddingModel instead
182
+ * Required provider parameters.
466
183
  */
467
- embedding(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
184
+ requireParameters?: boolean;
468
185
  }
469
- interface OpenRouterProviderSettings {
186
+ /**
187
+ * Model-specific options for OpenRouter requests.
188
+ *
189
+ * @description
190
+ * Options that can be passed when creating a model to customize its behavior.
191
+ * These include OpenRouter-specific features like plugins, transforms, model
192
+ * fallbacks, and routing configuration. Additional properties are passed through
193
+ * to the underlying API.
194
+ *
195
+ * @example
196
+ * ```ts
197
+ * const model = openrouter('anthropic/claude-3.5-sonnet', {
198
+ * usage: { include: true },
199
+ * transforms: ['middle-out'],
200
+ * models: ['anthropic/claude-3-opus', 'openai/gpt-4'], // fallbacks
201
+ * provider: {
202
+ * order: ['Anthropic'],
203
+ * allowFallbacks: false,
204
+ * },
205
+ * });
206
+ * ```
207
+ */
208
+ interface OpenRouterModelOptions {
470
209
  /**
471
- Base URL for the OpenRouter API calls.
472
- */
473
- baseURL?: string;
210
+ * Usage accounting configuration.
211
+ */
212
+ usage?: {
213
+ /**
214
+ * Whether to include usage information in the response.
215
+ */
216
+ include?: boolean;
217
+ };
474
218
  /**
475
- @deprecated Use `baseURL` instead.
476
- */
477
- baseUrl?: string;
219
+ * OpenRouter plugins to enable.
220
+ */
221
+ plugins?: OpenRouterPluginConfig[];
478
222
  /**
479
- API key for authenticating requests.
480
- */
481
- apiKey?: string;
223
+ * Message transforms to apply.
224
+ */
225
+ transforms?: string[];
482
226
  /**
483
- Custom headers to include in the requests.
484
- */
485
- headers?: Record<string, string>;
227
+ * Fallback model IDs.
228
+ */
229
+ models?: string[];
486
230
  /**
487
- OpenRouter compatibility mode. Should be set to `strict` when using the OpenRouter API,
488
- and `compatible` when using 3rd party providers. In `compatible` mode, newer
489
- information such as streamOptions are not being sent. Defaults to 'compatible'.
231
+ * Routing strategy.
490
232
  */
491
- compatibility?: 'strict' | 'compatible';
233
+ route?: string;
492
234
  /**
493
- Custom fetch implementation. You can use it as a middleware to intercept requests,
494
- or to provide a custom fetch implementation for e.g. testing.
495
- */
496
- fetch?: typeof fetch;
235
+ * Provider routing configuration.
236
+ */
237
+ provider?: OpenRouterProviderRoutingConfig;
497
238
  /**
498
- A JSON object to send as the request body to access OpenRouter features & upstream provider features.
499
- */
500
- extraBody?: Record<string, unknown>;
239
+ * How to handle system messages for reasoning models.
240
+ * - 'system': Standard system message (default)
241
+ * - 'developer': Convert system to developer role for reasoning models
242
+ * - 'remove': Strip system messages entirely
243
+ */
244
+ systemMessageMode?: 'system' | 'developer' | 'remove';
501
245
  /**
502
- * Record of provider slugs to API keys for injecting into provider routing.
503
- * Maps provider slugs (e.g. "anthropic", "openai") to their respective API keys.
246
+ * Allow any additional model-specific options.
247
+ * These are passed through to the API.
504
248
  */
505
- api_keys?: Record<string, string>;
249
+ [key: string]: unknown;
506
250
  }
507
- /**
508
- Create an OpenRouter provider instance.
509
- */
510
- declare function createOpenRouter(options?: OpenRouterProviderSettings): OpenRouterProvider;
511
- /**
512
- Default OpenRouter provider instance. It uses 'strict' compatibility mode.
513
- */
514
- declare const openrouter: OpenRouterProvider;
515
251
 
516
252
  /**
517
- @deprecated Use `createOpenRouter` instead.
253
+ * OpenRouter provider interface extending the AI SDK V3 ProviderV3 interface.
254
+ *
255
+ * The provider is callable - calling it directly is equivalent to calling languageModel().
518
256
  */
519
- declare class OpenRouter {
257
+ interface OpenRouterProvider extends ProviderV3 {
520
258
  /**
521
- Use a different URL prefix for API calls, e.g. to use proxy servers.
522
- The default prefix is `https://openrouter.ai/api/v1`.
259
+ * Create a language model by calling the provider directly.
523
260
  */
524
- readonly baseURL: string;
261
+ (modelId: string, settings?: OpenRouterModelOptions): OpenRouterChatLanguageModel;
525
262
  /**
526
- API key that is being sent using the `Authorization` header.
527
- It defaults to the `OPENROUTER_API_KEY` environment variable.
528
- */
529
- readonly apiKey?: string;
263
+ * Create a language model.
264
+ */
265
+ languageModel(modelId: string, settings?: OpenRouterModelOptions): OpenRouterChatLanguageModel;
266
+ /**
267
+ * Create a chat model (alias for languageModel).
268
+ */
269
+ chat(modelId: string, settings?: OpenRouterModelOptions): OpenRouterChatLanguageModel;
530
270
  /**
531
- Custom headers to include in the requests.
271
+ * Create an embedding model.
532
272
  */
533
- readonly headers?: Record<string, string>;
273
+ embeddingModel(modelId: string, settings?: OpenRouterModelOptions): OpenRouterEmbeddingModel;
534
274
  /**
535
- * Record of provider slugs to API keys for injecting into provider routing.
275
+ * Create a text embedding model.
276
+ * @deprecated Use embeddingModel instead.
536
277
  */
537
- readonly api_keys?: Record<string, string>;
278
+ textEmbeddingModel(modelId: string, settings?: OpenRouterModelOptions): OpenRouterEmbeddingModel;
538
279
  /**
539
- * Creates a new OpenRouter provider instance.
280
+ * Create an image model.
540
281
  */
541
- constructor(options?: OpenRouterProviderSettings);
542
- private get baseConfig();
543
- chat(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
544
- completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
545
- textEmbeddingModel(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
282
+ imageModel(modelId: string, settings?: OpenRouterModelOptions): OpenRouterImageModel;
546
283
  /**
547
- * @deprecated Use textEmbeddingModel instead
284
+ * Create an image model (alias for imageModel).
548
285
  */
549
- embedding(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
286
+ image(modelId: string, settings?: OpenRouterModelOptions): OpenRouterImageModel;
287
+ /**
288
+ * Create an embedding model (alias for embeddingModel).
289
+ * @deprecated Use embeddingModel instead.
290
+ */
291
+ embedding(modelId: string, settings?: OpenRouterModelOptions): OpenRouterEmbeddingModel;
550
292
  }
293
+ /**
294
+ * Internal settings passed to model constructors.
295
+ * Contains resolved API key and normalized configuration.
296
+ */
297
+ interface OpenRouterModelSettings {
298
+ apiKey: string;
299
+ baseURL: string;
300
+ headers?: Record<string, string>;
301
+ fetch?: typeof globalThis.fetch;
302
+ extraBody?: Record<string, unknown>;
303
+ modelOptions?: OpenRouterModelOptions;
304
+ }
305
+ /**
306
+ * Creates an OpenRouter provider instance for the AI SDK.
307
+ *
308
+ * @description
309
+ * Factory function that creates an OpenRouter provider compatible with the AI SDK v3 provider
310
+ * specification. The provider can create language models, embedding models, and image models
311
+ * that route requests through OpenRouter to various AI providers (OpenAI, Anthropic, Google, etc.).
312
+ *
313
+ * The returned provider is callable - you can use it directly as a function to create language
314
+ * models, or use its methods for specific model types.
315
+ *
316
+ * @param options - Provider settings including API key, base URL, headers, and fetch implementation.
317
+ * If no API key is provided, it will be loaded from the OPENROUTER_API_KEY environment variable.
318
+ * @returns An OpenRouter provider that can create language, embedding, and image models.
319
+ *
320
+ * @example Basic usage with environment variable
321
+ * ```ts
322
+ * import { createOpenRouter } from '@openrouter/ai-sdk-provider';
323
+ *
324
+ * // Uses OPENROUTER_API_KEY from environment
325
+ * const openrouter = createOpenRouter();
326
+ *
327
+ * const model = openrouter('anthropic/claude-3.5-sonnet');
328
+ * ```
329
+ *
330
+ * @example With explicit API key
331
+ * ```ts
332
+ * import { createOpenRouter } from '@openrouter/ai-sdk-provider';
333
+ *
334
+ * const openrouter = createOpenRouter({
335
+ * apiKey: process.env.OPENROUTER_API_KEY,
336
+ * });
337
+ *
338
+ * const model = openrouter('anthropic/claude-3.5-sonnet');
339
+ * ```
340
+ *
341
+ * @example Creating different model types
342
+ * ```ts
343
+ * const openrouter = createOpenRouter();
344
+ *
345
+ * // Language model (callable shorthand)
346
+ * const chat = openrouter('anthropic/claude-3.5-sonnet');
347
+ *
348
+ * // Embedding model
349
+ * const embeddings = openrouter.embeddingModel('openai/text-embedding-3-small');
350
+ *
351
+ * // Image model
352
+ * const image = openrouter.imageModel('openai/dall-e-3');
353
+ * ```
354
+ *
355
+ * @example Model variants
356
+ * ```ts
357
+ * const openrouter = createOpenRouter();
358
+ *
359
+ * // Online search variant - model has web search capabilities
360
+ * const online = openrouter('anthropic/claude-3.5-sonnet:online');
361
+ *
362
+ * // Nitro variant - faster inference
363
+ * const nitro = openrouter('anthropic/claude-3.5-sonnet:nitro');
364
+ *
365
+ * // Floor pricing variant - routes to cheapest provider
366
+ * const floor = openrouter('anthropic/claude-3.5-sonnet:floor');
367
+ *
368
+ * // Free tier variant
369
+ * const free = openrouter('meta-llama/llama-3-8b-instruct:free');
370
+ * ```
371
+ */
372
+ declare function createOpenRouter(options?: OpenRouterProviderSettings): OpenRouterProvider;
373
+
374
+ declare const VERSION = "6.0.0-alpha.0";
375
+
376
+ /**
377
+ * Default OpenRouter provider instance.
378
+ *
379
+ * Uses OPENROUTER_API_KEY environment variable for authentication.
380
+ *
381
+ * @example
382
+ * ```ts
383
+ * import { openrouter } from '@openrouter/ai-sdk-provider';
384
+ *
385
+ * const model = openrouter('anthropic/claude-3.5-sonnet');
386
+ * ```
387
+ */
388
+ declare const openrouter: OpenRouterProvider;
551
389
 
552
- export { OpenRouter, type OpenRouterChatSettings, type OpenRouterCompletionSettings, type OpenRouterEmbeddingModelId, type OpenRouterEmbeddingSettings, type OpenRouterProvider, type OpenRouterProviderOptions, type OpenRouterProviderSettings, type OpenRouterSharedSettings, type OpenRouterUsageAccounting, createOpenRouter, openrouter };
390
+ export { type OpenRouterModelOptions, type OpenRouterPluginConfig, type OpenRouterProvider, type OpenRouterProviderRoutingConfig, type OpenRouterProviderSettings, VERSION, createOpenRouter, openrouter };