@effect/ai-openai-compat 4.0.0-beta.70 → 4.0.0-beta.71

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.
@@ -77,8 +77,22 @@ export interface Service {
77
77
  }
78
78
 
79
79
  /**
80
- * Context service tag for accessing an OpenAI-compatible client from the
81
- * Effect context.
80
+ * Context service tag for the OpenAI-compatible chat completions and embeddings client.
81
+ *
82
+ * **When to use**
83
+ *
84
+ * Use when building effects that depend on the low-level OpenAI-compatible
85
+ * client through context rather than receiving the client as a value.
86
+ *
87
+ * **Details**
88
+ *
89
+ * The tagged service is the `Service` interface produced by `make` and provided
90
+ * by `layer` or `layerConfig`.
91
+ *
92
+ * @see {@link Service} for the operations provided by the service
93
+ * @see {@link make} for constructing the service from explicit options
94
+ * @see {@link layer} for providing the service from explicit options
95
+ * @see {@link layerConfig} for loading client settings from `Config`
82
96
  *
83
97
  * @category services
84
98
  * @since 4.0.0
@@ -109,10 +123,25 @@ const RedactedOpenAiHeaders = {
109
123
  /**
110
124
  * Constructs an OpenAI-compatible client service from explicit options.
111
125
  *
126
+ * **When to use**
127
+ *
128
+ * Use to construct the OpenAI-compatible client service inside an effect when
129
+ * you need the service value directly.
130
+ *
112
131
  * **Details**
113
132
  *
114
- * The returned service applies the configured base URL, authentication, and
115
- * OpenAI organization/project headers to the underlying HTTP client.
133
+ * The returned service uses the current `HttpClient`, prepends `apiUrl` or
134
+ * `https://api.openai.com/v1`, adds authentication and OpenAI
135
+ * organization/project headers, accepts JSON responses, and applies
136
+ * `transformClient` when provided.
137
+ *
138
+ * **Gotchas**
139
+ *
140
+ * A scoped `OpenAiConfig.withClientTransform` is applied when request helpers
141
+ * run, after the `transformClient` option supplied to `make`.
142
+ *
143
+ * @see {@link layer} for providing this client from explicit options
144
+ * @see {@link layerConfig} for loading client settings from `Config`
116
145
  *
117
146
  * @category constructors
118
147
  * @since 4.0.0
@@ -257,6 +286,14 @@ export const make = Effect.fnUntraced(
257
286
  /**
258
287
  * Creates a layer that provides an OpenAI-compatible client from explicit options.
259
288
  *
289
+ * **When to use**
290
+ *
291
+ * Use to install `OpenAiClient` in an application layer when the client options
292
+ * are already available as values rather than loaded from `Config`.
293
+ *
294
+ * @see {@link make} for constructing the client service effectfully
295
+ * @see {@link layerConfig} for loading client settings from `Config`
296
+ *
260
297
  * @category layers
261
298
  * @since 4.0.0
262
299
  */
@@ -267,6 +304,20 @@ export const layer = (options: Options): Layer.Layer<OpenAiClient, never, HttpCl
267
304
  * Creates a layer that loads OpenAI-compatible client settings from `Config`
268
305
  * values before constructing the service.
269
306
  *
307
+ * **When to use**
308
+ *
309
+ * Use when OpenAI-compatible client settings should be read from Effect
310
+ * `Config` values while providing `OpenAiClient` as a layer.
311
+ *
312
+ * **Details**
313
+ *
314
+ * Only config values supplied in `options` are loaded. Omitted fields are
315
+ * passed to `make` as `undefined`, and `transformClient` is forwarded as a
316
+ * plain option.
317
+ *
318
+ * @see {@link make} for constructing the client service effectfully
319
+ * @see {@link layer} for providing the client from already-resolved options
320
+ *
270
321
  * @category layers
271
322
  * @since 4.0.0
272
323
  */
@@ -30,6 +30,13 @@ import type { HttpClient } from "effect/unstable/http/HttpClient"
30
30
  * Context service used to carry OpenAI-compatible client configuration for the
31
31
  * current Effect scope.
32
32
  *
