@openrouter/ai-sdk-provider 1.5.3 → 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.
@@ -1,410 +1,364 @@
1
- import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart } from '@ai-sdk/provider';
2
- export { LanguageModelV2, LanguageModelV2Prompt } from '@ai-sdk/provider';
3
- import { z } from 'zod/v4';
4
- import * as models from '@openrouter/sdk/models';
1
+ import { LanguageModelV3Usage, JSONObject, LanguageModelV3FinishReason, LanguageModelV3Prompt } from '@ai-sdk/provider';
2
+ import { ChatGenerationTokenUsage } from '@openrouter/sdk/models';
5
3
 
6
- declare enum ReasoningFormat {
7
- Unknown = "unknown",
8
- OpenAIResponsesV1 = "openai-responses-v1",
9
- XAIResponsesV1 = "xai-responses-v1",
10
- AnthropicClaudeV1 = "anthropic-claude-v1",
11
- GoogleGeminiV1 = "google-gemini-v1"
12
- }
13
-
14
- declare enum ReasoningDetailType {
15
- Summary = "reasoning.summary",
16
- Encrypted = "reasoning.encrypted",
17
- Text = "reasoning.text"
4
+ /**
5
+ * Raw usage data from OpenRouter API response.
6
+ */
7
+ interface OpenRouterRawUsage {
8
+ inputTokens?: number;
9
+ outputTokens?: number;
10
+ inputTokensDetails?: {
11
+ cachedTokens?: number;
12
+ };
13
+ outputTokensDetails?: {
14
+ reasoningTokens?: number;
15
+ };
18
16
  }
19
- declare const ReasoningDetailUnionSchema: z.ZodUnion<readonly [z.ZodObject<{
20
- type: z.ZodLiteral<ReasoningDetailType.Summary>;
21
- summary: z.ZodString;
22
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
23
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
24
- index: z.ZodOptional<z.ZodNumber>;
25
- }, z.core.$strip>, z.ZodObject<{
26
- type: z.ZodLiteral<ReasoningDetailType.Encrypted>;
27
- data: z.ZodString;
28
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
29
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
30
- index: z.ZodOptional<z.ZodNumber>;
31
- }, z.core.$strip>, z.ZodObject<{
32
- type: z.ZodLiteral<ReasoningDetailType.Text>;
33
- text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
34
- signature: z.ZodOptional<z.ZodNullable<z.ZodString>>;
35
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
36
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
37
- index: z.ZodOptional<z.ZodNumber>;
38
- }, z.core.$strip>]>;
39
- type ReasoningDetailUnion = z.infer<typeof ReasoningDetailUnionSchema>;
17
+ /**
18
+ * Builds a LanguageModelV3Usage object from OpenRouter API usage data.
19
+ *
20
+ * @param usage - The raw usage data from the OpenRouter API response.
21
+ * @returns A LanguageModelV3Usage object with standardized token counts.
22
+ */
23
+ declare function buildUsage(usage: OpenRouterRawUsage | undefined): LanguageModelV3Usage;
40
24
 
41
- type OpenRouterChatModelId = string;
42
- type OpenRouterChatSettings = {
43
- /**
44
- Modify the likelihood of specified tokens appearing in the completion.
45
-
46
- Accepts a JSON object that maps tokens (specified by their token ID in
47
- the GPT tokenizer) to an associated bias value from -100 to 100. You
48
- can use this tokenizer tool to convert text to token IDs. Mathematically,
49
- the bias is added to the logits generated by the model prior to sampling.
50
- The exact effect will vary per model, but values between -1 and 1 should
51
- decrease or increase likelihood of selection; values like -100 or 100
52
- should result in a ban or exclusive selection of the relevant token.
53
-
54
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
55
- token from being generated.
56
- */
57
- logitBias?: Record<number, number>;
58
- /**
59
- Return the log probabilities of the tokens. Including logprobs will increase
60
- the response size and can slow down response times. However, it can
61
- be useful to understand better how the model is behaving.
62
-
63
- Setting to true will return the log probabilities of the tokens that
64
- were generated.
65
-
66
- Setting to a number will return the log probabilities of the top n
67
- tokens that were generated.
68
- */
69
- logprobs?: boolean | number;
25
+ /**
26
+ * OpenRouter-specific provider metadata structure.
27
+ */
28
+ interface OpenRouterProviderMetadata {
70
29
  /**
71
- Whether to enable parallel function calling during tool use. Default to true.
30
+ * The response ID from OpenRouter.
72
31
  */
73
- parallelToolCalls?: boolean;
32
+ responseId?: string;
74
33
  /**
75
- A unique identifier representing your end-user, which can help OpenRouter to
76
- monitor and detect abuse. Learn more.
77
- */
78
- user?: string;
79
- /**
80
- * Plugin configurations for enabling various capabilities
34
+ * The upstream provider that served the request.
81
35
  */
82
- plugins?: Array<{
83
- id: models.IdWeb;
84
- max_results?: number;
85
- search_prompt?: string;
86
- engine?: models.Engine;
87
- } | {
88
- id: models.IdFileParser;
89
- max_files?: number;
90
- pdf?: {
91
- engine?: models.PdfEngine;
92
- };
93
- } | {
94
- id: models.IdModeration;
95
- }>;
36
+ provider?: string;
96
37
  /**
97
- * Built-in web search options for models that support native web search
38
+ * Detailed usage information.
98
39
  */
99
- web_search_options?: {
40
+ usage?: {
41
+ promptTokens?: number;
42
+ completionTokens?: number;
43
+ totalTokens?: number;
44
+ promptTokensDetails?: {
45
+ cachedTokens?: number;
46
+ cacheWriteTokens?: number;
47
+ audioTokens?: number;
48
+ videoTokens?: number;
49
+ };
50
+ completionTokensDetails?: {
51
+ reasoningTokens?: number;
52
+ imageTokens?: number;
53
+ };
100
54
  /**
101
- * Maximum number of search results to include
55
+ * Cost in USD (omit if unavailable).
102
56
  */
103
- max_results?: number;
57
+ cost?: number;
104
58
  /**
105
- * Custom search prompt to guide the search query
59
+ * Whether the request used BYOK (Bring Your Own Key).
106
60
  */
107
- search_prompt?: string;
61
+ isByok?: boolean;
108
62
  /**
109
- * Search engine to use for web search
110
- * - "native": Use provider's built-in web search
111
- * - "exa": Use Exa's search API
112
- * - undefined: Native if supported, otherwise Exa
113
- * @see https://openrouter.ai/docs/features/web-search
63
+ * Detailed cost breakdown.
114
64
  */
115
- engine?: models.Engine;
65
+ costDetails?: JSONObject;
116
66
  };
67
+ }
68
+ /**
69
+ * Extended prompt tokens details with fields not in SDK types.
70
+ */
71
+ interface ExtendedPromptTokensDetails {
72
+ cachedTokens?: number | null;
73
+ cacheWriteTokens?: number | null;
74
+ audioTokens?: number | null;
75
+ videoTokens?: number | null;
76
+ }
77
+ /**
78
+ * Extended completion tokens details with fields not in SDK types.
79
+ */
80
+ interface ExtendedCompletionTokensDetails {
81
+ reasoningTokens?: number | null;
82
+ imageTokens?: number | null;
83
+ }
84
+ /**
85
+ * Extended usage type with additional fields from raw OpenRouter API response.
86
+ * The SDK types don't include cost/is_byok but the API returns them.
87
+ */
88
+ interface OpenRouterUsageExtended extends Omit<ChatGenerationTokenUsage, 'promptTokensDetails' | 'completionTokensDetails'> {
89
+ cost?: number;
90
+ isByok?: boolean;
91
+ costDetails?: JSONObject;
92
+ promptTokensDetails?: ExtendedPromptTokensDetails | null;
93
+ completionTokensDetails?: ExtendedCompletionTokensDetails | null;
94
+ }
95
+ /**
96
+ * Response data from OpenRouter API used to build provider metadata.
97
+ * Note: The SDK transforms snake_case to camelCase for all fields.
98
+ * The `provider` field exists in raw API responses but isn't in SDK types.
99
+ */
100
+ interface OpenRouterResponseData {
101
+ id?: string;
117
102
  /**
118
- * Debug options for troubleshooting API requests.
119
- * Only works with streaming requests.
120
- * @see https://openrouter.ai/docs/api-reference/debugging
103
+ * The upstream provider that served the request (e.g. "Google", "Anthropic").
104
+ * This field exists in the raw API response but isn't in SDK TypeScript types.
121
105
  */
122
- debug?: {
123
- /**
124
- * When true, echoes back the request body that was sent to the upstream provider.
125
- * The debug data will be returned as the first chunk in the stream with a `debug.echo_upstream_body` field.
126
- * Sensitive data like user IDs and base64 content will be redacted.
127
- */
128
- echo_upstream_body?: boolean;
129
- };
106
+ provider?: string;
130
107
  /**
131
- * Provider routing preferences to control request routing behavior
108
+ * Usage data in camelCase (as transformed by SDK).
132
109
  */
133
- provider?: {
134
- /**
135
- * List of provider slugs to try in order (e.g. ["anthropic", "openai"])
136
- */
137
- order?: string[];
138
- /**
139
- * Whether to allow backup providers when primary is unavailable (default: true)
140
- */
141
- allow_fallbacks?: boolean;
142
- /**
143
- * Only use providers that support all parameters in your request (default: false)
144
- */
145
- require_parameters?: boolean;
146
- /**
147
- * Control whether to use providers that may store data
148
- */
149
- data_collection?: models.DataCollection;
150
- /**
151
- * List of provider slugs to allow for this request
152
- */
153
- only?: string[];
154
- /**
155
- * List of provider slugs to skip for this request
156
- */
157
- ignore?: string[];
158
- /**
159
- * List of quantization levels to filter by (e.g. ["int4", "int8"])
160
- */
161
- quantizations?: Array<models.Quantization>;
162
- /**
163
- * Sort providers by price, throughput, or latency
164
- */
165
- sort?: models.ProviderSort;
166
- /**
167
- * Maximum pricing you want to pay for this request
168
- */
169
- max_price?: {
170
- prompt?: number | string;
171
- completion?: number | string;
172
- image?: number | string;
173
- audio?: number | string;
174
- request?: number | string;
175
- };
176
- /**
177
- * Whether to restrict routing to only ZDR (Zero Data Retention) endpoints.
178
- * When true, only endpoints that do not retain prompts will be used.
179
- */
180
- zdr?: boolean;
181
- };
182
- } & OpenRouterSharedSettings;
110
+ usage?: OpenRouterUsageExtended;
111
+ }
112
+ /**
113
+ * Builds provider metadata from OpenRouter API response data.
114
+ *
115
+ * @param response - The response data from OpenRouter API (with camelCase fields from SDK).
116
+ * @returns Provider metadata in the format expected by AI SDK.
117
+ */
118
+ declare function buildProviderMetadata(response: OpenRouterResponseData | undefined): Record<string, JSONObject> | undefined;
183
119
 
184
- type OpenRouterCompletionModelId = string;
185
- type OpenRouterCompletionSettings = {
120
+ /**
121
+ * Configuration for an OpenRouter plugin.
122
+ *
123
+ * @description
124
+ * Plugins extend OpenRouter functionality with features like web search, code execution,
125
+ * and more. Each plugin has a unique identifier and optional configuration parameters.
126
+ * Additional plugin-specific properties can be included as needed.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * const model = openrouter('anthropic/claude-3.5-sonnet', {
131
+ * plugins: [
132
+ * { id: 'web-search' },
133
+ * { id: 'code-interpreter', config: { timeout: 30000 } },
134
+ * ],
135
+ * });
136
+ * ```
137
+ */
138
+ interface OpenRouterPluginConfig {
186
139
  /**
187
- Modify the likelihood of specified tokens appearing in the completion.
188
-
189
- Accepts a JSON object that maps tokens (specified by their token ID in
190
- the GPT tokenizer) to an associated bias value from -100 to 100. You
191
- can use this tokenizer tool to convert text to token IDs. Mathematically,
192
- the bias is added to the logits generated by the model prior to sampling.
193
- The exact effect will vary per model, but values between -1 and 1 should
194
- decrease or increase likelihood of selection; values like -100 or 100
195
- should result in a ban or exclusive selection of the relevant token.
196
-
197
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
198
- token from being generated.
140
+ * The plugin identifier.
199
141
  */
200
- logitBias?: Record<number, number>;
142
+ id: string;
201
143
  /**
202
- Return the log probabilities of the tokens. Including logprobs will increase
203
- the response size and can slow down response times. However, it can
204
- be useful to better understand how the model is behaving.
205
-
206
- Setting to true will return the log probabilities of the tokens that
207
- were generated.
208
-
209
- Setting to a number will return the log probabilities of the top n
210
- tokens that were generated.
144
+ * Plugin-specific configuration.
211
145
  */
212
- logprobs?: boolean | number;
146
+ config?: Record<string, unknown>;
213
147
  /**
214
- The suffix that comes after a completion of inserted text.
148
+ * Allow any additional plugin-specific properties.
215
149
  */
216
- suffix?: string;
217
- } & OpenRouterSharedSettings;
218
-
219
- type OpenRouterCompletionConfig = {
220
- provider: string;
221
- compatibility: 'strict' | 'compatible';
222
- headers: () => Record<string, string | undefined>;
223
- url: (options: {
224
- modelId: string;
225
- path: string;
226
- }) => string;
227
- fetch?: typeof fetch;
228
- extraBody?: Record<string, unknown>;
229
- };
230
- declare class OpenRouterCompletionLanguageModel implements LanguageModelV2 {
231
- readonly specificationVersion: "v2";
232
- readonly provider = "openrouter";
233
- readonly modelId: OpenRouterCompletionModelId;
234
- readonly supportsImageUrls = true;
235
- readonly supportedUrls: Record<string, RegExp[]>;
236
- readonly defaultObjectGenerationMode: undefined;
237
- readonly settings: OpenRouterCompletionSettings;
238
- private readonly config;
239
- constructor(modelId: OpenRouterCompletionModelId, settings: OpenRouterCompletionSettings, config: OpenRouterCompletionConfig);
240
- private getArgs;
241
- doGenerate(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>;
242
- doStream(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
150
+ [key: string]: unknown;
243
151
  }
244
-
245
- type OpenRouterEmbeddingModelId = string;
246
- type OpenRouterEmbeddingSettings = {
152
+ /**
153
+ * Configuration for OpenRouter's provider routing behavior.
154
+ *
155
+ * @description
156
+ * Controls how OpenRouter selects and falls back between different AI providers
157
+ * when routing requests. Use this to specify provider preferences, enable/disable
158
+ * fallbacks, and require specific provider parameters.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * const model = openrouter('openai/gpt-4', {
163
+ * provider: {
164
+ * order: ['Azure', 'OpenAI'],
165
+ * allowFallbacks: true,
166
+ * },
167
+ * });
168
+ * ```
169
+ */
170
+ interface OpenRouterProviderRoutingConfig {
247
171
  /**
248
- * A unique identifier representing your end-user, which can help OpenRouter to
249
- * monitor and detect abuse.
172
+ * Provider order preference.
250
173
  */
251
- user?: string;
174
+ order?: string[];
252
175
  /**
253
- * Provider routing preferences to control request routing behavior
176
+ * Allow fallbacks to other providers.
254
177
  */
255
- provider?: {
256
- /**
257
- * List of provider slugs to try in order (e.g. ["openai", "voyageai"])
258
- */
259
- order?: string[];
260
- /**
261
- * Whether to allow backup providers when primary is unavailable (default: true)
262
- */
263
- allow_fallbacks?: boolean;
264
- /**
265
- * Only use providers that support all parameters in your request (default: false)
266
- */
267
- require_parameters?: boolean;
268
- /**
269
- * Control whether to use providers that may store data
270
- */
271
- data_collection?: 'allow' | 'deny';
272
- /**
273
- * List of provider slugs to allow for this request
274
- */
275
- only?: string[];
276
- /**
277
- * List of provider slugs to skip for this request
278
- */
279
- ignore?: string[];
280
- /**
281
- * Sort providers by price, throughput, or latency
282
- */
283
- sort?: 'price' | 'throughput' | 'latency';
178
+ allowFallbacks?: boolean;
179
+ /**
180
+ * Required provider parameters.
181
+ */
182
+ requireParameters?: boolean;
183
+ }
184
+ /**
185
+ * Model-specific options for OpenRouter requests.
186
+ *
187
+ * @description
188
+ * Options that can be passed when creating a model to customize its behavior.
189
+ * These include OpenRouter-specific features like plugins, transforms, model
190
+ * fallbacks, and routing configuration. Additional properties are passed through
191
+ * to the underlying API.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * const model = openrouter('anthropic/claude-3.5-sonnet', {
196
+ * usage: { include: true },
197
+ * transforms: ['middle-out'],
198
+ * models: ['anthropic/claude-3-opus', 'openai/gpt-4'], // fallbacks
199
+ * provider: {
200
+ * order: ['Anthropic'],
201
+ * allowFallbacks: false,
202
+ * },
203
+ * });
204
+ * ```
205
+ */
206
+ interface OpenRouterModelOptions {
207
+ /**
208
+ * Usage accounting configuration.
209
+ */
210
+ usage?: {
284
211
  /**
285
- * Maximum pricing you want to pay for this request
212
+ * Whether to include usage information in the response.
286
213
  */
287
- max_price?: {
288
- prompt?: number | string;
289
- completion?: number | string;
290
- image?: number | string;
291
- audio?: number | string;
292
- request?: number | string;
293
- };
214
+ include?: boolean;
294
215
  };
295
- } & OpenRouterSharedSettings;
296
-
297
- type OpenRouterProviderOptions = {
216
+ /**
217
+ * OpenRouter plugins to enable.
218
+ */
219
+ plugins?: OpenRouterPluginConfig[];
220
+ /**
221
+ * Message transforms to apply.
222
+ */
223
+ transforms?: string[];
224
+ /**
225
+ * Fallback model IDs.
226
+ */
298
227
  models?: string[];
299
228
  /**
300
- * https://openrouter.ai/docs/use-cases/reasoning-tokens
301
- * One of `max_tokens` or `effort` is required.
302
- * If `exclude` is true, reasoning will be removed from the response. Default is false.
229
+ * Routing strategy.
303
230
  */
304
- reasoning?: {
305
- enabled?: boolean;
306
- exclude?: boolean;
307
- } & ({
308
- max_tokens: number;
309
- } | {
310
- effort: 'high' | 'medium' | 'low';
311
- });
231
+ route?: string;
312
232
  /**
313
- * A unique identifier representing your end-user, which can
314
- * help OpenRouter to monitor and detect abuse.
233
+ * Provider routing configuration.
315
234
  */
316
- user?: string;
317
- };
318
- type OpenRouterSharedSettings = OpenRouterProviderOptions & {
235
+ provider?: OpenRouterProviderRoutingConfig;
319
236
  /**
320
- * @deprecated use `reasoning` instead
237
+ * How to handle system messages for reasoning models.
238
+ * - 'system': Standard system message (default)
239
+ * - 'developer': Convert system to developer role for reasoning models
240
+ * - 'remove': Strip system messages entirely
321
241
  */
322
- includeReasoning?: boolean;
323
- extraBody?: Record<string, unknown>;
242
+ systemMessageMode?: 'system' | 'developer' | 'remove';
324
243
  /**
325
- * Enable usage accounting to get detailed token usage information.
326
- * https://openrouter.ai/docs/use-cases/usage-accounting
244
+ * Allow any additional model-specific options.
245
+ * These are passed through to the API.
327
246
  */
328
- usage?: {
329
- /**
330
- * When true, includes token usage information in the response.
331
- */
332
- include: boolean;
333
- };
334
- };
247
+ [key: string]: unknown;
248
+ }
249
+
335
250
  /**
336
- * Usage accounting response
337
- * @see https://openrouter.ai/docs/use-cases/usage-accounting
251
+ * Result of parsing provider options, including any warnings.
338
252
  */
339
- type OpenRouterUsageAccounting = {
340
- promptTokens: number;
341
- promptTokensDetails?: {
342
- cachedTokens: number;
343
- };
344
- completionTokens: number;
345
- completionTokensDetails?: {
346
- reasoningTokens: number;
347
- };
348
- totalTokens: number;
349
- cost?: number;
350
- costDetails?: {
351
- upstreamInferenceCost: number;
352
- };
353
- };
354
-
355
- type OpenRouterChatConfig = {
356
- provider: string;
357
- compatibility: 'strict' | 'compatible';
358
- headers: () => Record<string, string | undefined>;
359
- url: (options: {
360
- modelId: string;
361
- path: string;
362
- }) => string;
363
- fetch?: typeof fetch;
364
- extraBody?: Record<string, unknown>;
365
- };
366
- declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
367
- readonly specificationVersion: "v2";
368
- readonly provider = "openrouter";
369
- readonly defaultObjectGenerationMode: "tool";
370
- readonly modelId: OpenRouterChatModelId;
371
- readonly supportsImageUrls = true;
372
- readonly supportedUrls: Record<string, RegExp[]>;
373
- readonly settings: OpenRouterChatSettings;
374
- private readonly config;
375
- constructor(modelId: OpenRouterChatModelId, settings: OpenRouterChatSettings, config: OpenRouterChatConfig);
376
- private getArgs;
377
- doGenerate(options: LanguageModelV2CallOptions): Promise<{
378
- content: Array<LanguageModelV2Content>;
379
- finishReason: LanguageModelV2FinishReason;
380
- usage: LanguageModelV2Usage;
381
- warnings: Array<LanguageModelV2CallWarning>;
382
- providerMetadata?: {
383
- openrouter: {
384
- provider: string;
385
- reasoning_details?: ReasoningDetailUnion[];
386
- usage: OpenRouterUsageAccounting;
387
- };
388
- };
389
- request?: {
390
- body?: unknown;
391
- };
392
- response?: LanguageModelV2ResponseMetadata & {
393
- headers?: SharedV2Headers;
394
- body?: unknown;
395
- };
396
- }>;
397
- doStream(options: LanguageModelV2CallOptions): Promise<{
398
- stream: ReadableStream<LanguageModelV2StreamPart>;
399
- warnings: Array<LanguageModelV2CallWarning>;
400
- request?: {
401
- body?: unknown;
402
- };
403
- response?: LanguageModelV2ResponseMetadata & {
404
- headers?: SharedV2Headers;
405
- body?: unknown;
406
- };
253
+ interface ParsedProviderOptions {
254
+ /**
255
+ * The merged options.
256
+ */
257
+ options: OpenRouterModelOptions;
258
+ /**
259
+ * Warnings generated during parsing (e.g., unknown keys).
260
+ */
261
+ warnings: Array<{
262
+ type: 'unsupported';
263
+ feature: string;
264
+ details?: string;
407
265
  }>;
408
266
  }
267
+ /**
268
+ * Parses and merges provider options from model-level and call-time sources.
269
+ *
270
+ * Call-time options override model-level options for the same keys.
271
+ * Unknown keys pass through (per design spec - they are passed to the API).
272
+ *
273
+ * @param modelOptions - Options set at model creation time.
274
+ * @param callOptions - Options set at call time via providerOptions.openrouter.
275
+ * @returns The merged options and any warnings.
276
+ */
277
+ declare function parseOpenRouterOptions(modelOptions: OpenRouterModelOptions | undefined, callOptions: Record<string, unknown> | undefined): ParsedProviderOptions;
278
+
279
+ /**
280
+ * Maps OpenRouter finish reasons to the AI SDK V3 unified format.
281
+ *
282
+ * Mapping table:
283
+ * - 'end_turn', 'stop', 'stop_sequence' -> 'stop'
284
+ * - 'max_tokens', 'length' -> 'length'
285
+ * - 'tool_use', 'tool_calls' -> 'tool-calls'
286
+ * - 'content_filter' -> 'content-filter'
287
+ * - 'error' -> 'error'
288
+ * - null/undefined/unknown -> 'other'
289
+ *
290
+ * @param finishReason - The finish reason from OpenRouter API response
291
+ * @returns Object containing the unified finish reason and raw original value
292
+ */
293
+ declare function mapOpenRouterFinishReason(finishReason: string | null | undefined): LanguageModelV3FinishReason;
294
+
295
+ /**
296
+ * OpenRouter Responses API input item types.
297
+ * These match the OpenResponsesEasyInputMessage format used by the Responses API.
298
+ */
299
+ type OpenRouterInputItem = OpenRouterEasyInputMessage | OpenRouterFunctionCall | OpenRouterFunctionCallOutput;
300
+ /**
301
+ * Reasoning object for assistant messages.
302
+ * Contains the reasoning details to send back to the API.
303
+ */
304
+ interface OpenRouterReasoning {
305
+ text?: string;
306
+ summary?: string;
307
+ encrypted?: string;
308
+ }
309
+ /**
310
+ * Easy input message format for Responses API.
311
+ * Supports user, system, assistant, and developer roles.
312
+ */
313
+ interface OpenRouterEasyInputMessage {
314
+ type?: 'message';
315
+ role: 'user' | 'system' | 'assistant' | 'developer';
316
+ content: string | OpenRouterInputContent[];
317
+ reasoning?: OpenRouterReasoning;
318
+ }
319
+ interface OpenRouterFunctionCall {
320
+ type: 'function_call';
321
+ callId: string;
322
+ name: string;
323
+ arguments: string;
324
+ }
325
+ interface OpenRouterFunctionCallOutput {
326
+ type: 'function_call_output';
327
+ callId: string;
328
+ output: string;
329
+ status: 'completed' | 'incomplete';
330
+ }
331
+ /**
332
+ * Input content types for Responses API.
333
+ * Uses 'input_text', 'input_image', 'input_file' type prefixes.
334
+ */
335
+ type OpenRouterInputContent = {
336
+ type: 'input_text';
337
+ text: string;
338
+ } | {
339
+ type: 'input_image';
340
+ imageUrl: string;
341
+ detail?: 'auto' | 'low' | 'high';
342
+ } | {
343
+ type: 'input_file';
344
+ fileUrl: string;
345
+ filename?: string;
346
+ };
347
+ /**
348
+ * Converts AI SDK V3 prompt format to OpenRouter Responses API input format.
349
+ *
350
+ * Mapping table:
351
+ * - system { content } -> { role: 'system', content: string }
352
+ * - user text -> { role: 'user', content: [{ type: 'input_text', text }] }
353
+ * - user image -> { role: 'user', content: [{ type: 'input_image', imageUrl }] }
354
+ * - user file -> { role: 'user', content: [{ type: 'input_file', fileUrl }] }
355
+ * - assistant text -> { role: 'assistant', content: string }
356
+ * - assistant tool-call -> { type: 'function_call', ... }
357
+ * - tool result -> { type: 'function_call_output', ... }
358
+ *
359
+ * @param prompt - The AI SDK V3 prompt
360
+ * @returns Array of input items in OpenRouter Responses API format
361
+ */
362
+ declare function convertToOpenRouterMessages(prompt: LanguageModelV3Prompt): OpenRouterInputItem[];
409
363
 
410
- export { OpenRouterChatLanguageModel, type OpenRouterChatModelId, type OpenRouterChatSettings, OpenRouterCompletionLanguageModel, type OpenRouterCompletionModelId, type OpenRouterCompletionSettings, type OpenRouterEmbeddingModelId, type OpenRouterEmbeddingSettings, type OpenRouterProviderOptions, type OpenRouterSharedSettings, type OpenRouterUsageAccounting };
364
+ export { type OpenRouterProviderMetadata, type OpenRouterRawUsage, type OpenRouterResponseData, type ParsedProviderOptions, buildProviderMetadata, buildUsage, convertToOpenRouterMessages, mapOpenRouterFinishReason, parseOpenRouterOptions };