@effect/ai-openrouter 4.0.0-beta.65 → 4.0.0-beta.67

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.
@@ -4,14 +4,14 @@
4
4
  * Provides OpenRouter-specific metadata fields for AI error types through
5
5
  * module augmentation, enabling typed access to OpenRouter error details.
6
6
  *
7
- * @since 1.0.0
7
+ * @since 4.0.0
8
8
  */
9
9
 
10
10
  /**
11
11
  * OpenRouter-specific error metadata fields.
12
12
  *
13
- * @since 1.0.0
14
13
  * @category models
14
+ * @since 4.0.0
15
15
  */
16
16
  export type OpenRouterErrorMetadata = {
17
17
  /**
@@ -31,8 +31,8 @@ export type OpenRouterErrorMetadata = {
31
31
  /**
32
32
  * OpenRouter-specific rate limit metadata fields.
33
33
  *
34
- * @since 1.0.0
35
34
  * @category models
35
+ * @since 4.0.0
36
36
  */
37
37
  export type OpenRouterRateLimitMetadata = OpenRouterErrorMetadata & {
38
38
  readonly limit: string | null
@@ -42,43 +42,164 @@ export type OpenRouterRateLimitMetadata = OpenRouterErrorMetadata & {
42
42
  }
43
43
 
44
44
  declare module "effect/unstable/ai/AiError" {
45
+ /**
46
+ * OpenRouter metadata attached to `RateLimitError` values.
47
+ *
48
+ * Captures OpenRouter error details together with rate limit header
49
+ * information from responses where the provider rejected the request because
50
+ * a limit was reached.
51
+ *
52
+ * @category provider options
53
+ * @since 4.0.0
54
+ */
45
55
  export interface RateLimitErrorMetadata {
56
+ /**
57
+ * OpenRouter-specific details for the rate limit response.
58
+ */
46
59
  readonly openrouter?: OpenRouterRateLimitMetadata | null
47
60
  }
48
61
 
62
+ /**
63
+ * OpenRouter metadata attached to `QuotaExhaustedError` values.
64
+ *
65
+ * Preserves provider error details for failures caused by exhausted account,
66
+ * billing, or usage quota.
67
+ *
68
+ * @category provider options
69
+ * @since 4.0.0
70
+ */
49
71
  export interface QuotaExhaustedErrorMetadata {
72
+ /**
73
+ * OpenRouter-specific details for the quota exhaustion response.
74
+ */
50
75
  readonly openrouter?: OpenRouterErrorMetadata | null
51
76
  }
52
77
 
78
+ /**
79
+ * OpenRouter metadata attached to `AuthenticationError` values.
80
+ *
81
+ * Preserves provider error details for failed API key, authorization, or
82
+ * permission checks.
83
+ *
84
+ * @category provider options
85
+ * @since 4.0.0
86
+ */
53
87
  export interface AuthenticationErrorMetadata {
88
+ /**
89
+ * OpenRouter-specific details for the authentication failure.
90
+ */
54
91
  readonly openrouter?: OpenRouterErrorMetadata | null
55
92
  }
56
93
 
94
+ /**
95
+ * OpenRouter metadata attached to `ContentPolicyError` values.
96
+ *
97
+ * Preserves provider error details when OpenRouter rejects input or output
98
+ * because it violates a content policy.
99
+ *
100
+ * @category provider options
101
+ * @since 4.0.0
102
+ */
57
103
  export interface ContentPolicyErrorMetadata {
104
+ /**
105
+ * OpenRouter-specific details for the content policy response.
106
+ */
58
107
  readonly openrouter?: OpenRouterErrorMetadata | null
59
108
  }
60
109
 
110
+ /**
111
+ * OpenRouter metadata attached to `InvalidRequestError` values.
112
+ *
113
+ * Preserves provider error details for malformed requests, unsupported
114
+ * parameters, or other request validation failures reported by OpenRouter.
115
+ *
116
+ * @category provider options
117
+ * @since 4.0.0
118
+ */
61
119
  export interface InvalidRequestErrorMetadata {
120
+ /**
121
+ * OpenRouter-specific details for the invalid request response.
122
+ */
62
123
  readonly openrouter?: OpenRouterErrorMetadata | null
63
124
  }
64
125
 
126
+ /**
127
+ * OpenRouter metadata attached to `InternalProviderError` values.
128
+ *
129
+ * Preserves provider error details for OpenRouter-side failures such as
130
+ * transient server errors or overload responses.
131
+ *
132
+ * @category provider options
133
+ * @since 4.0.0
134
+ */
65
135
  export interface InternalProviderErrorMetadata {
136
+ /**
137
+ * OpenRouter-specific details for the internal provider response.
138
+ */
66
139
  readonly openrouter?: OpenRouterErrorMetadata | null
67
140
  }
68
141
 
142
+ /**
143
+ * OpenRouter metadata attached to `InvalidOutputError` values.
144
+ *
145
+ * Preserves provider error details when an OpenRouter response cannot be
146
+ * parsed or validated as the expected output.
147
+ *
148
+ * @category provider options
149
+ * @since 4.0.0
150
+ */
69
151
  export interface InvalidOutputErrorMetadata {
152
+ /**
153
+ * OpenRouter-specific details for the invalid output response.
154
+ */
70
155
  readonly openrouter?: OpenRouterErrorMetadata | null
71
156
  }
72
157
 
158
+ /**
159
+ * OpenRouter metadata attached to `StructuredOutputError` values.
160
+ *
161
+ * Preserves provider error details when OpenRouter returns content that does
162
+ * not satisfy the requested structured output schema.
163
+ *
164
+ * @category provider options
165
+ * @since 4.0.0
166
+ */
73
167
  export interface StructuredOutputErrorMetadata {
168
+ /**
169
+ * OpenRouter-specific details for the structured output failure.
170
+ */
74
171
  readonly openrouter?: OpenRouterErrorMetadata | null
75
172
  }
76
173
 
174
+ /**
175
+ * OpenRouter metadata attached to `UnsupportedSchemaError` values.
176
+ *
177
+ * Preserves provider error details when an unsupported schema failure is
178
+ * associated with an OpenRouter response.
179
+ *
180
+ * @category provider options
181
+ * @since 4.0.0
182
+ */
77
183
  export interface UnsupportedSchemaErrorMetadata {
184
+ /**
185
+ * OpenRouter-specific details for the unsupported schema failure.
186
+ */
78
187
  readonly openrouter?: OpenRouterErrorMetadata | null
79
188
  }
80
189
 
190
+ /**
191
+ * OpenRouter metadata attached to `UnknownError` values.
192
+ *
193
+ * Preserves provider error details for OpenRouter failures that do not map
194
+ * cleanly to a more specific AI error category.
195
+ *
196
+ * @category provider options
197
+ * @since 4.0.0
198
+ */
81
199
  export interface UnknownErrorMetadata {
200
+ /**
201
+ * OpenRouter-specific details for the unclassified provider failure.
202
+ */
82
203
  readonly openrouter?: OpenRouterErrorMetadata | null
83
204
  }
84
205
  }
@@ -1,5 +1,25 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `OpenRouterLanguageModel` module provides constructors for using
3
+ * OpenRouter chat completion models through the Effect AI `LanguageModel`
4
+ * interface. It adapts Effect prompts, tools, structured output schemas, file
5
+ * parts, reasoning details, cache-control hints, and telemetry annotations into
6
+ * the OpenRouter request and response formats.
7
+ *
8
+ * Use this module when an application wants to select an OpenRouter model by
9
+ * name while keeping the rest of its AI workflow provider-agnostic. The
10
+ * exported layer and model constructors install a `LanguageModel` service backed
11
+ * by `OpenRouterClient`, and `withConfigOverride` can scope per-request
12
+ * OpenRouter options such as sampling, routing, tool use, or JSON schema
13
+ * behavior.
14
+ *
15
+ * OpenRouter routes requests to many underlying providers, so model support for
16
+ * images, files, tools, structured outputs, caching, and reasoning metadata can
17
+ * vary. Provider-specific prompt and response metadata is preserved under the
18
+ * `openrouter` option namespace so multi-turn conversations can round-trip
19
+ * details such as reasoning blocks and file annotations when the selected model
20
+ * supports them.
21
+ *
22
+ * @since 4.0.0
3
23
  */
4
24
  /** @effect-diagnostics preferSchemaOverJson:skip-file */
5
25
  import * as Arr from "effect/Array"
@@ -40,8 +60,8 @@ import { type ChatStreamingResponseChunkData, OpenRouterClient } from "./OpenRou
40
60
  /**
41
61
  * Service definition for OpenRouter language model configuration.
42
62
  *
43
- * @since 1.0.0
44
63
  * @category services
64
+ * @since 4.0.0
45
65
  */
46
66
  export class Config extends Context.Service<
47
67
  Config,
@@ -69,14 +89,20 @@ export class Config extends Context.Service<
69
89
  // =============================================================================
70
90
 
71
91
  /**
72
- * @since 1.0.0
92
+ * OpenRouter assistant reasoning detail blocks preserved for multi-turn
93
+ * conversations.
94
+ *
73
95
  * @category models
96
+ * @since 4.0.0
74
97
  */
75
98
  export type ReasoningDetails = Exclude<typeof Generated.AssistantMessage.Encoded["reasoning_details"], undefined>
76
99
 
77
100
  /**
78
- * @since 1.0.0
101
+ * File annotations emitted on OpenRouter assistant messages and exposed in
102
+ * finish metadata.
103
+ *
79
104
  * @category models
105
+ * @since 4.0.0
80
106
  */
81
107
  export type FileAnnotation = Extract<
82
108
  NonNullable<typeof Generated.AssistantMessage.fields.annotations.Type>[number],
@@ -84,7 +110,16 @@ export type FileAnnotation = Extract<
84
110
  >
85
111
 
86
112
  declare module "effect/unstable/ai/Prompt" {
113
+ /**
114
+ * OpenRouter-specific options for system messages.
115
+ *
116
+ * These options are used when translating system instructions into
117
+ * OpenRouter chat messages.
118
+ */
87
119
  export interface SystemMessageOptions extends ProviderOptions {
120
+ /**
121
+ * Provider-specific options sent to OpenRouter for the system message.
122
+ */
88
123
  readonly openrouter?: {
89
124
  /**
90
125
  * A breakpoint which marks the end of reusable content eligible for caching.
@@ -93,7 +128,16 @@ declare module "effect/unstable/ai/Prompt" {
93
128
  } | null
94
129
  }
95
130
 
131
+ /**
132
+ * OpenRouter-specific options for user messages.
133
+ *
134
+ * These options are used when translating user content into OpenRouter chat
135
+ * messages.
136
+ */
96
137
  export interface UserMessageOptions extends ProviderOptions {
138
+ /**
139
+ * Provider-specific options sent to OpenRouter for the user message.
140
+ */
97
141
  readonly openrouter?: {
98
142
  /**
99
143
  * A breakpoint which marks the end of reusable content eligible for caching.
@@ -102,7 +146,16 @@ declare module "effect/unstable/ai/Prompt" {
102
146
  } | null
103
147
  }
104
148
 
149
+ /**
150
+ * OpenRouter-specific options for assistant messages.
151
+ *
152
+ * Preserves reasoning metadata when assistant messages are replayed in later
153
+ * OpenRouter requests.
154
+ */
105
155
  export interface AssistantMessageOptions extends ProviderOptions {
156
+ /**
157
+ * Provider-specific options sent to OpenRouter for the assistant message.
158
+ */
106
159
  readonly openrouter?: {
107
160
  /**
108
161
  * A breakpoint which marks the end of reusable content eligible for caching.
@@ -115,7 +168,16 @@ declare module "effect/unstable/ai/Prompt" {
115
168
  } | null
116
169
  }
117
170
 
171
+ /**
172
+ * OpenRouter-specific options for tool messages.
173
+ *
174
+ * These options are used when converting tool results into OpenRouter chat
175
+ * messages.
176
+ */
118
177
  export interface ToolMessageOptions extends ProviderOptions {
178
+ /**
179
+ * Provider-specific options sent to OpenRouter for the tool message.
180
+ */
119
181
  readonly openrouter?: {
120
182
  /**
121
183
  * A breakpoint which marks the end of reusable content eligible for caching.
@@ -124,7 +186,15 @@ declare module "effect/unstable/ai/Prompt" {
124
186
  } | null
125
187
  }
126
188
 
189
+ /**
190
+ * OpenRouter-specific options for text prompt parts.
191
+ *
192
+ * Use these options to control how text content is sent to OpenRouter.
193
+ */
127
194
  export interface TextPartOptions extends ProviderOptions {
195
+ /**
196
+ * Provider-specific options sent to OpenRouter for the text part.
197
+ */
128
198
  readonly openrouter?: {
129
199
  /**
130
200
  * A breakpoint which marks the end of reusable content eligible for caching.
@@ -133,7 +203,16 @@ declare module "effect/unstable/ai/Prompt" {
133
203
  } | null
134
204
  }
135
205
 
206
+ /**
207
+ * OpenRouter-specific options for reasoning prompt parts.
208
+ *
209
+ * Preserves provider reasoning blocks so reasoning-aware conversations can
210
+ * continue across OpenRouter requests.
211
+ */
136
212
  export interface ReasoningPartOptions extends ProviderOptions {
213
+ /**
214
+ * Provider-specific options sent to OpenRouter for the reasoning part.
215
+ */
137
216
  readonly openrouter?: {
138
217
  /**
139
218
  * A breakpoint which marks the end of reusable content eligible for caching.
@@ -146,7 +225,15 @@ declare module "effect/unstable/ai/Prompt" {
146
225
  } | null
147
226
  }
148
227
 
228
+ /**
229
+ * OpenRouter-specific options for file prompt parts.
230
+ *
231
+ * Controls file naming and prompt caching for files sent to OpenRouter.
232
+ */
149
233
  export interface FilePartOptions extends ProviderOptions {
234
+ /**
235
+ * Provider-specific options sent to OpenRouter for the file part.
236
+ */
150
237
  readonly openrouter?: {
151
238
  /**
152
239
  * The name to give to the file. Will be prioritized over the file name
@@ -160,7 +247,16 @@ declare module "effect/unstable/ai/Prompt" {
160
247
  } | null
161
248
  }
162
249
 
250
+ /**
251
+ * OpenRouter-specific options for tool call prompt parts.
252
+ *
253
+ * Preserves reasoning details associated with tool calls when a conversation
254
+ * is sent back to OpenRouter.
255
+ */
163
256
  export interface ToolCallPartOptions extends ProviderOptions {
257
+ /**
258
+ * Provider-specific options sent to OpenRouter for the tool call part.
259
+ */
164
260
  readonly openrouter?: {
165
261
  /**
166
262
  * Reasoning details associated with the tool call part.
@@ -169,7 +265,15 @@ declare module "effect/unstable/ai/Prompt" {
169
265
  } | null
170
266
  }
171
267
 
268
+ /**
269
+ * OpenRouter-specific options for tool result prompt parts.
270
+ *
271
+ * Controls prompt caching for tool results sent to OpenRouter.
272
+ */
172
273
  export interface ToolResultPartOptions extends ProviderOptions {
274
+ /**
275
+ * Provider-specific options sent to OpenRouter for the tool result part.
276
+ */
173
277
  readonly openrouter?: {
174
278
  /**
175
279
  * A breakpoint which marks the end of reusable content eligible for caching.
@@ -180,43 +284,127 @@ declare module "effect/unstable/ai/Prompt" {
180
284
  }
181
285
 
182
286
  declare module "effect/unstable/ai/Response" {
287
+ /**
288
+ * OpenRouter metadata attached to completed reasoning response parts.
289
+ *
290
+ * Preserves provider reasoning details that can be sent back in later turns.
291
+ */
183
292
  export interface ReasoningPartMetadata extends ProviderMetadata {
293
+ /**
294
+ * Provider-specific metadata returned for the reasoning part.
295
+ */
184
296
  readonly openrouter?: {
297
+ /**
298
+ * Reasoning details emitted by the underlying provider for this part.
299
+ */
185
300
  readonly reasoningDetails?: ReasoningDetails | null
186
301
  } | null
187
302
  }
188
303
 
304
+ /**
305
+ * OpenRouter metadata emitted when a streamed reasoning part starts.
306
+ *
307
+ * Carries the first reasoning detail chunk when OpenRouter exposes one.
308
+ */
189
309
  export interface ReasoningStartPartMetadata extends ProviderMetadata {
310
+ /**
311
+ * Provider-specific metadata returned for the streamed reasoning start.
312
+ */
190
313
  readonly openrouter?: {
314
+ /**
315
+ * Reasoning details emitted by the underlying provider for this part.
316
+ */
191
317
  readonly reasoningDetails?: ReasoningDetails | null
192
318
  } | null
193
319
  }
194
320
 
321
+ /**
322
+ * OpenRouter metadata emitted for streamed reasoning deltas.
323
+ *
324
+ * Carries provider reasoning detail chunks as they arrive from OpenRouter.
325
+ */
195
326
  export interface ReasoningDeltaPartMetadata extends ProviderMetadata {
327
+ /**
328
+ * Provider-specific metadata returned for the streamed reasoning delta.
329
+ */
196
330
  readonly openrouter?: {
331
+ /**
332
+ * Reasoning details emitted by the underlying provider for this delta.
333
+ */
197
334
  readonly reasoningDetails?: ReasoningDetails | null
198
335
  } | null
199
336
  }
200
337
 
338
+ /**
339
+ * OpenRouter metadata attached to tool-call response parts.
340
+ *
341
+ * Associates tool calls with provider reasoning details when the model emits
342
+ * reasoning and tool calls together.
343
+ */
201
344
  export interface ToolCallPartMetadata extends ProviderMetadata {
345
+ /**
346
+ * Provider-specific metadata returned for the tool call.
347
+ */
202
348
  readonly openrouter?: {
349
+ /**
350
+ * Reasoning details associated with this tool call.
351
+ */
203
352
  readonly reasoningDetails?: ReasoningDetails | null
204
353
  } | null
205
354
  }
206
355
 
356
+ /**
357
+ * OpenRouter metadata attached to URL source citations.
358
+ *
359
+ * Includes citation text and offsets returned by providers that support URL
360
+ * annotations.
361
+ */
207
362
  export interface UrlSourcePartMetadata extends ProviderMetadata {
363
+ /**
364
+ * Provider-specific citation metadata returned for the URL source.
365
+ */
208
366
  readonly openrouter?: {
367
+ /**
368
+ * The cited source content returned by the provider.
369
+ */
209
370
  readonly content?: string | null
371
+ /**
372
+ * The zero-based start index of the citation in the generated text.
373
+ */
210
374
  readonly startIndex?: number | null
375
+ /**
376
+ * The zero-based end index of the citation in the generated text.
377
+ */
211
378
  readonly endIndex?: number | null
212
379
  } | null
213
380
  }
214
381
 
382
+ /**
383
+ * OpenRouter metadata attached to finish response parts.
384
+ *
385
+ * Exposes provider response details that are not represented by the common
386
+ * Effect AI finish part fields.
387
+ */
215
388
  export interface FinishPartMetadata extends ProviderMetadata {
389
+ /**
390
+ * Provider-specific metadata returned when the OpenRouter response finishes.
391
+ */
216
392
  readonly openrouter?: {
393
+ /**
394
+ * Provider fingerprint for the backend configuration that served the request.
395
+ */
217
396
  readonly systemFingerprint?: string | null
397
+ /**
398
+ * Raw token usage reported by OpenRouter.
399
+ */
218
400
  readonly usage?: typeof Generated.ChatGenerationTokenUsage.Encoded | null
401
+ /**
402
+ * File annotations returned by the provider.
403
+ */
219
404
  readonly annotations?: ReadonlyArray<FileAnnotation> | null
405
+ /**
406
+ * The OpenRouter provider that served the request, when reported.
407
+ */
220
408
  readonly provider?: string | null
221
409
  } | null
222
410
  }
@@ -227,8 +415,10 @@ declare module "effect/unstable/ai/Response" {
227
415
  // =============================================================================
228
416
 
229
417
  /**
230
- * @since 1.0.0
418
+ * Creates an AI model descriptor for an OpenRouter language model.
419
+ *
231
420
  * @category constructors
421
+ * @since 4.0.0
232
422
  */
233
423
  export const model = (
234
424
  model: string,
@@ -239,8 +429,8 @@ export const model = (
239
429
  /**
240
430
  * Creates an OpenRouter language model service.
241
431
  *
242
- * @since 1.0.0
243
432
  * @category constructors
433
+ * @since 4.0.0
244
434
  */
245
435
  export const make = Effect.fnUntraced(function*({ model, config: providerConfig }: {
246
436
  readonly model: string
@@ -308,8 +498,8 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
308
498
  /**
309
499
  * Creates a layer for the OpenRouter language model.
310
500
  *
311
- * @since 1.0.0
312
501
  * @category layers
502
+ * @since 4.0.0
313
503
  */
314
504
  export const layer = (options: {
315
505
  readonly model: string
@@ -320,37 +510,37 @@ export const layer = (options: {
320
510
  /**
321
511
  * Provides config overrides for OpenRouter language model operations.
322
512
  *
323
- * @since 1.0.0
324
513
  * @category configuration
514
+ * @since 4.0.0
325
515
  */
326
516
  export const withConfigOverride: {
327
517
  /**
328
518
  * Provides config overrides for OpenRouter language model operations.
329
519
  *
330
- * @since 1.0.0
331
520
  * @category configuration
521
+ * @since 4.0.0
332
522
  */
333
523
  (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>
334
524
  /**
335
525
  * Provides config overrides for OpenRouter language model operations.
336
526
  *
337
- * @since 1.0.0
338
527
  * @category configuration
528
+ * @since 4.0.0
339
529
  */
340
530
  <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>
341
531
  } = dual<
342
532
  /**
343
533
  * Provides config overrides for OpenRouter language model operations.
344
534
  *
345
- * @since 1.0.0
346
535
  * @category configuration
536
+ * @since 4.0.0
347
537
  */
348
538
  (overrides: typeof Config.Service) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>,
349
539
  /**
350
540
  * Provides config overrides for OpenRouter language model operations.
351
541
  *
352
- * @since 1.0.0
353
542
  * @category configuration
543
+ * @since 4.0.0
354
544
  */
355
545
  <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service) => Effect.Effect<A, E, Exclude<R, Config>>
356
546
  >(2, (self, overrides) =>
package/src/index.ts CHANGED
@@ -1,21 +1,21 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  // @barrel: Auto-generated exports. Do not edit manually.
6
6
 
7
7
  /**
8
- * @since 1.0.0
8
+ * @since 4.0.0
9
9
  */
10
10
  export * as Generated from "./Generated.ts"
11
11
 
12
12
  /**
13
- * @since 1.0.0
13
+ * @since 4.0.0
14
14
  */
15
15
  export * as OpenRouterClient from "./OpenRouterClient.ts"
16
16
 
17
17
  /**
18
- * @since 1.0.0
18
+ * @since 4.0.0
19
19
  */
20
20
  export * as OpenRouterConfig from "./OpenRouterConfig.ts"
21
21
 
@@ -25,11 +25,11 @@ export * as OpenRouterConfig from "./OpenRouterConfig.ts"
25
25
  * Provides OpenRouter-specific metadata fields for AI error types through
26
26
  * module augmentation, enabling typed access to OpenRouter error details.
27
27
  *
28
- * @since 1.0.0
28
+ * @since 4.0.0
29
29
  */
30
30
  export * as OpenRouterError from "./OpenRouterError.ts"
31
31
 
32
32
  /**
33
- * @since 1.0.0
33
+ * @since 4.0.0
34
34
  */
35
35
  export * as OpenRouterLanguageModel from "./OpenRouterLanguageModel.ts"