33
+ * **When to use**
34
+ *
35
+ * Use as the context service for OpenAI-compatible client configuration when you
36
+ * need to provide or read scoped HTTP client transforms through Effect context.
37
+ *
38
+ * @see {@link withClientTransform} for scoping an HTTP client transformation
39
+ *
33
40
  * @category services
34
41
  * @since 4.0.0
35
42
  */
@@ -71,7 +78,7 @@ export declare namespace OpenAiConfig {
71
78
  *
72
79
  * **When to use**
73
80
  *
74
- * Use this to add provider-specific OpenAI-compatible HTTP behavior, such as
81
+ * Use to add provider-specific OpenAI-compatible HTTP behavior, such as
75
82
  * headers, retries, instrumentation, or proxy routing.
76
83
  *
77
84
  * **Details**
@@ -88,7 +95,7 @@ export const withClientTransform: {
88
95
  *
89
96
  * **When to use**
90
97
  *
91
- * Use this to add provider-specific OpenAI-compatible HTTP behavior, such as
98
+ * Use to add provider-specific OpenAI-compatible HTTP behavior, such as
92
99
  * headers, retries, instrumentation, or proxy routing.
93
100
  *
94
101
  * **Details**
@@ -105,7 +112,7 @@ export const withClientTransform: {
105
112
  *
106
113
  * **When to use**
107
114
  *
108
- * Use this to add provider-specific OpenAI-compatible HTTP behavior, such as
115
+ * Use to add provider-specific OpenAI-compatible HTTP behavior, such as
109
116
  * headers, retries, instrumentation, or proxy routing.
110
117
  *
111
118
  * **Details**
@@ -1,7 +1,37 @@
1
1
  /**
2
- * OpenAI Embedding Model implementation.
2
+ * The `OpenAiEmbeddingModel` module adapts OpenAI-compatible embeddings
3
+ * endpoints to Effect's embedding model service. It sends embedding requests
4
+ * through {@link OpenAiClient}, exposes constructors for layers and `AiModel`
5
+ * values, and supports scoped request configuration overrides.
3
6
  *
4
- * Provides an EmbeddingModel implementation for OpenAI-compatible embeddings APIs.
7
+ * **Mental model**
8
+ *
9
+ * - {@link make} builds the `EmbeddingModel` service when an
10
+ * {@link OpenAiClient} is already available.
11
+ * - {@link layer} provides that service as a `Layer`.
12
+ * - {@link model} creates an `AiModel` and also provides the configured vector
13
+ * dimensions service expected by embedding consumers.
14
+ * - {@link Config} and {@link withConfigOverride} merge default request options
15
+ * with scoped overrides for individual operations.
16
+ *
17
+ * **Common tasks**
18
+ *
19
+ * - Use {@link model} when application code wants a named `AiModel` with known
20
+ * dimensions.
21
+ * - Use {@link layer} when composing services around an existing
22
+ * {@link OpenAiClient} layer.
23
+ * - Use {@link withConfigOverride} to set per-operation options such as `user`,
24
+ * `dimensions`, or provider-specific request fields.
25
+ *
26
+ * **Gotchas**
27
+ *
28
+ * - {@link Model} is `string` because OpenAI-compatible providers use their
29
+ * own embedding model identifiers.
30
+ * - {@link model} requires explicit dimensions because compatible providers do
31
+ * not expose a shared way to infer vector width.
32
+ * - Provider responses must contain one numeric vector per input with unique,
33
+ * in-range indexes; base64 embeddings or malformed indexes fail with
34
+ * `InvalidOutputError`.
5
35
  *
6
36
  * @since 4.0.0
7
37
  */
@@ -27,6 +57,20 @@ export type Model = string
27
57
  /**
28
58
  * Service definition for OpenAI embedding model configuration.
29
59
  *
60
+ * **When to use**
61
+ *
62
+ * Use when you need to provide shared default request options for
63
+ * OpenAI-compatible embedding operations through the Effect context, such as
64
+ * `dimensions`, `encoding_format`, or `user`.
65
+ *
66
+ * **Details**
67
+ *
68
+ * The service stores the embedding request payload without `input`. Requests
69
+ * combine the selected model, layer or constructor config, and scoped context
70
+ * config, with scoped context config taking precedence.
71
+ *
72
+ * @see {@link withConfigOverride} for scoping embedding request overrides
73
+ *
30
74
  * @category context
31
75
  * @since 4.0.0
32
76
  */
@@ -46,8 +90,15 @@ export class Config extends Context.Service<
46
90
  >()("@effect/ai-openai-compat/OpenAiEmbeddingModel/Config") {}
47
91
 
48
92
  /**
49
- * Creates an OpenAI-compatible embedding model that can be used with
50
- * `AiModel.provide`.
93
+ * Creates an `AiModel` for an OpenAI-compatible embedding model with its configured vector dimensions.
94
+ *
95
+ * **When to use**
96
+ *
97
+ * Use to provide an OpenAI-compatible `EmbeddingModel` and its `Dimensions`
98
+ * service to an Effect program.
99
+ *
100
+ * @see {@link layer} for providing only the embedding model service
101
+ * @see {@link withConfigOverride} for scoped request configuration overrides
51
102
  *
52
103
  * @category constructors
53
104
  * @since 4.0.0
@@ -75,7 +126,29 @@ export const model = (
75
126
  )
76
127
 
77
128
  /**
78
- * Creates an OpenAI embedding model service.
129
+ * Creates an OpenAI-compatible embedding model service backed by `OpenAiClient`.
130
+ *
131
+ * **When to use**
132
+ *
133
+ * Use when you need to build or provide an `EmbeddingModel` service directly
134
+ * from an existing `OpenAiClient`.
135
+ *
136
+ * **Details**
137
+ *
138
+ * The service sends embedding requests through `OpenAiClient.createEmbedding`.
139
+ * Request config is merged as the selected model, constructor config, then
140
+ * scoped `Config`, so scoped overrides take precedence. Provider usage
141
+ * `prompt_tokens` is exposed as `usage.inputTokens`.
142
+ *
143
+ * **Gotchas**
144
+ *
145
+ * Provider responses must contain one numeric vector for every requested input
146
+ * with unique, in-range `index` values; otherwise embedding operations fail with
147
+ * `AiError.InvalidOutputError`.
148
+ *
149
+ * @see {@link model} for the higher-level `AiModel` descriptor that also provides `EmbeddingModel.Dimensions`
150
+ * @see {@link layer} for providing the service as a `Layer`
151
+ * @see {@link withConfigOverride} for scoping embedding request overrides
79
152
  *
80
153
  * @category constructors
81
154
  * @since 4.0.0
@@ -101,7 +174,16 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
101
174
  })
102
175
 
103
176
  /**
104
- * Creates a layer for the OpenAI embedding model.
177
+ * Creates a layer for an OpenAI-compatible embedding model service.
178
+ *
179
+ * **When to use**
180
+ *
181
+ * Use when composing application layers and you want an OpenAI-compatible
182
+ * embeddings endpoint to satisfy `EmbeddingModel.EmbeddingModel` while
183
+ * supplying `OpenAiClient` from another layer.
184
+ *
185
+ * @see {@link make} for constructing the embedding model service effectfully
186
+ * @see {@link model} for creating an `AiModel` with configured dimensions
105
187
  *
106
188
  * @category layers
107
189
  * @since 4.0.0
@@ -113,21 +195,63 @@ export const layer = (options: {
113
195
  Layer.effect(EmbeddingModel.EmbeddingModel, make(options))
114
196
 
115
197
  /**
116
- * Provides config overrides for OpenAI embedding model operations.
198
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
199
+ *
200
+ * **When to use**
201
+ *
202
+ * Use to apply embedding request options to one effect without changing the
203
+ * model's default configuration.
204
+ *
205
+ * **Details**
206
+ *
207
+ * The overrides are merged with any existing `Config` service for the duration
208
+ * of the supplied effect. Fields in `overrides` take precedence over existing
209
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
210
+ * and `withConfigOverride(effect, overrides)`.
211
+ *
212
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
117
213
  *
118
214
  * @category configuration
119
215
  * @since 4.0.0
120
216
  */
121
217
  export const withConfigOverride: {
122
218
  /**
123
- * Provides config overrides for OpenAI embedding model operations.
219
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
220
+ *
221
+ * **When to use**
222
+ *
223
+ * Use to apply embedding request options to one effect without changing the
224
+ * model's default configuration.
225
+ *
226
+ * **Details**
227
+ *
228
+ * The overrides are merged with any existing `Config` service for the duration
229
+ * of the supplied effect. Fields in `overrides` take precedence over existing
230
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
231
+ * and `withConfigOverride(effect, overrides)`.
232
+ *
233
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
124
234
  *
125
235
  * @category configuration
126
236
  * @since 4.0.0
127
237
  */
128
238
  (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>
129
239
  /**
130
- * Provides config overrides for OpenAI embedding model operations.
240
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
241
+ *
242
+ * **When to use**
243
+ *
244
+ * Use to apply embedding request options to one effect without changing the
245
+ * model's default configuration.
246
+ *
247
+ * **Details**
248
+ *
249
+ * The overrides are merged with any existing `Config` service for the duration
250
+ * of the supplied effect. Fields in `overrides` take precedence over existing
251
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
252
+ * and `withConfigOverride(effect, overrides)`.
253
+ *
254
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
131
255
  *
132
256
  * @category configuration
133
257
  * @since 4.0.0
@@ -135,14 +259,42 @@ export const withConfigOverride: {
135
259
  <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>
136
260
  } = dual<
137
261
  /**
138
- * Provides config overrides for OpenAI embedding model operations.
262
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
263
+ *
264
+ * **When to use**
265
+ *
266
+ * Use to apply embedding request options to one effect without changing the
267
+ * model's default configuration.
268
+ *
269
+ * **Details**
270
+ *
271
+ * The overrides are merged with any existing `Config` service for the duration
272
+ * of the supplied effect. Fields in `overrides` take precedence over existing
273
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
274
+ * and `withConfigOverride(effect, overrides)`.
275
+ *
276
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
139
277
  *
140
278
  * @category configuration
141
279
  * @since 4.0.0
142
280
  */
143
281
  (overrides: typeof Config.Service) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>,
144
282
  /**
145
- * Provides config overrides for OpenAI embedding model operations.
283
+ * Provides scoped request config overrides for OpenAI-compatible embedding model operations.
284
+ *
285
+ * **When to use**
286
+ *
287
+ * Use to apply embedding request options to one effect without changing the
288
+ * model's default configuration.
289
+ *
290
+ * **Details**
291
+ *
292
+ * The overrides are merged with any existing `Config` service for the duration
293
+ * of the supplied effect. Fields in `overrides` take precedence over existing
294
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
295
+ * and `withConfigOverride(effect, overrides)`.
296
+ *
297
+ * @see {@link Config} for available OpenAI-compatible embedding request configuration fields
146
298
  *
147
299
  * @category configuration
148
300
  * @since 4.0.0
@@ -1,8 +1,34 @@
1
1
  /**
2
- * OpenAI Language Model implementation.
2
+ * The `OpenAiLanguageModel` module adapts OpenAI-compatible chat-completions
3
+ * providers to the shared Effect AI `LanguageModel` interface. It translates
4
+ * provider-neutral prompts, tools, structured output schemas, and streaming
5
+ * responses into the request and response shapes used by `OpenAiClient`.
3
6
  *
4
- * Provides a LanguageModel implementation for OpenAI's chat completions API,
5
- * supporting text generation, structured output, tool calling, and streaming.
7
+ * Use this module when an application wants to talk to OpenAI-compatible
8
+ * endpoints through Effect AI abstractions rather than constructing provider
9
+ * payloads directly. The exported constructors build a language model service
10
+ * from a model id, while `Config` and {@link withConfigOverride} provide scoped
11
+ * defaults for request fields such as temperature, reasoning options, text
12
+ * format, and provider-specific file handling.
13
+ *
14
+ * **Common tasks**
15
+ *
16
+ * - Create a model descriptor with {@link model}
17
+ * - Build or provide the `LanguageModel` service with {@link make} or
18
+ * {@link layer}
19
+ * - Scope request defaults with {@link Config} and {@link withConfigOverride}
20
+ * - Send tool calls, structured output schemas, images, files, and reasoning
21
+ * metadata through the provider-neutral Effect AI prompt types
22
+ *
23
+ * **Gotchas**
24
+ *
25
+ * - The module requires an `OpenAiClient` service; configure authentication,
26
+ * base URL, and HTTP behavior through that client layer.
27
+ * - Compatibility depends on the provider supporting the OpenAI request fields
28
+ * being used. Optional capabilities such as strict JSON schemas, reasoning
29
+ * metadata, and tool status fields may vary across providers.
30
+ * - `fileIdPrefixes` tells the prompt conversion which file references are
31
+ * provider file IDs instead of base64 file contents.
6
32
  *
7
33
  * @since 4.0.0
8
34
  */
@@ -61,6 +87,14 @@ type ImageDetail = "auto" | "low" | "high"
61
87
  /**
62
88
  * Service definition for OpenAI language model configuration.
63
89
  *
90
+ * **When to use**
91
+ *
92
+ * Use as the context service for OpenAI-compatible language model request
93
+ * configuration, especially when a scoped operation should override the defaults
94
+ * supplied to `model`, `make`, or `layer`.
95
+ *
96
+ * @see {@link withConfigOverride} for scoping language model request overrides
97
+ *
64
98
  * @category context
65
99
  * @since 4.0.0
66
100
  */
@@ -506,7 +540,15 @@ declare module "effect/unstable/ai/Response" {
506
540
  // =============================================================================
507
541
 
508
542
  /**
509
- * Creates an AI model descriptor for an OpenAI-compatible language model.
543
+ * Creates an OpenAI-compatible model descriptor that can be provided with `Effect.provide`.
544
+ *
545
+ * **When to use**
546
+ *
547
+ * Use when you want an OpenAI-compatible language model value that carries
548
+ * provider and model metadata and can be supplied directly to an Effect program.
549
+ *
550
+ * @see {@link layer} for creating a `LanguageModel.LanguageModel` layer directly
551
+ * @see {@link make} for constructing the language model service effectfully
510
552
  *
511
553
  * @category constructors
512
554
  * @since 4.0.0
@@ -529,7 +571,22 @@ export const model = (
529
571
  // AiModel.make("openai", model, layerWithTokenizer({ model, config }))
530
572
 
531
573
  /**
532
- * Creates an OpenAI language model service.
574
+ * Creates an OpenAI-compatible `LanguageModel` service from a model identifier and optional request defaults.
575
+ *
576
+ * **When to use**
577
+ *
578
+ * Use when an Effect needs to construct a `LanguageModel.Service` value backed
579
+ * by `OpenAiClient`.
580
+ *
581
+ * **Details**
582
+ *
583
+ * The returned effect requires `OpenAiClient`. Request defaults from the
584
+ * `config` option are merged with any `Config` service in the context, with
585
+ * context values taking precedence. The service supports both `generateText` and
586
+ * `streamText`.
587
+ *
588
+ * @see {@link layer} for providing the service as a `Layer`
589
+ * @see {@link model} for creating a model descriptor for `AiModel.provide`
533
590
  *
534
591
  * @category constructors
535
592
  * @since 4.0.0
@@ -628,7 +685,16 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
628
685
  })
629
686
 
630
687
  /**
631
- * Creates a layer for the OpenAI language model.
688
+ * Creates a layer for the OpenAI-compatible language model.
689
+ *
690
+ * **When to use**
691
+ *
692
+ * Use when composing application layers and you want OpenAI-compatible APIs to
693
+ * satisfy `LanguageModel.LanguageModel` while supplying `OpenAiClient` from
694
+ * another layer.
695
+ *
696
+ * @see {@link make} for constructing the language model service effectfully
697
+ * @see {@link model} for creating an AI model descriptor
632
698
  *
633
699
  * @category layers
634
700
  * @since 4.0.0
@@ -640,21 +706,57 @@ export const layer = (options: {
640
706
  Layer.effect(LanguageModel.LanguageModel, make(options))
641
707
 
642
708
  /**
643
- * Provides config overrides for OpenAI language model operations.
709
+ * Provides scoped config overrides for OpenAI-compatible language model operations.
710
+ *
711
+ * **When to use**
712
+ *
713
+ * Use to override request configuration for a single language model effect
714
+ * without changing the defaults supplied to `model`, `make`, or `layer`.
715
+ *
716
+ * **Details**
717
+ *
718
+ * Existing `Config` values from the Effect context are merged with `overrides`,
719
+ * and the override values take precedence.
720
+ *
721
+ * @see {@link Config} for the configuration shape
644
722
  *
645
723
  * @category configuration
646
724
  * @since 4.0.0
647
725
  */
648
726
  export const withConfigOverride: {
649
727
  /**
650
- * Provides config overrides for OpenAI language model operations.
728
+ * Provides scoped config overrides for OpenAI-compatible language model operations.
729
+ *
730
+ * **When to use**
731
+ *
732
+ * Use to override request configuration for a single language model effect
733
+ * without changing the defaults supplied to `model`, `make`, or `layer`.
734
+ *
735
+ * **Details**
736
+ *
737
+ * Existing `Config` values from the Effect context are merged with `overrides`,
738
+ * and the override values take precedence.
739
+ *
740
+ * @see {@link Config} for the configuration shape
651
741
  *
652
742
  * @category configuration
653
743
  * @since 4.0.0
654
744
  */
655
745
  (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>
656
746
  /**
657
- * Provides config overrides for OpenAI language model operations.
747
+ * Provides scoped config overrides for OpenAI-compatible language model operations.
748
+ *
749
+ * **When to use**
750
+ *
751
+ * Use to override request configuration for a single language model effect
752
+ * without changing the defaults supplied to `model`, `make`, or `layer`.
753
+ *
754
+ * **Details**
755
+ *
756
+ * Existing `Config` values from the Effect context are merged with `overrides`,
757
+ * and the override values take precedence.
758
+ *
759
+ * @see {@link Config} for the configuration shape
658
760
  *
659
761
  * @category configuration
660
762
  * @since 4.0.0
@@ -662,14 +764,38 @@ export const withConfigOverride: {
662
764
  <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>
663
765
  } = dual<
664
766
  /**
665
- * Provides config overrides for OpenAI language model operations.
767
+ * Provides scoped config overrides for OpenAI-compatible language model operations.
768
+ *
769
+ * **When to use**
770
+ *
771
+ * Use to override request configuration for a single language model effect
772
+ * without changing the defaults supplied to `model`, `make`, or `layer`.
773
+ *
774
+ * **Details**
775
+ *
776
+ * Existing `Config` values from the Effect context are merged with `overrides`,
777
+ * and the override values take precedence.
778
+ *
779
+ * @see {@link Config} for the configuration shape
666
780
  *
667
781
  * @category configuration
668
782
  * @since 4.0.0
669
783
  */
670
784
  (overrides: typeof Config.Service) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>,
671
785
  /**
672
- * Provides config overrides for OpenAI language model operations.
786
+ * Provides scoped config overrides for OpenAI-compatible language model operations.
787
+ *
788
+ * **When to use**
789
+ *
790
+ * Use to override request configuration for a single language model effect
791
+ * without changing the defaults supplied to `model`, `make`, or `layer`.
792
+ *
793
+ * **Details**
794
+ *
795
+ * Existing `Config` values from the Effect context are merged with `overrides`,
796
+ * and the override values take precedence.
797
+ *
798
+ * @see {@link Config} for the configuration shape
673
799
  *
674
800
  * @category configuration
675
801
  * @since 4.0.0
@@ -1,9 +1,35 @@
1
1
  /**
2
- * OpenAI telemetry attributes for OpenTelemetry integration.
2
+ * The `OpenAiTelemetry` module adds OpenAI-compatible provider attributes to
3
+ * the provider-neutral GenAI telemetry model. It keeps the standard
4
+ * `Telemetry.addGenAIAnnotations` attributes and adds OpenAI request and
5
+ * response metadata under the `gen_ai.openai.*` OpenTelemetry namespaces.
6
+ *
7
+ * **Mental model**
8
+ *
9
+ * - Standard GenAI attributes come from `effect/unstable/ai/Telemetry`
10
+ * - OpenAI request attributes are written under `gen_ai.openai.request.*`
11
+ * - OpenAI response attributes are written under `gen_ai.openai.response.*`
12
+ * - Attribute option keys are written in camelCase and converted to
13
+ * OpenTelemetry snake_case attribute names
14
+ * - {@link addGenAIAnnotations} mutates the supplied span by adding any
15
+ * non-nullish attributes from the option object
16
+ *
17
+ * **Common tasks**
18
+ *
19
+ * - Use {@link OpenAiTelemetryAttributes} when typing the complete set of
20
+ * standard and OpenAI-specific span attributes
21
+ * - Pass `openai.request` data for requested response format and service tier
22
+ * - Pass `openai.response` data for the service tier actually used and the
23
+ * system fingerprint returned by the provider
24
+ * - Use {@link addGenAIAnnotations} from an OpenAI-compatible model span to keep
25
+ * standard GenAI and provider-specific annotations together
3
26
  *
4
- * Provides OpenAI-specific GenAI telemetry attributes following OpenTelemetry
5
- * semantic conventions, extending the base GenAI attributes with OpenAI-specific
6
- * request and response metadata.
27
+ * **Gotchas**
28
+ *
29
+ * - This module only annotates spans; it does not start spans or export traces
30
+ * - Null and undefined attribute values are skipped instead of being written
31
+ * - OpenAI-compatible providers may not return every OpenAI-specific response
32
+ * field, so only pass fields that are present on the provider response
7
33
  *
8
34
  * @since 4.0.0
9
35
  */
@@ -17,7 +43,12 @@ import * as Telemetry from "effect/unstable/ai/Telemetry"
17
43
  * The attributes used to describe telemetry in the context of Generative
18
44
  * Artificial Intelligence (GenAI) Models requests and responses.
19
45
  *
20
- * @see https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/
46
+ * **Details**
47
+ *
48
+ * These attributes follow the OpenTelemetry generative AI semantic
49
+ * conventions:
50
+ * https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/
51
+ *
21
52
  * @category models
22
53
  * @since 4.0.0
23
54
  */
@@ -126,6 +157,17 @@ const addOpenAiResponseAttributes = Telemetry.addSpanAttributes("gen_ai.openai.r
126
157
  * Applies the specified OpenAi GenAI telemetry attributes to the provided
127
158
  * `Span`.
128
159
  *
160
+ * **When to use**
161
+ *
162
+ * Use to annotate an OpenAI-compatible model span with standard GenAI telemetry
163
+ * attributes and OpenAI-specific request or response metadata.
164
+ *
165
+ * **Details**
166
+ *
167
+ * Standard GenAI attributes are applied first. When OpenAI request or response
168
+ * metadata is present, it is written under `gen_ai.openai.request.*` and
169
+ * `gen_ai.openai.response.*` attributes.
170
+ *
129
171
  * **Gotchas**
130
172
  *
131
173
  * This method will mutate the `Span` **in-place**.
@@ -138,6 +180,17 @@ export const addGenAIAnnotations: {
138
180
  * Applies the specified OpenAi GenAI telemetry attributes to the provided
139
181
  * `Span`.
140
182
  *
183
+ * **When to use**
184
+ *
185
+ * Use to annotate an OpenAI-compatible model span with standard GenAI telemetry
186
+ * attributes and OpenAI-specific request or response metadata.
187
+ *
188
+ * **Details**
189
+ *
190
+ * Standard GenAI attributes are applied first. When OpenAI request or response
191
+ * metadata is present, it is written under `gen_ai.openai.request.*` and
192
+ * `gen_ai.openai.response.*` attributes.
193
+ *
141
194
  * **Gotchas**
142
195
  *
143
196
  * This method will mutate the `Span` **in-place**.
@@ -150,6 +203,17 @@ export const addGenAIAnnotations: {
150
203
  * Applies the specified OpenAi GenAI telemetry attributes to the provided
151
204
  * `Span`.
152
205
  *
206
+ * **When to use**
207
+ *
208
+ * Use to annotate an OpenAI-compatible model span with standard GenAI telemetry
209
+ * attributes and OpenAI-specific request or response metadata.
210
+ *
211
+ * **Details**
212
+ *
213
+ * Standard GenAI attributes are applied first. When OpenAI request or response
214
+ * metadata is present, it is written under `gen_ai.openai.request.*` and
215
+ * `gen_ai.openai.response.*` attributes.
216
+ *
153
217
  * **Gotchas**
154
218
  *
155
219
  * This method will mutate the `Span` **in-place**.