@openrouter/ai-sdk-provider 2.9.1 → 3.0.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 DELETED
@@ -1,880 +0,0 @@
1
- import * as _ai_sdk_provider from '@ai-sdk/provider';
2
- import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3Content, LanguageModelV3FinishReason, LanguageModelV3Usage, SharedV3Warning, LanguageModelV3ResponseMetadata, SharedV3Headers, LanguageModelV3StreamPart, EmbeddingModelV3, SharedV3ProviderMetadata, ImageModelV3, ImageModelV3CallOptions, ImageModelV3ProviderMetadata, ImageModelV3Usage, Experimental_VideoModelV3, Experimental_VideoModelV3CallOptions, Experimental_VideoModelV3VideoData, ProviderV3 } from '@ai-sdk/provider';
3
- export { LanguageModelV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
4
- import { ProviderToolFactory } from '@ai-sdk/provider-utils';
5
- import { z } from 'zod/v4';
6
-
7
- /**
8
- * Plugin identifier for web search functionality.
9
- */
10
- type IdWeb = 'web';
11
- /**
12
- * Plugin identifier for file parsing functionality.
13
- */
14
- type IdFileParser = 'file-parser';
15
- /**
16
- * Plugin identifier for content moderation.
17
- */
18
- type IdModeration = 'moderation';
19
- /**
20
- * Plugin identifier for response healing.
21
- * Automatically validates and repairs malformed JSON responses.
22
- * @see https://openrouter.ai/docs/guides/features/plugins/response-healing
23
- */
24
- type IdResponseHealing = 'response-healing';
25
- /**
26
- * Plugin identifier for auto-router model selection.
27
- * Configures allowed models when using the openrouter/auto model.
28
- * @see https://openrouter.ai/docs/guides/routing/routers/auto-router
29
- */
30
- type IdAutoRouter = 'auto-router';
31
- /**
32
- * Search engine options for web search.
33
- * Open enum - accepts known values or any string for forward compatibility.
34
- */
35
- type Engine = 'native' | 'exa' | (string & {});
36
- /**
37
- * PDF processing engine options.
38
- * Open enum - accepts known values or any string for forward compatibility.
39
- */
40
- type PdfEngine = 'mistral-ocr' | 'pdf-text' | 'native' | (string & {});
41
- /**
42
- * Data collection preference for provider routing.
43
- * Open enum - accepts known values or any string for forward compatibility.
44
- */
45
- type DataCollection = 'deny' | 'allow' | (string & {});
46
- /**
47
- * Model quantization levels for provider filtering.
48
- * Open enum - accepts known values or any string for forward compatibility.
49
- */
50
- type Quantization = 'int4' | 'int8' | 'fp4' | 'fp6' | 'fp8' | 'fp16' | 'bf16' | 'fp32' | 'unknown' | (string & {});
51
- /**
52
- * Provider sorting strategy options.
53
- * Open enum - accepts known values or any string for forward compatibility.
54
- */
55
- type ProviderSort = 'price' | 'throughput' | 'latency' | (string & {});
56
-
57
- type OpenRouterChatModelId = string;
58
- type OpenRouterChatSettings = {
59
- /**
60
- Modify the likelihood of specified tokens appearing in the completion.
61
-
62
- Accepts a JSON object that maps tokens (specified by their token ID in
63
- the GPT tokenizer) to an associated bias value from -100 to 100. You
64
- can use this tokenizer tool to convert text to token IDs. Mathematically,
65
- the bias is added to the logits generated by the model prior to sampling.
66
- The exact effect will vary per model, but values between -1 and 1 should
67
- decrease or increase likelihood of selection; values like -100 or 100
68
- should result in a ban or exclusive selection of the relevant token.
69
-
70
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
71
- token from being generated.
72
- */
73
- logitBias?: Record<number, number>;
74
- /**
75
- Return the log probabilities of the tokens. Including logprobs will increase
76
- the response size and can slow down response times. However, it can
77
- be useful to understand better how the model is behaving.
78
-
79
- Setting to true will return the log probabilities of the tokens that
80
- were generated.
81
-
82
- Setting to a number will return the log probabilities of the top n
83
- tokens that were generated.
84
- */
85
- logprobs?: boolean | number;
86
- /**
87
- Whether to enable parallel function calling during tool use. Default to true.
88
- */
89
- parallelToolCalls?: boolean;
90
- /**
91
- A unique identifier representing your end-user, which can help OpenRouter to
92
- monitor and detect abuse. Learn more.
93
- */
94
- user?: string;
95
- /**
96
- * Plugin configurations for enabling various capabilities
97
- */
98
- plugins?: Array<{
99
- id: IdWeb;
100
- max_results?: number;
101
- search_prompt?: string;
102
- engine?: Engine;
103
- } | {
104
- id: IdFileParser;
105
- max_files?: number;
106
- pdf?: {
107
- engine?: PdfEngine;
108
- };
109
- } | {
110
- id: IdModeration;
111
- } | {
112
- /**
113
- * Response healing plugin - automatically validates and repairs malformed JSON responses.
114
- *
115
- * **Important:** This plugin only works with non-streaming requests (e.g., `generateObject`).
116
- * It has no effect when used with streaming methods like `streamObject` or `streamText`.
117
- * The plugin activates when using `response_format` with `json_schema` or `json_object`.
118
- *
119
- * @see https://openrouter.ai/docs/guides/features/plugins/response-healing
120
- */
121
- id: IdResponseHealing;
122
- } | {
123
- /**
124
- * Auto-router plugin - configures allowed models when using `openrouter/auto`.
125
- *
126
- * Use wildcard patterns to restrict which models the auto router can select from.
127
- * When no `allowed_models` are specified, the auto router uses all supported models.
128
- *
129
- * @see https://openrouter.ai/docs/guides/routing/routers/auto-router
130
- */
131
- id: IdAutoRouter;
132
- allowed_models?: string[];
133
- }>;
134
- /**
135
- * Built-in web search options for models that support native web search
136
- */
137
- web_search_options?: {
138
- /**
139
- * Maximum number of search results to include
140
- */
141
- max_results?: number;
142
- /**
143
- * Custom search prompt to guide the search query
144
- */
145
- search_prompt?: string;
146
- /**
147
- * Search engine to use for web search
148
- * - "native": Use provider's built-in web search
149
- * - "exa": Use Exa's search API
150
- * - undefined: Native if supported, otherwise Exa
151
- * @see https://openrouter.ai/docs/features/web-search
152
- */
153
- engine?: Engine;
154
- };
155
- /**
156
- * Enable Anthropic automatic prompt caching by setting a top-level cache_control
157
- * directive on the request body. When set to `{ type: 'ephemeral' }`, Anthropic
158
- * will automatically cache eligible content in your prompts.
159
- *
160
- * Only works with Anthropic models through OpenRouter.
161
- *
162
- * @see https://platform.claude.com/docs/en/build-with-claude/prompt-caching#automatic-caching
163
- * @see https://openrouter.ai/docs
164
- */
165
- cache_control?: {
166
- type: 'ephemeral';
167
- /**
168
- * Optional time-to-live for the cache entry.
169
- * - `'5m'` — 5 minutes (default when omitted)
170
- * - `'1h'` — 1 hour
171
- */
172
- ttl?: '5m' | '1h';
173
- };
174
- /**
175
- * Debug options for troubleshooting API requests.
176
- * Only works with streaming requests.
177
- * @see https://openrouter.ai/docs/api-reference/debugging
178
- */
179
- debug?: {
180
- /**
181
- * When true, echoes back the request body that was sent to the upstream provider.
182
- * The debug data will be returned as the first chunk in the stream with a `debug.echo_upstream_body` field.
183
- * Sensitive data like user IDs and base64 content will be redacted.
184
- */
185
- echo_upstream_body?: boolean;
186
- };
187
- /**
188
- * Structured-output options forwarded to OpenRouter's
189
- * `response_format.json_schema` payload.
190
- *
191
- * Use this to opt out of strict mode for models whose providers don't
192
- * advertise support for it (e.g. open-source models routed through
193
- * non-OpenAI-compatible providers). When `strict` is left unset, the
194
- * SDK defaults to `true` for backward compatibility.
195
- *
196
- * Only applies when a `responseFormat` with a `schema` is provided on
197
- * the call site. Has no effect for `json_object` or text responses.
198
- */
199
- structuredOutputs?: {
200
- /**
201
- * Whether to set `response_format.json_schema.strict` on the outbound
202
- * request. Defaults to `true` when omitted.
203
- */
204
- strict?: boolean;
205
- };
206
- /**
207
- * Provider routing preferences to control request routing behavior
208
- */
209
- provider?: {
210
- /**
211
- * List of provider slugs to try in order (e.g. ["anthropic", "openai"])
212
- */
213
- order?: string[];
214
- /**
215
- * Whether to allow backup providers when primary is unavailable (default: true)
216
- */
217
- allow_fallbacks?: boolean;
218
- /**
219
- * Only use providers that support all parameters in your request (default: false)
220
- */
221
- require_parameters?: boolean;
222
- /**
223
- * Control whether to use providers that may store data
224
- */
225
- data_collection?: DataCollection;
226
- /**
227
- * List of provider slugs to allow for this request
228
- */
229
- only?: string[];
230
- /**
231
- * List of provider slugs to skip for this request
232
- */
233
- ignore?: string[];
234
- /**
235
- * List of quantization levels to filter by (e.g. ["int4", "int8"])
236
- */
237
- quantizations?: Array<Quantization>;
238
- /**
239
- * Sort providers by price, throughput, or latency
240
- */
241
- sort?: ProviderSort;
242
- /**
243
- * Maximum pricing you want to pay for this request
244
- */
245
- max_price?: {
246
- prompt?: number | string;
247
- completion?: number | string;
248
- image?: number | string;
249
- audio?: number | string;
250
- request?: number | string;
251
- };
252
- /**
253
- * Whether to restrict routing to only ZDR (Zero Data Retention) endpoints.
254
- * When true, only endpoints that do not retain prompts will be used.
255
- */
256
- zdr?: boolean;
257
- };
258
- } & OpenRouterSharedSettings;
259
-
260
- type OpenRouterEmbeddingModelId = string;
261
- type OpenRouterEmbeddingSettings = {
262
- /**
263
- * A unique identifier representing your end-user, which can help OpenRouter to
264
- * monitor and detect abuse.
265
- */
266
- user?: string;
267
- /**
268
- * Provider routing preferences to control request routing behavior
269
- */
270
- provider?: {
271
- /**
272
- * List of provider slugs to try in order (e.g. ["openai", "voyageai"])
273
- */
274
- order?: string[];
275
- /**
276
- * Whether to allow backup providers when primary is unavailable (default: true)
277
- */
278
- allow_fallbacks?: boolean;
279
- /**
280
- * Only use providers that support all parameters in your request (default: false)
281
- */
282
- require_parameters?: boolean;
283
- /**
284
- * Control whether to use providers that may store data
285
- */
286
- data_collection?: 'allow' | 'deny';
287
- /**
288
- * List of provider slugs to allow for this request
289
- */
290
- only?: string[];
291
- /**
292
- * List of provider slugs to skip for this request
293
- */
294
- ignore?: string[];
295
- /**
296
- * Sort providers by price, throughput, or latency
297
- */
298
- sort?: 'price' | 'throughput' | 'latency';
299
- /**
300
- * Maximum pricing you want to pay for this request
301
- */
302
- max_price?: {
303
- prompt?: number | string;
304
- completion?: number | string;
305
- image?: number | string;
306
- audio?: number | string;
307
- request?: number | string;
308
- };
309
- };
310
- } & OpenRouterSharedSettings;
311
-
312
- type OpenRouterImageModelId = string;
313
- type OpenRouterImageSettings = {
314
- /**
315
- * Provider routing preferences to control request routing behavior
316
- */
317
- provider?: {
318
- /**
319
- * List of provider slugs to try in order (e.g. ["google", "black-forest-labs"])
320
- */
321
- order?: string[];
322
- /**
323
- * Whether to allow backup providers when primary is unavailable (default: true)
324
- */
325
- allow_fallbacks?: boolean;
326
- /**
327
- * Only use providers that support all parameters in your request (default: false)
328
- */
329
- require_parameters?: boolean;
330
- /**
331
- * Control whether to use providers that may store data
332
- */
333
- data_collection?: 'allow' | 'deny';
334
- /**
335
- * List of provider slugs to allow for this request
336
- */
337
- only?: string[];
338
- /**
339
- * List of provider slugs to skip for this request
340
- */
341
- ignore?: string[];
342
- /**
343
- * Sort providers by price, throughput, or latency
344
- */
345
- sort?: 'price' | 'throughput' | 'latency';
346
- /**
347
- * Maximum pricing you want to pay for this request
348
- */
349
- max_price?: {
350
- prompt?: number | string;
351
- completion?: number | string;
352
- image?: number | string;
353
- request?: number | string;
354
- };
355
- };
356
- } & OpenRouterSharedSettings;
357
-
358
- type OpenRouterVideoModelId = string;
359
- type OpenRouterVideoSettings = {
360
- /**
361
- * Whether to generate audio alongside the video.
362
- * Defaults to the endpoint's generate_audio capability flag, false if not set.
363
- */
364
- generateAudio?: boolean;
365
- /**
366
- * Polling interval in milliseconds when waiting for video generation to complete.
367
- * @default 2000
368
- */
369
- pollIntervalMs?: number;
370
- /**
371
- * Maximum time in milliseconds to wait for video generation to complete.
372
- * @default 600000 (10 minutes)
373
- */
374
- maxPollTimeMs?: number;
375
- /**
376
- * Additional body parameters to send with the video generation request.
377
- */
378
- extraBody?: Record<string, unknown>;
379
- };
380
-
381
- type OpenRouterProviderOptions = {
382
- models?: string[];
383
- /**
384
- * https://openrouter.ai/docs/use-cases/reasoning-tokens
385
- * One of `max_tokens` or `effort` is required.
386
- * If `exclude` is true, reasoning will be removed from the response. Default is false.
387
- */
388
- reasoning?: {
389
- enabled?: boolean;
390
- exclude?: boolean;
391
- } & ({
392
- max_tokens: number;
393
- } | {
394
- effort: 'xhigh' | 'high' | 'medium' | 'low' | 'minimal' | 'none';
395
- });
396
- /**
397
- * A unique identifier representing your end-user, which can
398
- * help OpenRouter to monitor and detect abuse.
399
- */
400
- user?: string;
401
- };
402
- type OpenRouterSharedSettings = OpenRouterProviderOptions & {
403
- /**
404
- * @deprecated use `reasoning` instead
405
- */
406
- includeReasoning?: boolean;
407
- extraBody?: Record<string, unknown>;
408
- /**
409
- * Enable usage accounting to get detailed token usage information.
410
- * https://openrouter.ai/docs/use-cases/usage-accounting
411
- */
412
- usage?: {
413
- /**
414
- * When true, includes token usage information in the response.
415
- */
416
- include: boolean;
417
- };
418
- /**
419
- * Default temperature for model calls. Controls randomness in the output.
420
- * Can be overridden at call time via generateText/streamText options.
421
- * Range: 0 to 2, where 0 is deterministic and higher values are more random.
422
- */
423
- temperature?: number;
424
- /**
425
- * Default top-p (nucleus sampling) for model calls.
426
- * Can be overridden at call time via generateText/streamText options.
427
- * Range: 0 to 1.
428
- */
429
- topP?: number;
430
- /**
431
- * Default top-k sampling for model calls.
432
- * Can be overridden at call time via generateText/streamText options.
433
- */
434
- topK?: number;
435
- /**
436
- * Default frequency penalty for model calls.
437
- * Can be overridden at call time via generateText/streamText options.
438
- * Range: -2 to 2.
439
- */
440
- frequencyPenalty?: number;
441
- /**
442
- * Default presence penalty for model calls.
443
- * Can be overridden at call time via generateText/streamText options.
444
- * Range: -2 to 2.
445
- */
446
- presencePenalty?: number;
447
- /**
448
- * Default maximum number of tokens to generate.
449
- * Can be overridden at call time via generateText/streamText options.
450
- */
451
- maxTokens?: number;
452
- };
453
- /**
454
- * Usage accounting response
455
- * @see https://openrouter.ai/docs/use-cases/usage-accounting
456
- */
457
- type OpenRouterUsageAccounting = {
458
- promptTokens: number;
459
- promptTokensDetails?: {
460
- cachedTokens: number;
461
- };
462
- completionTokens: number;
463
- completionTokensDetails?: {
464
- reasoningTokens: number;
465
- };
466
- totalTokens: number;
467
- cost?: number;
468
- costDetails?: {
469
- upstreamInferenceCost: number;
470
- };
471
- };
472
-
473
- type OpenRouterCompletionModelId = string;
474
- type OpenRouterCompletionSettings = {
475
- /**
476
- Modify the likelihood of specified tokens appearing in the completion.
477
-
478
- Accepts a JSON object that maps tokens (specified by their token ID in
479
- the GPT tokenizer) to an associated bias value from -100 to 100. You
480
- can use this tokenizer tool to convert text to token IDs. Mathematically,
481
- the bias is added to the logits generated by the model prior to sampling.
482
- The exact effect will vary per model, but values between -1 and 1 should
483
- decrease or increase likelihood of selection; values like -100 or 100
484
- should result in a ban or exclusive selection of the relevant token.
485
-
486
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
487
- token from being generated.
488
- */
489
- logitBias?: Record<number, number>;
490
- /**
491
- Return the log probabilities of the tokens. Including logprobs will increase
492
- the response size and can slow down response times. However, it can
493
- be useful to better understand how the model is behaving.
494
-
495
- Setting to true will return the log probabilities of the tokens that
496
- were generated.
497
-
498
- Setting to a number will return the log probabilities of the top n
499
- tokens that were generated.
500
- */
501
- logprobs?: boolean | number;
502
- /**
503
- The suffix that comes after a completion of inserted text.
504
- */
505
- suffix?: string;
506
- } & OpenRouterSharedSettings;
507
-
508
- declare enum ReasoningFormat {
509
- Unknown = "unknown",
510
- OpenAIResponsesV1 = "openai-responses-v1",
511
- AzureOpenAIResponsesV1 = "azure-openai-responses-v1",
512
- XAIResponsesV1 = "xai-responses-v1",
513
- AnthropicClaudeV1 = "anthropic-claude-v1",
514
- GoogleGeminiV1 = "google-gemini-v1"
515
- }
516
-
517
- declare enum ReasoningDetailType {
518
- Summary = "reasoning.summary",
519
- Encrypted = "reasoning.encrypted",
520
- Text = "reasoning.text"
521
- }
522
- declare const ReasoningDetailUnionSchema: z.ZodUnion<readonly [z.ZodObject<{
523
- type: z.ZodLiteral<ReasoningDetailType.Summary>;
524
- summary: z.ZodString;
525
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
526
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
527
- index: z.ZodOptional<z.ZodNumber>;
528
- }, z.core.$strip>, z.ZodObject<{
529
- type: z.ZodLiteral<ReasoningDetailType.Encrypted>;
530
- data: z.ZodString;
531
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
532
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
533
- index: z.ZodOptional<z.ZodNumber>;
534
- }, z.core.$strip>, z.ZodObject<{
535
- type: z.ZodLiteral<ReasoningDetailType.Text>;
536
- text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
537
- signature: z.ZodOptional<z.ZodNullable<z.ZodString>>;
538
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
539
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
540
- index: z.ZodOptional<z.ZodNumber>;
541
- }, z.core.$strip>]>;
542
- type ReasoningDetailUnion = z.infer<typeof ReasoningDetailUnionSchema>;
543
-
544
- type OpenRouterChatConfig = {
545
- provider: string;
546
- compatibility: 'strict' | 'compatible';
547
- headers: () => Record<string, string | undefined>;
548
- url: (options: {
549
- modelId: string;
550
- path: string;
551
- }) => string;
552
- fetch?: typeof fetch;
553
- extraBody?: Record<string, unknown>;
554
- };
555
- declare class OpenRouterChatLanguageModel implements LanguageModelV3 {
556
- readonly specificationVersion: "v3";
557
- readonly provider = "openrouter";
558
- readonly defaultObjectGenerationMode: "tool";
559
- readonly modelId: OpenRouterChatModelId;
560
- readonly supportsImageUrls = true;
561
- readonly supportedUrls: Record<string, RegExp[]>;
562
- readonly settings: OpenRouterChatSettings;
563
- private readonly config;
564
- constructor(modelId: OpenRouterChatModelId, settings: OpenRouterChatSettings, config: OpenRouterChatConfig);
565
- private getArgs;
566
- doGenerate(options: LanguageModelV3CallOptions): Promise<{
567
- content: Array<LanguageModelV3Content>;
568
- finishReason: LanguageModelV3FinishReason;
569
- usage: LanguageModelV3Usage;
570
- warnings: Array<SharedV3Warning>;
571
- providerMetadata?: {
572
- openrouter: {
573
- provider: string;
574
- reasoning_details?: ReasoningDetailUnion[];
575
- usage: OpenRouterUsageAccounting;
576
- };
577
- };
578
- request?: {
579
- body?: unknown;
580
- };
581
- response?: LanguageModelV3ResponseMetadata & {
582
- headers?: SharedV3Headers;
583
- body?: unknown;
584
- };
585
- }>;
586
- doStream(options: LanguageModelV3CallOptions): Promise<{
587
- stream: ReadableStream<LanguageModelV3StreamPart>;
588
- warnings: Array<SharedV3Warning>;
589
- request?: {
590
- body?: unknown;
591
- };
592
- response?: LanguageModelV3ResponseMetadata & {
593
- headers?: SharedV3Headers;
594
- body?: unknown;
595
- };
596
- }>;
597
- }
598
-
599
- type OpenRouterCompletionConfig = {
600
- provider: string;
601
- compatibility: 'strict' | 'compatible';
602
- headers: () => Record<string, string | undefined>;
603
- url: (options: {
604
- modelId: string;
605
- path: string;
606
- }) => string;
607
- fetch?: typeof fetch;
608
- extraBody?: Record<string, unknown>;
609
- };
610
- declare class OpenRouterCompletionLanguageModel implements LanguageModelV3 {
611
- readonly specificationVersion: "v3";
612
- readonly provider = "openrouter";
613
- readonly modelId: OpenRouterCompletionModelId;
614
- readonly supportsImageUrls = true;
615
- readonly supportedUrls: Record<string, RegExp[]>;
616
- readonly defaultObjectGenerationMode: undefined;
617
- readonly settings: OpenRouterCompletionSettings;
618
- private readonly config;
619
- constructor(modelId: OpenRouterCompletionModelId, settings: OpenRouterCompletionSettings, config: OpenRouterCompletionConfig);
620
- private getArgs;
621
- doGenerate(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
622
- doStream(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
623
- }
624
-
625
- type OpenRouterEmbeddingConfig = {
626
- provider: string;
627
- headers: () => Record<string, string | undefined>;
628
- url: (options: {
629
- modelId: string;
630
- path: string;
631
- }) => string;
632
- fetch?: typeof fetch;
633
- extraBody?: Record<string, unknown>;
634
- };
635
- declare class OpenRouterEmbeddingModel implements EmbeddingModelV3 {
636
- readonly specificationVersion: "v3";
637
- readonly provider = "openrouter";
638
- readonly modelId: OpenRouterEmbeddingModelId;
639
- readonly settings: OpenRouterEmbeddingSettings;
640
- readonly maxEmbeddingsPerCall: undefined;
641
- readonly supportsParallelCalls = true;
642
- private readonly config;
643
- constructor(modelId: OpenRouterEmbeddingModelId, settings: OpenRouterEmbeddingSettings, config: OpenRouterEmbeddingConfig);
644
- doEmbed(options: {
645
- values: Array<string>;
646
- abortSignal?: AbortSignal;
647
- headers?: Record<string, string | undefined>;
648
- }): Promise<{
649
- embeddings: Array<Array<number>>;
650
- usage?: {
651
- tokens: number;
652
- };
653
- providerMetadata?: SharedV3ProviderMetadata;
654
- response?: {
655
- headers?: SharedV3Headers;
656
- body?: unknown;
657
- };
658
- warnings: Array<_ai_sdk_provider.SharedV3Warning>;
659
- }>;
660
- }
661
-
662
- type OpenRouterImageConfig = {
663
- provider: string;
664
- headers: () => Record<string, string | undefined>;
665
- url: (options: {
666
- modelId: string;
667
- path: string;
668
- }) => string;
669
- fetch?: typeof fetch;
670
- extraBody?: Record<string, unknown>;
671
- };
672
- declare class OpenRouterImageModel implements ImageModelV3 {
673
- readonly specificationVersion: "v3";
674
- readonly provider = "openrouter";
675
- readonly modelId: OpenRouterImageModelId;
676
- readonly settings: OpenRouterImageSettings;
677
- readonly maxImagesPerCall = 1;
678
- private readonly config;
679
- constructor(modelId: OpenRouterImageModelId, settings: OpenRouterImageSettings, config: OpenRouterImageConfig);
680
- doGenerate(options: ImageModelV3CallOptions): Promise<{
681
- images: Array<string>;
682
- warnings: Array<SharedV3Warning>;
683
- providerMetadata?: ImageModelV3ProviderMetadata;
684
- response: {
685
- timestamp: Date;
686
- modelId: string;
687
- headers: Record<string, string> | undefined;
688
- };
689
- usage?: ImageModelV3Usage;
690
- }>;
691
- }
692
-
693
- type OpenRouterVideoConfig = {
694
- provider: string;
695
- headers: () => Record<string, string | undefined>;
696
- url: (options: {
697
- modelId: string;
698
- path: string;
699
- }) => string;
700
- fetch?: typeof fetch;
701
- extraBody?: Record<string, unknown>;
702
- };
703
- declare class OpenRouterVideoModel implements Experimental_VideoModelV3 {
704
- readonly specificationVersion = "v3";
705
- readonly provider = "openrouter";
706
- readonly modelId: OpenRouterVideoModelId;
707
- readonly settings: OpenRouterVideoSettings;
708
- readonly maxVideosPerCall = 1;
709
- private readonly config;
710
- constructor(modelId: OpenRouterVideoModelId, settings: OpenRouterVideoSettings, config: OpenRouterVideoConfig);
711
- doGenerate(options: Experimental_VideoModelV3CallOptions): Promise<{
712
- videos: Array<Experimental_VideoModelV3VideoData>;
713
- warnings: Array<SharedV3Warning>;
714
- providerMetadata?: SharedV3ProviderMetadata;
715
- response: {
716
- timestamp: Date;
717
- modelId: string;
718
- headers: Record<string, string> | undefined;
719
- };
720
- }>;
721
- private pollUntilComplete;
722
- }
723
-
724
- /**
725
- * Configuration args for the web search provider tool.
726
- * These are mapped to snake_case in the API request.
727
- */
728
- type WebSearchToolArgs = {
729
- /** Maximum number of search results to include */
730
- maxResults?: number;
731
- /** Custom search prompt to guide the search query */
732
- searchPrompt?: string;
733
- /** Search engine to use: 'auto', 'native', or 'exa' */
734
- engine?: 'auto' | Engine;
735
- };
736
-
737
- interface OpenRouterProvider extends ProviderV3 {
738
- (modelId: OpenRouterChatModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
739
- (modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
740
- languageModel(modelId: OpenRouterChatModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
741
- languageModel(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
742
- /**
743
- Creates an OpenRouter chat model for text generation.
744
- */
745
- chat(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
746
- /**
747
- Creates an OpenRouter completion model for text generation.
748
- */
749
- completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
750
- /**
751
- Creates an OpenRouter text embedding model. (AI SDK v5)
752
- */
753
- textEmbeddingModel(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
754
- /**
755
- Creates an OpenRouter text embedding model. (AI SDK v4 - deprecated, use textEmbeddingModel instead)
756
- @deprecated Use textEmbeddingModel instead
757
- */
758
- embedding(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
759
- /**
760
- Creates an OpenRouter image model for image generation.
761
- */
762
- imageModel(modelId: OpenRouterImageModelId, settings?: OpenRouterImageSettings): OpenRouterImageModel;
763
- /**
764
- Creates an OpenRouter video model for video generation.
765
- */
766
- videoModel(modelId: OpenRouterVideoModelId, settings?: OpenRouterVideoSettings): OpenRouterVideoModel;
767
- /**
768
- * Provider-defined tools for OpenRouter server tools.
769
- */
770
- readonly tools: {
771
- /**
772
- * Creates an OpenRouter web search server tool.
773
- *
774
- * @see https://openrouter.ai/docs/guides/features/server-tools/web-search
775
- */
776
- webSearch: ProviderToolFactory<unknown, WebSearchToolArgs>;
777
- };
778
- }
779
- interface OpenRouterProviderSettings {
780
- /**
781
- Base URL for the OpenRouter API calls.
782
- */
783
- baseURL?: string;
784
- /**
785
- @deprecated Use `baseURL` instead.
786
- */
787
- baseUrl?: string;
788
- /**
789
- API key for authenticating requests.
790
- */
791
- apiKey?: string;
792
- /**
793
- Custom headers to include in the requests.
794
- */
795
- headers?: Record<string, string>;
796
- /**
797
- OpenRouter compatibility mode. Should be set to `strict` when using the OpenRouter API,
798
- and `compatible` when using 3rd party providers. In `compatible` mode, newer
799
- information such as streamOptions are not being sent. Defaults to 'compatible'.
800
- */
801
- compatibility?: 'strict' | 'compatible';
802
- /**
803
- Custom fetch implementation. You can use it as a middleware to intercept requests,
804
- or to provide a custom fetch implementation for e.g. testing.
805
- */
806
- fetch?: typeof fetch;
807
- /**
808
- A JSON object to send as the request body to access OpenRouter features & upstream provider features.
809
- */
810
- extraBody?: Record<string, unknown>;
811
- /**
812
- * Record of provider slugs to API keys for injecting into provider routing.
813
- * Maps provider slugs (e.g. "anthropic", "openai") to their respective API keys.
814
- */
815
- api_keys?: Record<string, string>;
816
- /**
817
- * Your app's display name. Sets the `X-OpenRouter-Title` header on
818
- * every request for app attribution on the openrouter.ai dashboard.
819
- */
820
- appName?: string;
821
- /**
822
- * Your app's URL or identifier. Sets the `HTTP-Referer` header on every request,
823
- * used to identify your app on the openrouter.ai dashboard.
824
- */
825
- appUrl?: string;
826
- }
827
- /**
828
- Create an OpenRouter provider instance.
829
- */
830
- declare function createOpenRouter(options?: OpenRouterProviderSettings): OpenRouterProvider;
831
- /**
832
- Default OpenRouter provider instance. It uses 'strict' compatibility mode.
833
- */
834
- declare const openrouter: OpenRouterProvider;
835
-
836
- /**
837
- @deprecated Use `createOpenRouter` instead.
838
- */
839
- declare class OpenRouter {
840
- /**
841
- Use a different URL prefix for API calls, e.g. to use proxy servers.
842
- The default prefix is `https://openrouter.ai/api/v1`.
843
- */
844
- readonly baseURL: string;
845
- /**
846
- API key that is being sent using the `Authorization` header.
847
- It defaults to the `OPENROUTER_API_KEY` environment variable.
848
- */
849
- readonly apiKey?: string;
850
- /**
851
- Custom headers to include in the requests.
852
- */
853
- readonly headers?: Record<string, string>;
854
- /**
855
- * Record of provider slugs to API keys for injecting into provider routing.
856
- */
857
- readonly api_keys?: Record<string, string>;
858
- /**
859
- * App display name for the `X-OpenRouter-Title` header.
860
- */
861
- readonly appName?: string;
862
- /**
863
- * App URL for the `HTTP-Referer` header.
864
- */
865
- readonly appUrl?: string;
866
- /**
867
- * Creates a new OpenRouter provider instance.
868
- */
869
- constructor(options?: OpenRouterProviderSettings);
870
- private get baseConfig();
871
- chat(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
872
- completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
873
- textEmbeddingModel(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
874
- /**
875
- * @deprecated Use textEmbeddingModel instead
876
- */
877
- embedding(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
878
- }
879
-
880
- export { OpenRouter, type OpenRouterChatSettings, type OpenRouterCompletionSettings, type OpenRouterEmbeddingModelId, type OpenRouterEmbeddingSettings, type OpenRouterImageModelId, type OpenRouterImageSettings, type OpenRouterProvider, type OpenRouterProviderOptions, type OpenRouterProviderSettings, type OpenRouterSharedSettings, type OpenRouterUsageAccounting, type OpenRouterVideoModelId, type OpenRouterVideoSettings, createOpenRouter, openrouter };