@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.mts +331 -493
- package/dist/index.d.ts +331 -493
- package/dist/index.js +1047 -2782
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1040 -2768
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +315 -361
- package/dist/internal/index.d.ts +315 -361
- package/dist/internal/index.js +372 -2593
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +365 -2582
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +40 -36
package/dist/index.d.mts
CHANGED
|
@@ -1,552 +1,390 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
*
|
|
84
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
38
|
+
* Whether the model supports parallel calls.
|
|
97
39
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
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
|
-
|
|
150
|
-
|
|
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
|
-
*
|
|
153
|
-
* monitor and detect abuse.
|
|
95
|
+
* API key for OpenRouter. If not provided, will use OPENROUTER_API_KEY env var.
|
|
154
96
|
*/
|
|
155
|
-
|
|
97
|
+
apiKey?: string;
|
|
156
98
|
/**
|
|
157
|
-
*
|
|
99
|
+
* Base URL for the OpenRouter API.
|
|
100
|
+
* @default 'https://openrouter.ai/api/v1'
|
|
158
101
|
*/
|
|
159
|
-
|
|
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
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
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
|
-
|
|
209
|
-
enabled?: boolean;
|
|
210
|
-
exclude?: boolean;
|
|
211
|
-
} & ({
|
|
212
|
-
max_tokens: number;
|
|
213
|
-
} | {
|
|
214
|
-
effort: 'high' | 'medium' | 'low';
|
|
215
|
-
});
|
|
108
|
+
baseUrl?: string;
|
|
216
109
|
/**
|
|
217
|
-
*
|
|
218
|
-
* help OpenRouter to monitor and detect abuse.
|
|
110
|
+
* Custom headers to include in all requests.
|
|
219
111
|
*/
|
|
220
|
-
|
|
221
|
-
};
|
|
222
|
-
type OpenRouterSharedSettings = OpenRouterProviderOptions & {
|
|
112
|
+
headers?: Record<string, string>;
|
|
223
113
|
/**
|
|
224
|
-
*
|
|
114
|
+
* Custom fetch implementation.
|
|
225
115
|
*/
|
|
226
|
-
|
|
227
|
-
extraBody?: Record<string, unknown>;
|
|
116
|
+
fetch?: typeof globalThis.fetch;
|
|
228
117
|
/**
|
|
229
|
-
*
|
|
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
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
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
|
-
|
|
150
|
+
* Allow any additional plugin-specific properties.
|
|
453
151
|
*/
|
|
454
|
-
|
|
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
|
-
|
|
174
|
+
* Provider order preference.
|
|
457
175
|
*/
|
|
458
|
-
|
|
176
|
+
order?: string[];
|
|
459
177
|
/**
|
|
460
|
-
|
|
178
|
+
* Allow fallbacks to other providers.
|
|
461
179
|
*/
|
|
462
|
-
|
|
180
|
+
allowFallbacks?: boolean;
|
|
463
181
|
/**
|
|
464
|
-
|
|
465
|
-
@deprecated Use textEmbeddingModel instead
|
|
182
|
+
* Required provider parameters.
|
|
466
183
|
*/
|
|
467
|
-
|
|
184
|
+
requireParameters?: boolean;
|
|
468
185
|
}
|
|
469
|
-
|
|
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
|
-
|
|
472
|
-
|
|
473
|
-
|
|
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
|
-
|
|
476
|
-
|
|
477
|
-
|
|
219
|
+
* OpenRouter plugins to enable.
|
|
220
|
+
*/
|
|
221
|
+
plugins?: OpenRouterPluginConfig[];
|
|
478
222
|
/**
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
223
|
+
* Message transforms to apply.
|
|
224
|
+
*/
|
|
225
|
+
transforms?: string[];
|
|
482
226
|
/**
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
227
|
+
* Fallback model IDs.
|
|
228
|
+
*/
|
|
229
|
+
models?: string[];
|
|
486
230
|
/**
|
|
487
|
-
|
|
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
|
-
|
|
233
|
+
route?: string;
|
|
492
234
|
/**
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
fetch?: typeof fetch;
|
|
235
|
+
* Provider routing configuration.
|
|
236
|
+
*/
|
|
237
|
+
provider?: OpenRouterProviderRoutingConfig;
|
|
497
238
|
/**
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
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
|
-
*
|
|
503
|
-
*
|
|
246
|
+
* Allow any additional model-specific options.
|
|
247
|
+
* These are passed through to the API.
|
|
504
248
|
*/
|
|
505
|
-
|
|
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
|
-
|
|
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
|
-
|
|
257
|
+
interface OpenRouterProvider extends ProviderV3 {
|
|
520
258
|
/**
|
|
521
|
-
|
|
522
|
-
The default prefix is `https://openrouter.ai/api/v1`.
|
|
259
|
+
* Create a language model by calling the provider directly.
|
|
523
260
|
*/
|
|
524
|
-
|
|
261
|
+
(modelId: string, settings?: OpenRouterModelOptions): OpenRouterChatLanguageModel;
|
|
525
262
|
/**
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
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
|
-
|
|
271
|
+
* Create an embedding model.
|
|
532
272
|
*/
|
|
533
|
-
|
|
273
|
+
embeddingModel(modelId: string, settings?: OpenRouterModelOptions): OpenRouterEmbeddingModel;
|
|
534
274
|
/**
|
|
535
|
-
*
|
|
275
|
+
* Create a text embedding model.
|
|
276
|
+
* @deprecated Use embeddingModel instead.
|
|
536
277
|
*/
|
|
537
|
-
|
|
278
|
+
textEmbeddingModel(modelId: string, settings?: OpenRouterModelOptions): OpenRouterEmbeddingModel;
|
|
538
279
|
/**
|
|
539
|
-
*
|
|
280
|
+
* Create an image model.
|
|
540
281
|
*/
|
|
541
|
-
|
|
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
|
-
*
|
|
284
|
+
* Create an image model (alias for imageModel).
|
|
548
285
|
*/
|
|
549
|
-
|
|
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 {
|
|
390
|
+
export { type OpenRouterModelOptions, type OpenRouterPluginConfig, type OpenRouterProvider, type OpenRouterProviderRoutingConfig, type OpenRouterProviderSettings, VERSION, createOpenRouter, openrouter };
|