@openrouter/ai-sdk-provider 1.4.0 → 1.5.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/README.md CHANGED
@@ -55,6 +55,64 @@ This list is not a definitive list of models supported by OpenRouter, as it cons
55
55
 
56
56
  You can find the latest list of tool-supported models supported by OpenRouter [here](https://openrouter.ai/models?order=newest&supported_parameters=tools). (Note: This list may contain models that are not compatible with the AI SDK.)
57
57
 
58
+ ## Embeddings
59
+
60
+ OpenRouter supports embedding models for semantic search, RAG pipelines, and vector-native features. The provider exposes embeddings compatible with both AI SDK v5 and v4.
61
+
62
+ ### AI SDK v5 (Recommended)
63
+
64
+ ```ts
65
+ import { embed } from 'ai';
66
+ import { openrouter } from '@openrouter/ai-sdk-provider';
67
+
68
+ const { embedding } = await embed({
69
+ model: openrouter.textEmbeddingModel('openai/text-embedding-3-small'),
70
+ value: 'sunny day at the beach',
71
+ });
72
+
73
+ console.log(embedding); // Array of numbers representing the embedding
74
+ ```
75
+
76
+ ### Batch Embeddings
77
+
78
+ ```ts
79
+ import { embedMany } from 'ai';
80
+ import { openrouter } from '@openrouter/ai-sdk-provider';
81
+
82
+ const { embeddings } = await embedMany({
83
+ model: openrouter.textEmbeddingModel('openai/text-embedding-3-small'),
84
+ values: [
85
+ 'sunny day at the beach',
86
+ 'rainy day in the city',
87
+ 'snowy mountain peak',
88
+ ],
89
+ });
90
+
91
+ console.log(embeddings); // Array of embedding arrays
92
+ ```
93
+
94
+ ### AI SDK v4 (Deprecated)
95
+
96
+ For backwards compatibility, the `embedding` method is also available:
97
+
98
+ ```ts
99
+ import { embed } from 'ai';
100
+ import { openrouter } from '@openrouter/ai-sdk-provider';
101
+
102
+ const { embedding } = await embed({
103
+ model: openrouter.embedding('openai/text-embedding-3-small'),
104
+ value: 'sunny day at the beach',
105
+ });
106
+ ```
107
+
108
+ ### Supported Embedding Models
109
+
110
+ OpenRouter supports various embedding models including:
111
+ - `openai/text-embedding-3-small`
112
+ - `openai/text-embedding-3-large`
113
+ - `openai/text-embedding-ada-002`
114
+ - And more available on [OpenRouter](https://openrouter.ai/models?output_modalities=embeddings)
115
+
58
116
  ## Passing Extra Body to OpenRouter
59
117
 
60
118
  There are 3 ways to pass extra body to OpenRouter:
package/dist/index.d.mts CHANGED
@@ -1,7 +1,9 @@
1
- import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart, ProviderV2 } from '@ai-sdk/provider';
1
+ import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart, EmbeddingModelV2, SharedV2ProviderMetadata, ProviderV2 } from '@ai-sdk/provider';
2
2
  export { LanguageModelV2, LanguageModelV2Prompt } from '@ai-sdk/provider';
3
3
  import * as models from '@openrouter/sdk/models';
4
4
  import { z } from 'zod/v4';
5
+ import { EncodeOptions, DecodeOptions, JsonValue } from '@toon-format/toon';
6
+ export { DecodeOptions, EncodeOptions, JsonValue } from '@toon-format/toon';
5
7
 
6
8
  type OpenRouterChatModelId = string;
