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