7
9
  type OpenRouterChatSettings = {
@@ -70,6 +72,14 @@ type OpenRouterChatSettings = {
70
72
  * Custom search prompt to guide the search query
71
73
  */
72
74
  search_prompt?: string;
75
+ /**
76
+ * Search engine to use for web search
77
+ * - "native": Use provider's built-in web search
78
+ * - "exa": Use Exa's search API
79
+ * - undefined: Native if supported, otherwise Exa
80
+ * @see https://openrouter.ai/docs/features/web-search
81
+ */
82
+ engine?: models.Engine;
73
83
  };
74
84
  /**
75
85
  * Debug options for troubleshooting API requests.
@@ -130,6 +140,63 @@ type OpenRouterChatSettings = {
130
140
  audio?: number | string;
131
141
  request?: number | string;
132
142
  };
143
+ /**
144
+ * Whether to restrict routing to only ZDR (Zero Data Retention) endpoints.
145
+ * When true, only endpoints that do not retain prompts will be used.
146
+ */
147
+ zdr?: boolean;
148
+ };
149
+ } & OpenRouterSharedSettings;
150
+
151
+ type OpenRouterEmbeddingModelId = string;
152
+ type OpenRouterEmbeddingSettings = {
153
+ /**
154
+ * A unique identifier representing your end-user, which can help OpenRouter to
155
+ * monitor and detect abuse.
156
+ */
157
+ user?: string;
158
+ /**
159
+ * Provider routing preferences to control request routing behavior
160
+ */
161
+ provider?: {
162
+ /**
163
+ * List of provider slugs to try in order (e.g. ["openai", "voyageai"])
164
+ */
165
+ order?: string[];
166
+ /**
167
+ * Whether to allow backup providers when primary is unavailable (default: true)
168
+ */
169
+ allow_fallbacks?: boolean;
170
+ /**
171
+ * Only use providers that support all parameters in your request (default: false)
172
+ */
173
+ require_parameters?: boolean;
174
+ /**
175
+ * Control whether to use providers that may store data
176
+ */
177
+ data_collection?: 'allow' | 'deny';
178
+ /**
179
+ * List of provider slugs to allow for this request
180
+ */
181
+ only?: string[];
182
+ /**
183
+ * List of provider slugs to skip for this request
184
+ */
185
+ ignore?: string[];
186
+ /**
187
+ * Sort providers by price, throughput, or latency
188
+ */
189
+ sort?: 'price' | 'throughput' | 'latency';
190
+ /**
191
+ * Maximum pricing you want to pay for this request
192
+ */
193
+ max_price?: {
194
+ prompt?: number | string;
195
+ completion?: number | string;
196
+ image?: number | string;
197
+ audio?: number | string;
198
+ request?: number | string;
199
+ };
133
200
  };
134
201
  } & OpenRouterSharedSettings;
135
202
 
@@ -342,6 +409,42 @@ declare class OpenRouterCompletionLanguageModel implements LanguageModelV2 {
342
409
  doStream(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
343
410
  }
344
411
 
412
+ type OpenRouterEmbeddingConfig = {
413
+ provider: string;
414
+ headers: () => Record<string, string | undefined>;
415
+ url: (options: {
416
+ modelId: string;
417
+ path: string;
418
+ }) => string;
419
+ fetch?: typeof fetch;
420
+ extraBody?: Record<string, unknown>;
421
+ };
422
+ declare class OpenRouterEmbeddingModel implements EmbeddingModelV2<string> {
423
+ readonly specificationVersion: "v2";
424
+ readonly provider = "openrouter";
425
+ readonly modelId: OpenRouterEmbeddingModelId;
426
+ readonly settings: OpenRouterEmbeddingSettings;
427
+ readonly maxEmbeddingsPerCall: undefined;
428
+ readonly supportsParallelCalls = true;
429
+ private readonly config;
430
+ constructor(modelId: OpenRouterEmbeddingModelId, settings: OpenRouterEmbeddingSettings, config: OpenRouterEmbeddingConfig);
431
+ doEmbed(options: {
432
+ values: Array<string>;
433
+ abortSignal?: AbortSignal;
434
+ headers?: Record<string, string | undefined>;
435
+ }): Promise<{
436
+ embeddings: Array<Array<number>>;
437
+ usage?: {
438
+ tokens: number;
439
+ };
440
+ providerMetadata?: SharedV2ProviderMetadata;
441
+ response?: {
442
+ headers?: SharedV2Headers;
443
+ body?: unknown;
444
+ };
445
+ }>;
446
+ }
447
+
345
448
  interface OpenRouterProvider extends ProviderV2 {
346
449
  (modelId: OpenRouterChatModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
347
450
  (modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
@@ -355,6 +458,15 @@ interface OpenRouterProvider extends ProviderV2 {
355
458
  Creates an OpenRouter completion model for text generation.
356
459
  */
357
460
  completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
461
+ /**
462
+ Creates an OpenRouter text embedding model. (AI SDK v5)
463
+ */
464
+ textEmbeddingModel(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
465
+ /**
466
+ Creates an OpenRouter text embedding model. (AI SDK v4 - deprecated, use textEmbeddingModel instead)
467
+ @deprecated Use textEmbeddingModel instead
468
+ */
469
+ embedding(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
358
470
  }
359
471
  interface OpenRouterProviderSettings {
360
472
  /**
@@ -388,6 +500,11 @@ interface OpenRouterProviderSettings {
388
500
  A JSON object to send as the request body to access OpenRouter features & upstream provider features.
389
501
  */
390
502
  extraBody?: Record<string, unknown>;
503
+ /**
504
+ * Record of provider slugs to API keys for injecting into provider routing.
505
+ * Maps provider slugs (e.g. "anthropic", "openai") to their respective API keys.
506
+ */
507
+ api_keys?: Record<string, string>;
391
508
  }
392
509
  /**
393
510
  Create an OpenRouter provider instance.
@@ -416,6 +533,10 @@ declare class OpenRouter {
416
533
  Custom headers to include in the requests.
417
534
  */
418
535
  readonly headers?: Record<string, string>;
536
+ /**
537
+ * Record of provider slugs to API keys for injecting into provider routing.
538
+ */
539
+ readonly api_keys?: Record<string, string>;
419
540
  /**
420
541
  * Creates a new OpenRouter provider instance.
421
542
  */
@@ -423,6 +544,91 @@ declare class OpenRouter {
423
544
  private get baseConfig();
424
545
  chat(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
425
546
  completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
547
+ textEmbeddingModel(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
548
+ /**
549
+ * @deprecated Use textEmbeddingModel instead
550
+ */
551
+ embedding(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
426
552
  }
427
553
 
428
- export { OpenRouter, type OpenRouterCompletionSettings, type OpenRouterProvider, type OpenRouterProviderOptions, type OpenRouterProviderSettings, type OpenRouterSharedSettings, type OpenRouterUsageAccounting, createOpenRouter, openrouter };
554
+ /**
555
+ * TOON (Token-Oriented Object Notation) helper utilities for token-efficient
556
+ * data encoding in LLM prompts.
557
+ *
558
+ * TOON achieves ~40% token reduction vs JSON for tabular data while maintaining
559
+ * high LLM comprehension accuracy.
560
+ *
561
+ * @see https://toonformat.dev
562
+ * @see https://github.com/toon-format/toon
563
+ *
564
+ * @example
565
+ * ```ts
566
+ * import { encodeToon, decodeToon } from '@openrouter/ai-sdk-provider';
567
+ *
568
+ * // Encode data to TOON format
569
+ * const toon = await encodeToon([
570
+ * { id: 1, name: 'Alice', score: 95 },
571
+ * { id: 2, name: 'Bob', score: 87 },
572
+ * ]);
573
+ * // Result: [2]{id,name,score}: 1,Alice,95 2,Bob,87
574
+ *
575
+ * // Decode TOON back to JSON
576
+ * const data = await decodeToon(toon);
577
+ * ```
578
+ */
579
+
580
+ type ToonEncodeOptions = EncodeOptions;
581
+ type ToonDecodeOptions = DecodeOptions;
582
+ /**
583
+ * Encodes a JavaScript value into TOON format string.
584
+ *
585
+ * TOON is particularly efficient for uniform arrays of objects (tabular data),
586
+ * achieving CSV-like compactness while preserving explicit structure.
587
+ *
588
+ * @param value - Any JavaScript value (objects, arrays, primitives)
589
+ * @param options - Optional encoding configuration
590
+ * @returns Promise resolving to TOON formatted string
591
+ *
592
+ * @example
593
+ * ```ts
594
+ * // Simple object
595
+ * await encodeToon({ name: 'Alice', age: 30 });
596
+ * // name: Alice
597
+ * // age: 30
598
+ *
599
+ * // Tabular array (most efficient)
600
+ * await encodeToon([
601
+ * { id: 1, name: 'Alice' },
602
+ * { id: 2, name: 'Bob' },
603
+ * ]);
604
+ * // [2]{id,name}: 1,Alice 2,Bob
605
+ *
606
+ * // With options
607
+ * await encodeToon(data, { indent: 4, keyFolding: 'safe' });
608
+ * ```
609
+ */
610
+ declare function encodeToon(value: unknown, options?: ToonEncodeOptions): Promise<string>;
611
+ /**
612
+ * Decodes a TOON format string into a JavaScript value.
613
+ *
614
+ * @param input - TOON formatted string
615
+ * @param options - Optional decoding configuration
616
+ * @returns Promise resolving to parsed JavaScript value
617
+ *
618
+ * @example
619
+ * ```ts
620
+ * // Decode simple object
621
+ * await decodeToon('name: Alice\nage: 30');
622
+ * // { name: 'Alice', age: 30 }
623
+ *
624
+ * // Decode tabular array
625
+ * await decodeToon('[2]{id,name}: 1,Alice 2,Bob');
626
+ * // [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]
627
+ *
628
+ * // With options
629
+ * await decodeToon(toonString, { strict: false, expandPaths: 'safe' });
630
+ * ```
631
+ */
632
+ declare function decodeToon(input: string, options?: ToonDecodeOptions): Promise<JsonValue>;
633
+
634
+ export { OpenRouter, type OpenRouterChatSettings, type OpenRouterCompletionSettings, type OpenRouterEmbeddingModelId, type OpenRouterEmbeddingSettings, type OpenRouterProvider, type OpenRouterProviderOptions, type OpenRouterProviderSettings, type OpenRouterSharedSettings, type OpenRouterUsageAccounting, type ToonDecodeOptions, type ToonEncodeOptions, createOpenRouter, decodeToon, encodeToon, openrouter };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart, ProviderV2 } from '@ai-sdk/provider';
1
+ import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart, EmbeddingModelV2, SharedV2ProviderMetadata, ProviderV2 } from '@ai-sdk/provider';
2
2
  export { LanguageModelV2, LanguageModelV2Prompt } from '@ai-sdk/provider';
3
3
  import * as models from '@openrouter/sdk/models';
4
4
  import { z } from 'zod/v4';
5
+ import { EncodeOptions, DecodeOptions, JsonValue } from '@toon-format/toon';
6
+ export { DecodeOptions, EncodeOptions, JsonValue } from '@toon-format/toon';
5
7
 
6
8
  type OpenRouterChatModelId = string;
7
9
  type OpenRouterChatSettings = {
@@ -70,6 +72,14 @@ type OpenRouterChatSettings = {
70
72
  * Custom search prompt to guide the search query
71
73
  */
72
74
  search_prompt?: string;
75
+ /**
76
+ * Search engine to use for web search
77
+ * - "native": Use provider's built-in web search
78
+ * - "exa": Use Exa's search API
79
+ * - undefined: Native if supported, otherwise Exa
80
+ * @see https://openrouter.ai/docs/features/web-search
81
+ */
82
+ engine?: models.Engine;
73
83
  };
74
84
  /**
75
85
  * Debug options for troubleshooting API requests.
@@ -130,6 +140,63 @@ type OpenRouterChatSettings = {
130
140
  audio?: number | string;
131
141
  request?: number | string;
132
142
  };
143
+ /**
144
+ * Whether to restrict routing to only ZDR (Zero Data Retention) endpoints.
145
+ * When true, only endpoints that do not retain prompts will be used.
146
+ */
147
+ zdr?: boolean;
148
+ };
149
+ } & OpenRouterSharedSettings;
150
+
151
+ type OpenRouterEmbeddingModelId = string;
152
+ type OpenRouterEmbeddingSettings = {
153
+ /**
154
+ * A unique identifier representing your end-user, which can help OpenRouter to
155
+ * monitor and detect abuse.
156
+ */
157
+ user?: string;
158
+ /**
159
+ * Provider routing preferences to control request routing behavior
160
+ */
161
+ provider?: {
162
+ /**
163
+ * List of provider slugs to try in order (e.g. ["openai", "voyageai"])
164
+ */
165
+ order?: string[];
166
+ /**
167
+ * Whether to allow backup providers when primary is unavailable (default: true)
168
+ */
169
+ allow_fallbacks?: boolean;
170
+ /**
171
+ * Only use providers that support all parameters in your request (default: false)
172
+ */
173
+ require_parameters?: boolean;
174
+ /**
175
+ * Control whether to use providers that may store data
176
+ */
177
+ data_collection?: 'allow' | 'deny';
178
+ /**
179
+ * List of provider slugs to allow for this request
180
+ */
181
+ only?: string[];
182
+ /**
183
+ * List of provider slugs to skip for this request
184
+ */
185
+ ignore?: string[];
186
+ /**
187
+ * Sort providers by price, throughput, or latency
188
+ */
189
+ sort?: 'price' | 'throughput' | 'latency';
190
+ /**
191
+ * Maximum pricing you want to pay for this request
192
+ */
193
+ max_price?: {
194
+ prompt?: number | string;
195
+ completion?: number | string;
196
+ image?: number | string;
197
+ audio?: number | string;
198
+ request?: number | string;
199
+ };
133
200
  };
134
201
  } & OpenRouterSharedSettings;
135
202
 
@@ -342,6 +409,42 @@ declare class OpenRouterCompletionLanguageModel implements LanguageModelV2 {
342
409
  doStream(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
343
410
  }
344
411
 
412
+ type OpenRouterEmbeddingConfig = {
413
+ provider: string;
414
+ headers: () => Record<string, string | undefined>;
415
+ url: (options: {
416
+ modelId: string;
417
+ path: string;
418
+ }) => string;
419
+ fetch?: typeof fetch;
420
+ extraBody?: Record<string, unknown>;
421
+ };
422
+ declare class OpenRouterEmbeddingModel implements EmbeddingModelV2<string> {
423
+ readonly specificationVersion: "v2";
424
+ readonly provider = "openrouter";
425
+ readonly modelId: OpenRouterEmbeddingModelId;
426
+ readonly settings: OpenRouterEmbeddingSettings;
427
+ readonly maxEmbeddingsPerCall: undefined;
428
+ readonly supportsParallelCalls = true;
429
+ private readonly config;
430
+ constructor(modelId: OpenRouterEmbeddingModelId, settings: OpenRouterEmbeddingSettings, config: OpenRouterEmbeddingConfig);
431
+ doEmbed(options: {
432
+ values: Array<string>;
433
+ abortSignal?: AbortSignal;
434
+ headers?: Record<string, string | undefined>;
435
+ }): Promise<{
436
+ embeddings: Array<Array<number>>;
437
+ usage?: {
438
+ tokens: number;
439
+ };
440
+ providerMetadata?: SharedV2ProviderMetadata;
441
+ response?: {
442
+ headers?: SharedV2Headers;
443
+ body?: unknown;
444
+ };
445
+ }>;
446
+ }
447
+
345
448
  interface OpenRouterProvider extends ProviderV2 {
346
449
  (modelId: OpenRouterChatModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
347
450
  (modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
@@ -355,6 +458,15 @@ interface OpenRouterProvider extends ProviderV2 {
355
458
  Creates an OpenRouter completion model for text generation.
356
459
  */
357
460
  completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
461
+ /**
462
+ Creates an OpenRouter text embedding model. (AI SDK v5)
463
+ */
464
+ textEmbeddingModel(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
465
+ /**
466
+ Creates an OpenRouter text embedding model. (AI SDK v4 - deprecated, use textEmbeddingModel instead)
467
+ @deprecated Use textEmbeddingModel instead
468
+ */
469
+ embedding(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
358
470
  }
359
471
  interface OpenRouterProviderSettings {
360
472
  /**
@@ -388,6 +500,11 @@ interface OpenRouterProviderSettings {
388
500
  A JSON object to send as the request body to access OpenRouter features & upstream provider features.
389
501
  */
390
502
  extraBody?: Record<string, unknown>;
503
+ /**
504
+ * Record of provider slugs to API keys for injecting into provider routing.
505
+ * Maps provider slugs (e.g. "anthropic", "openai") to their respective API keys.
506
+ */
507
+ api_keys?: Record<string, string>;
391
508
  }
392
509
  /**
393
510
  Create an OpenRouter provider instance.
@@ -416,6 +533,10 @@ declare class OpenRouter {
416
533
  Custom headers to include in the requests.
417
534
  */
418
535
  readonly headers?: Record<string, string>;
536
+ /**
537
+ * Record of provider slugs to API keys for injecting into provider routing.
538
+ */
539
+ readonly api_keys?: Record<string, string>;
419
540
  /**
420
541
  * Creates a new OpenRouter provider instance.
421
542
  */
@@ -423,6 +544,91 @@ declare class OpenRouter {
423
544
  private get baseConfig();
424
545
  chat(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
425
546
  completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
547
+ textEmbeddingModel(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
548
+ /**
549
+ * @deprecated Use textEmbeddingModel instead
550
+ */
551
+ embedding(modelId: OpenRouterEmbeddingModelId, settings?: OpenRouterEmbeddingSettings): OpenRouterEmbeddingModel;
426
552
  }
427
553
 
428
- export { OpenRouter, type OpenRouterCompletionSettings, type OpenRouterProvider, type OpenRouterProviderOptions, type OpenRouterProviderSettings, type OpenRouterSharedSettings, type OpenRouterUsageAccounting, createOpenRouter, openrouter };
554
+ /**
555
+ * TOON (Token-Oriented Object Notation) helper utilities for token-efficient
556
+ * data encoding in LLM prompts.
557
+ *
558
+ * TOON achieves ~40% token reduction vs JSON for tabular data while maintaining
559
+ * high LLM comprehension accuracy.
560
+ *
561
+ * @see https://toonformat.dev
562
+ * @see https://github.com/toon-format/toon
563
+ *
564
+ * @example
565
+ * ```ts
566
+ * import { encodeToon, decodeToon } from '@openrouter/ai-sdk-provider';
567
+ *
568
+ * // Encode data to TOON format
569
+ * const toon = await encodeToon([
570
+ * { id: 1, name: 'Alice', score: 95 },
571
+ * { id: 2, name: 'Bob', score: 87 },
572
+ * ]);
573
+ * // Result: [2]{id,name,score}: 1,Alice,95 2,Bob,87
574
+ *
575
+ * // Decode TOON back to JSON
576
+ * const data = await decodeToon(toon);
577
+ * ```
578
+ */
579
+
580
+ type ToonEncodeOptions = EncodeOptions;
581
+ type ToonDecodeOptions = DecodeOptions;
582
+ /**
583
+ * Encodes a JavaScript value into TOON format string.
584
+ *
585
+ * TOON is particularly efficient for uniform arrays of objects (tabular data),
586
+ * achieving CSV-like compactness while preserving explicit structure.
587
+ *
588
+ * @param value - Any JavaScript value (objects, arrays, primitives)
589
+ * @param options - Optional encoding configuration
590
+ * @returns Promise resolving to TOON formatted string
591
+ *
592
+ * @example
593
+ * ```ts
594
+ * // Simple object
595
+ * await encodeToon({ name: 'Alice', age: 30 });
596
+ * // name: Alice
597
+ * // age: 30
598
+ *
599
+ * // Tabular array (most efficient)
600
+ * await encodeToon([
601
+ * { id: 1, name: 'Alice' },
602
+ * { id: 2, name: 'Bob' },
603
+ * ]);
604
+ * // [2]{id,name}: 1,Alice 2,Bob
605
+ *
606
+ * // With options
607
+ * await encodeToon(data, { indent: 4, keyFolding: 'safe' });
608
+ * ```
609
+ */
610
+ declare function encodeToon(value: unknown, options?: ToonEncodeOptions): Promise<string>;
611
+ /**
612
+ * Decodes a TOON format string into a JavaScript value.
613
+ *
614
+ * @param input - TOON formatted string
615
+ * @param options - Optional decoding configuration
616
+ * @returns Promise resolving to parsed JavaScript value
617
+ *
618
+ * @example
619
+ * ```ts
620
+ * // Decode simple object
621
+ * await decodeToon('name: Alice\nage: 30');
622
+ * // { name: 'Alice', age: 30 }
623
+ *
624
+ * // Decode tabular array
625
+ * await decodeToon('[2]{id,name}: 1,Alice 2,Bob');
626
+ * // [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]
627
+ *
628
+ * // With options
629
+ * await decodeToon(toonString, { strict: false, expandPaths: 'safe' });
630
+ * ```
631
+ */
632
+ declare function decodeToon(input: string, options?: ToonDecodeOptions): Promise<JsonValue>;
633
+
634
+ export { OpenRouter, type OpenRouterChatSettings, type OpenRouterCompletionSettings, type OpenRouterEmbeddingModelId, type OpenRouterEmbeddingSettings, type OpenRouterProvider, type OpenRouterProviderOptions, type OpenRouterProviderSettings, type OpenRouterSharedSettings, type OpenRouterUsageAccounting, type ToonDecodeOptions, type ToonEncodeOptions, createOpenRouter, decodeToon, encodeToon, openrouter };