@effect/ai-openai 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.
Files changed (41) hide show
  1. package/dist/OpenAiClient.d.ts +87 -3
  2. package/dist/OpenAiClient.d.ts.map +1 -1
  3. package/dist/OpenAiClient.js +118 -6
  4. package/dist/OpenAiClient.js.map +1 -1
  5. package/dist/OpenAiConfig.d.ts +84 -15
  6. package/dist/OpenAiConfig.d.ts.map +1 -1
  7. package/dist/OpenAiConfig.js +52 -15
  8. package/dist/OpenAiConfig.js.map +1 -1
  9. package/dist/OpenAiEmbeddingModel.d.ts +126 -2
  10. package/dist/OpenAiEmbeddingModel.d.ts.map +1 -1
  11. package/dist/OpenAiEmbeddingModel.js +100 -2
  12. package/dist/OpenAiEmbeddingModel.js.map +1 -1
  13. package/dist/OpenAiLanguageModel.d.ts +138 -9
  14. package/dist/OpenAiLanguageModel.d.ts.map +1 -1
  15. package/dist/OpenAiLanguageModel.js +106 -7
  16. package/dist/OpenAiLanguageModel.js.map +1 -1
  17. package/dist/OpenAiSchema.d.ts +281 -12
  18. package/dist/OpenAiSchema.d.ts.map +1 -1
  19. package/dist/OpenAiSchema.js +227 -4
  20. package/dist/OpenAiSchema.js.map +1 -1
  21. package/dist/OpenAiTelemetry.d.ts +29 -1
  22. package/dist/OpenAiTelemetry.d.ts.map +1 -1
  23. package/dist/OpenAiTelemetry.js +29 -4
  24. package/dist/OpenAiTelemetry.js.map +1 -1
  25. package/dist/OpenAiTool.d.ts +111 -5
  26. package/dist/OpenAiTool.d.ts.map +1 -1
  27. package/dist/OpenAiTool.js +111 -5
  28. package/dist/OpenAiTool.js.map +1 -1
  29. package/dist/index.d.ts +1 -49
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -49
  32. package/dist/index.js.map +1 -1
  33. package/package.json +3 -3
  34. package/src/OpenAiClient.ts +118 -6
  35. package/src/OpenAiConfig.ts +84 -15
  36. package/src/OpenAiEmbeddingModel.ts +152 -2
  37. package/src/OpenAiLanguageModel.ts +170 -11
  38. package/src/OpenAiSchema.ts +309 -4
  39. package/src/OpenAiTelemetry.ts +50 -5
  40. package/src/OpenAiTool.ts +111 -5
  41. package/src/index.ts +1 -49
@@ -1,8 +1,42 @@
1
1
  /**
2
- * Minimal local OpenAI schemas used by the handwritten Responses client path.
2
+ * The `OpenAiSchema` module defines the request, response, streaming, and
3
+ * embedding schemas used by the handwritten OpenAI client. These schemas are
4
+ * the transport boundary for JSON sent to and decoded from the Responses and
5
+ * embeddings endpoints.
6
+ *
7
+ * **Mental model**
8
+ *
9
+ * - Request schemas such as {@link CreateResponse} and
10
+ * {@link CreateEmbeddingRequest} describe the encoded payloads sent to OpenAI.
11
+ * - Response schemas such as {@link Response}, {@link ResponseStreamEvent}, and
12
+ * {@link CreateEmbeddingResponse} describe provider data after schema
13
+ * decoding.
14
+ * - Shared schemas such as {@link InputItem}, {@link Tool}, and
15
+ * {@link TextResponseFormatConfiguration} cover the message, tool, and output
16
+ * format fragments reused across request and response shapes.
17
+ *
18
+ * **Common tasks**
19
+ *
20
+ * - Use {@link CreateResponse} with {@link Response} for non-streaming
21
+ * Responses API calls.
22
+ * - Use {@link ResponseStreamEvent} for server-sent events emitted by streaming
23
+ * Responses API calls.
24
+ * - Use {@link CreateEmbeddingRequest} and {@link CreateEmbeddingResponse} for
25
+ * embeddings endpoint payloads.
26
+ * - Use smaller schemas like {@link IncludeEnum}, {@link InputContent}, and
27
+ * {@link ToolChoice} when validating request fragments.
28
+ *
29
+ * **Gotchas**
30
+ *
31
+ * - The module models the subset of OpenAI shapes supported by this client
32
+ * path; it is not a complete mirror of every OpenAI REST API field.
33
+ * - Unknown future stream event types decode through
34
+ * {@link UnknownResponseStreamEvent}, while malformed known event types still
35
+ * fail schema decoding.
3
36
  *
4
37
  * @since 4.0.0
5
38
  */
39
+ import * as Effect from "effect/Effect"
6
40
  import * as Predicate from "effect/Predicate"
7
41
  import * as Schema from "effect/Schema"
8
42
 
@@ -15,11 +49,15 @@ const MessageRole = Schema.Literals(["system", "developer", "user", "assistant"]
15
49
  const ImageDetail = Schema.Literals(["low", "high", "auto"])
16
50
 
17
51
  /**
18
- * Schema for optional `include` values on OpenAI Responses requests.
52
+ * Schema for optional `include` values supported by the local handwritten
53
+ * Responses client schema.
19
54
  *
20
55
  * **Details**
21
56
  *
22
- * These values request additional response fields such as image URLs, encrypted reasoning content, output logprobs, code interpreter outputs, or web search sources.
57
+ * These values request additional response fields such as image URLs, encrypted
58
+ * reasoning content, output logprobs, code interpreter outputs, or web search
59
+ * sources. This schema enumerates the include values supported by this client
60
+ * path.
23
61
  *
24
62
  * @category schemas
25
63
  * @since 4.0.0
@@ -43,6 +81,11 @@ export type IncludeEnum = typeof IncludeEnum.Type
43
81
  /**
44
82
  * Schema for lifecycle statuses shared by messages, reasoning items, and tool calls.
45
83
  *
84
+ * **Details**
85
+ *
86
+ * Accepted values are `"in_progress"`, `"completed"`, and `"incomplete"`.
87
+ * This item-level status is used by message, reasoning, and tool-call shapes.
88
+ *
46
89
  * @category schemas
47
90
  * @since 4.0.0
48
91
  */
@@ -51,6 +94,10 @@ export const MessageStatus = Schema.Literals(["in_progress", "completed", "incom
51
94
  /**
52
95
  * Lifecycle status shared by messages, reasoning items, and tool calls.
53
96
  *
97
+ * **Details**
98
+ *
99
+ * Accepted values are `"in_progress"`, `"completed"`, and `"incomplete"`.
100
+ *
54
101
  * @category models
55
102
  * @since 4.0.0
56
103
  */
@@ -79,6 +126,12 @@ const InputFileContent = Schema.Struct({
79
126
  /**
80
127
  * Schema for content blocks accepted in OpenAI Responses input messages.
81
128
  *
129
+ * **Details**
130
+ *
131
+ * Accepted block variants are `input_text`, `input_image`, and `input_file`.
132
+ *
133
+ * @see {@link InputItem} for request input item shapes that can contain these content blocks
134
+ *
82
135
  * @category schemas
83
136
  * @since 4.0.0
84
137
  */
@@ -91,6 +144,10 @@ export const InputContent = Schema.Union([
91
144
  /**
92
145
  * Content block accepted in OpenAI Responses input messages.
93
146
  *
147
+ * **Details**
148
+ *
149
+ * Accepted block variants are `input_text`, `input_image`, and `input_file`.
150
+ *
94
151
  * @category models
95
152
  * @since 4.0.0
96
153
  */
@@ -99,6 +156,13 @@ export type InputContent = typeof InputContent.Type
99
156
  /**
100
157
  * Schema for a text block containing a model-provided reasoning summary.
101
158
  *
159
+ * **Details**
160
+ *
161
+ * The decoded shape is `type: "summary_text"` plus `text` containing the
162
+ * reasoning summary text.
163
+ *
164
+ * @see {@link ReasoningItem} for reasoning output items that contain summary text blocks
165
+ *
102
166
  * @category schemas
103
167
  * @since 4.0.0
104
168
  */
@@ -169,6 +233,11 @@ const FilePathAnnotation = Schema.Struct({
169
233
  /**
170
234
  * Schema for citation and file-path annotations attached to output text content.
171
235
  *
236
+ * **Details**
237
+ *
238
+ * Accepts annotation objects discriminated by `type`: `file_citation`,
239
+ * `url_citation`, `container_file_citation`, or `file_path`.
240
+ *
172
241
  * @category schemas
173
242
  * @since 4.0.0
174
243
  */
@@ -182,6 +251,11 @@ export const Annotation = Schema.Union([
182
251
  /**
183
252
  * Citation or file-path annotation attached to output text content.
184
253
  *
254
+ * **Details**
255
+ *
256
+ * Accepted annotation variants are `file_citation`, `url_citation`,
257
+ * `container_file_citation`, and `file_path`.
258
+ *
185
259
  * @category models
186
260
  * @since 4.0.0
187
261
  */
@@ -217,6 +291,24 @@ const OutputMessage = Schema.Struct({
217
291
  /**
218
292
  * Schema for a reasoning output item containing encrypted content, summaries, and optional reasoning text.
219
293
  *
294
+ * **When to use**
295
+ *
296
+ * Use when decoding or encoding OpenAI Responses reasoning items that may be
297
+ * carried into later request input.
298
+ *
299
+ * **Details**
300
+ *
301
+ * Reasoning items represent model reasoning content. `summary` is required,
302
+ * while `content` and `status` are optional.
303
+ *
304
+ * **Gotchas**
305
+ *
306
+ * `encrypted_content` is populated only when `reasoning.encrypted_content` is
307
+ * requested through `include`.
308
+ *
309
+ * @see {@link InputItem} for request input items that can carry reasoning items
310
+ * @see {@link IncludeEnum} for requesting encrypted reasoning content
311
+ *
220
312
  * @category schemas
221
313
  * @since 4.0.0
222
314
  */
@@ -232,6 +324,21 @@ export const ReasoningItem = Schema.Struct({
232
324
  /**
233
325
  * Reasoning output item containing encrypted content, summaries, and optional reasoning text.
234
326
  *
327
+ * **When to use**
328
+ *
329
+ * Use when typing OpenAI Responses reasoning items that may be carried into
330
+ * later request input.
331
+ *
332
+ * **Details**
333
+ *
334
+ * Reasoning items represent model reasoning content. `summary` is required,
335
+ * while `content` and `status` are optional.
336
+ *
337
+ * **Gotchas**
338
+ *
339
+ * `encrypted_content` is populated only when `reasoning.encrypted_content` is
340
+ * requested through `include`.
341
+ *
235
342
  * @category models
236
343
  * @since 4.0.0
237
344
  */
@@ -321,6 +428,19 @@ const RequestMessageItem = Schema.Struct({
321
428
  /**
322
429
  * Schema for item shapes accepted by an OpenAI Responses request `input` field.
323
430
  *
431
+ * **When to use**
432
+ *
433
+ * Use when validating structured `CreateResponse.input` array items.
434
+ *
435
+ * **Details**
436
+ *
437
+ * Accepted item families include request/output messages, function call and
438
+ * function call output, reasoning items, item references, shell and local shell
439
+ * calls and outputs, apply-patch output, and MCP approval responses.
440
+ *
441
+ * @see {@link CreateResponse} for the request schema that consumes input items
442
+ * @see {@link InputContent} for content blocks inside message items
443
+ *
324
444
  * @category schemas
325
445
  * @since 4.0.0
326
446
  */
@@ -342,6 +462,16 @@ export const InputItem = Schema.Union([
342
462
  /**
343
463
  * Item shape accepted by an OpenAI Responses request `input` field.
344
464
  *
465
+ * **When to use**
466
+ *
467
+ * Use when typing structured `CreateResponse.input` array items.
468
+ *
469
+ * **Details**
470
+ *
471
+ * Accepted item families include request/output messages, function call and
472
+ * function call output, reasoning items, item references, shell and local shell
473
+ * calls and outputs, apply-patch output, and MCP approval responses.
474
+ *
345
475
  * @category models
346
476
  * @since 4.0.0
347
477
  */
@@ -382,6 +512,22 @@ const ProviderDefinedTool = Schema.StructWithRest(
382
512
  /**
383
513
  * Schema for tool definitions that can be supplied to an OpenAI Responses request.
384
514
  *
515
+ * **Details**
516
+ *
517
+ * Accepted variants are function tools, custom tools, and provider-defined
518
+ * OpenAI tools. Provider-defined `type` literals include `apply_patch`,
519
+ * `code_interpreter`, `file_search`, `image_generation`, `local_shell`, `mcp`,
520
+ * `shell`, `web_search`, and `web_search_preview`.
521
+ *
522
+ * **Gotchas**
523
+ *
524
+ * Provider-defined tools use `Schema.StructWithRest`, so this schema checks the
525
+ * provider tool `type` and permits additional provider fields rather than fully
526
+ * validating every provider-specific tool payload.
527
+ *
528
+ * @see {@link ToolChoice} for selecting whether and which tools the model may call
529
+ * @see {@link CreateResponse} for the request schema that consumes tools
530
+ *
385
531
  * @category schemas
386
532
  * @since 4.0.0
387
533
  */
@@ -402,6 +548,14 @@ export type Tool = typeof Tool.Type
402
548
  /**
403
549
  * Schema for selecting whether and which tools the model may call in a Responses request.
404
550
  *
551
+ * **Details**
552
+ *
553
+ * Accepted forms are `"none"`, `"auto"`, `"required"`, an allowed-tools set,
554
+ * a named function or custom tool, or a provider-defined tool choice.
555
+ *
556
+ * @see {@link Tool} for tool definitions referenced by tool choices
557
+ * @see {@link CreateResponse} for the request schema that consumes `tool_choice`
558
+ *
405
559
  * @category schemas
406
560
  * @since 4.0.0
407
561
  */
@@ -441,6 +595,11 @@ export const ToolChoice = Schema.Union([
441
595
  /**
442
596
  * Tool selection mode or named tool choice for a Responses request.
443
597
  *
598
+ * **Details**
599
+ *
600
+ * Accepted forms are `"none"`, `"auto"`, `"required"`, an allowed-tools set,
601
+ * a named function or custom tool, or a provider-defined tool choice.
602
+ *
444
603
  * @category models
445
604
  * @since 4.0.0
446
605
  */
@@ -449,6 +608,17 @@ export type ToolChoice = typeof ToolChoice.Type
449
608
  /**
450
609
  * Schema for text output format configuration, including plain text, JSON object, and JSON Schema responses.
451
610
  *
611
+ * **Details**
612
+ *
613
+ * Accepted variants are `text`, `json_schema`, and `json_object`.
614
+ *
615
+ * **Gotchas**
616
+ *
617
+ * `json_object` is the older JSON mode. Prefer `json_schema` for models that
618
+ * support it.
619
+ *
620
+ * @see {@link CreateResponse} for the request schema that consumes text format configuration
621
+ *
452
622
  * @category schemas
453
623
  * @since 4.0.0
454
624
  */
@@ -475,6 +645,25 @@ export type TextResponseFormatConfiguration = typeof TextResponseFormatConfigura
475
645
  /**
476
646
  * Schema for request options used to create an OpenAI Responses API response.
477
647
  *
648
+ * **When to use**
649
+ *
650
+ * Use to validate or encode payloads sent to the OpenAI Responses API.
651
+ *
652
+ * **Details**
653
+ *
654
+ * Validates the Responses API request payload, including input content, model
655
+ * selection, instructions, reasoning options, text output format, tools,
656
+ * `tool_choice`, streaming, storage, response continuation, sampling options,
657
+ * and optional response fields requested through `include`.
658
+ *
659
+ * **Gotchas**
660
+ *
661
+ * When `stream` is `true`, the API returns stream events instead of a single
662
+ * response object.
663
+ *
664
+ * @see {@link Response} for decoded non-streaming response objects
665
+ * @see {@link ResponseStreamEvent} for decoded streaming event objects
666
+ *
478
667
  * @category schemas
479
668
  * @since 4.0.0
480
669
  */
@@ -531,6 +720,12 @@ export type CreateResponse = typeof CreateResponse.Type
531
720
  /**
532
721
  * Schema for token accounting reported on OpenAI Responses API response objects.
533
722
  *
723
+ * **Details**
724
+ *
725
+ * The required counters are `input_tokens`, `output_tokens`, and
726
+ * `total_tokens`. Provider-specific token detail objects are preserved through
727
+ * `input_tokens_details`, `output_tokens_details`, and additional fields.
728
+ *
534
729
  * @category schemas
535
730
  * @since 4.0.0
536
731
  */
@@ -548,6 +743,11 @@ export const ResponseUsage = Schema.StructWithRest(
548
743
  /**
549
744
  * Token accounting reported on OpenAI Responses API response objects.
550
745
  *
746
+ * **Details**
747
+ *
748
+ * Includes total input, output, and combined token counts, with provider-specific
749
+ * token detail fields preserved when present.
750
+ *
551
751
  * @category models
552
752
  * @since 4.0.0
553
753
  */
@@ -648,6 +848,19 @@ const OutputItem = Schema.Union([
648
848
  /**
649
849
  * Schema for an OpenAI Responses API response object.
650
850
  *
851
+ * **When to use**
852
+ *
853
+ * Use to decode non-streaming OpenAI Responses API responses.
854
+ *
855
+ * **Details**
856
+ *
857
+ * Response objects include the response id, model, creation time, output items,
858
+ * optional token usage, optional incomplete details, and optional service tier.
859
+ *
860
+ * @see {@link CreateResponse} for the request schema that creates responses
861
+ * @see {@link ResponseUsage} for token accounting on responses
862
+ * @see {@link ResponseStreamEvent} for streaming response events
863
+ *
651
864
  * @category schemas
652
865
  * @since 4.0.0
653
866
  */
@@ -656,7 +869,9 @@ export const Response = Schema.Struct({
656
869
  object: Schema.optionalKey(Schema.Literal("response")),
657
870
  model: Schema.String,
658
871
  created_at: Schema.Number,
659
- output: Schema.Array(OutputItem),
872
+ output: Schema.Array(OutputItem).pipe(
873
+ Schema.withDecodingDefault(Effect.succeed([]))
874
+ ),
660
875
  usage: Schema.optionalKey(Schema.NullOr(ResponseUsage)),
661
876
  incomplete_details: Schema.optionalKey(
662
877
  Schema.NullOr(
@@ -671,6 +886,15 @@ export const Response = Schema.Struct({
671
886
  /**
672
887
  * OpenAI Responses API response object.
673
888
  *
889
+ * **When to use**
890
+ *
891
+ * Use when typing non-streaming OpenAI Responses API responses.
892
+ *
893
+ * **Details**
894
+ *
895
+ * Response objects include metadata, output items, optional token usage, and
896
+ * optional incomplete details.
897
+ *
674
898
  * @category models
675
899
  * @since 4.0.0
676
900
  */
@@ -873,6 +1097,24 @@ const UnknownResponseStreamEvent = Schema.declare<UnknownResponseStreamEvent>(
873
1097
  /**
874
1098
  * Schema for server-sent event shapes emitted by OpenAI Responses API streams.
875
1099
  *
1100
+ * **When to use**
1101
+ *
1102
+ * Use to decode events from a streaming OpenAI Responses API request.
1103
+ *
1104
+ * **Details**
1105
+ *
1106
+ * Known event variants include response lifecycle events, output item events,
1107
+ * text and reasoning deltas, tool-call deltas, partial image events, and error
1108
+ * events.
1109
+ *
1110
+ * **Gotchas**
1111
+ *
1112
+ * Future event types decode through the fallback only when their `type` is not
1113
+ * one of the known event types. Malformed known events still fail to decode.
1114
+ *
1115
+ * @see {@link Response} for complete response objects carried by lifecycle events
1116
+ * @see {@link UnknownResponseStreamEvent} for the fallback shape for future event types
1117
+ *
876
1118
  * @category schemas
877
1119
  * @since 4.0.0
878
1120
  */
@@ -902,6 +1144,15 @@ export const ResponseStreamEvent = Schema.Union([
902
1144
  /**
903
1145
  * Server-sent event shape emitted by OpenAI Responses API streams.
904
1146
  *
1147
+ * **When to use**
1148
+ *
1149
+ * Use when typing events from a streaming OpenAI Responses API request.
1150
+ *
1151
+ * **Details**
1152
+ *
1153
+ * Includes known response stream events plus a fallback shape for unknown future
1154
+ * event types.
1155
+ *
905
1156
  * @category models
906
1157
  * @since 4.0.0
907
1158
  */
@@ -910,6 +1161,16 @@ export type ResponseStreamEvent = typeof ResponseStreamEvent.Type
910
1161
  /**
911
1162
  * Schema for one embedding item returned by the OpenAI embeddings API.
912
1163
  *
1164
+ * **Details**
1165
+ *
1166
+ * An embedding item contains its `index`, optional `object` marker, and an
1167
+ * `embedding` represented either as a numeric vector or as a string.
1168
+ *
1169
+ * **Gotchas**
1170
+ *
1171
+ * Callers that need numeric vectors must account for string embeddings, such as
1172
+ * base64-encoded embeddings returned for string encoding formats.
1173
+ *
913
1174
  * @category schemas
914
1175
  * @since 4.0.0
915
1176
  */
@@ -925,6 +1186,11 @@ export const Embedding = Schema.Struct({
925
1186
  /**
926
1187
  * One embedding item returned by the OpenAI embeddings API.
927
1188
  *
1189
+ * **Details**
1190
+ *
1191
+ * Contains the item index and embedding payload. The embedding payload may be a
1192
+ * numeric vector or a string.
1193
+ *
928
1194
  * @category models
929
1195
  * @since 4.0.0
930
1196
  */
@@ -933,6 +1199,18 @@ export type Embedding = typeof Embedding.Type
933
1199
  /**
934
1200
  * Schema for the request payload sent to the OpenAI embeddings endpoint.
935
1201
  *
1202
+ * **Details**
1203
+ *
1204
+ * Requires `input` and `model`. `input` may be a string, an array of strings,
1205
+ * a token array, or an array of token arrays. Optional fields configure the
1206
+ * embedding encoding format, requested dimensions, and user identifier.
1207
+ *
1208
+ * **Gotchas**
1209
+ *
1210
+ * This schema validates the transport shape, but OpenAI still enforces
1211
+ * provider-side constraints such as non-empty input, integer token ids, input
1212
+ * size limits, positive dimensions, and model-specific dimension support.
1213
+ *
936
1214
  * @category schemas
937
1215
  * @since 4.0.0
938
1216
  */
@@ -960,6 +1238,24 @@ export type CreateEmbeddingRequest = typeof CreateEmbeddingRequest.Type
960
1238
  /**
961
1239
  * Schema for a successful response payload returned by the OpenAI embeddings endpoint.
962
1240
  *
1241
+ * **When to use**
1242
+ *
1243
+ * Use to decode successful OpenAI embeddings responses.
1244
+ *
1245
+ * **Details**
1246
+ *
1247
+ * The response contains an array of `Embedding` items, the model name, an
1248
+ * optional `object: "list"` marker, and optional token usage counts for prompt
1249
+ * and total tokens.
1250
+ *
1251
+ * **Gotchas**
1252
+ *
1253
+ * Each `Embedding` may contain either a numeric vector or a string embedding.
1254
+ * Callers that require numeric vectors must account for string embeddings.
1255
+ *
1256
+ * @see {@link CreateEmbeddingRequest} for the request schema sent to the embeddings endpoint
1257
+ * @see {@link Embedding} for individual embedding items in the response
1258
+ *
963
1259
  * @category schemas
964
1260
  * @since 4.0.0
965
1261
  */
@@ -978,6 +1274,15 @@ export const CreateEmbeddingResponse = Schema.Struct({
978
1274
  /**
979
1275
  * Successful response payload returned by the OpenAI embeddings endpoint.
980
1276
  *
1277
+ * **When to use**
1278
+ *
1279
+ * Use when typing successful OpenAI embeddings responses.
1280
+ *
1281
+ * **Details**
1282
+ *
1283
+ * Contains embedding items, the model name, optional list marker, and optional
1284
+ * token usage counts.
1285
+ *
981
1286
  * @category models
982
1287
  * @since 4.0.0
983
1288
  */
@@ -1,9 +1,26 @@
1
1
  /**
2
- * OpenAI telemetry attributes for OpenTelemetry integration.
2
+ * OpenAI-specific telemetry annotations for GenAI spans.
3
3
  *
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.
4
+ * This module extends the provider-neutral GenAI telemetry model with
5
+ * attributes that only exist on OpenAI requests and responses. Use
6
+ * {@link addGenAIAnnotations} when an OpenAI operation already has an
7
+ * OpenTelemetry span and you want to record both standard GenAI metadata and
8
+ * OpenAI details such as response format, requested service tier, actual
9
+ * service tier, or system fingerprint.
10
+ *
11
+ * **Mental model**
12
+ *
13
+ * The public option shape stays idiomatic TypeScript (`responseFormat`,
14
+ * `serviceTier`, `systemFingerprint`). When annotations are applied, the
15
+ * attributes are written to the span under OpenTelemetry semantic-convention
16
+ * keys such as `gen_ai.openai.request.response_format` and
17
+ * `gen_ai.openai.response.system_fingerprint`.
18
+ *
19
+ * **Gotchas**
20
+ *
21
+ * Annotation mutates the provided span in place. It does not create, end, or
22
+ * export spans, and OpenAI-specific attributes are only added when the
23
+ * `openai.request` or `openai.response` option objects are present.
7
24
  *
8
25
  * @since 4.0.0
9
26
  */
@@ -17,7 +34,11 @@ import * as Telemetry from "effect/unstable/ai/Telemetry"
17
34
  * The attributes used to describe telemetry in the context of Generative
18
35
  * Artificial Intelligence (GenAI) Models requests and responses.
19
36
  *
20
- * @see https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/
37
+ * **Details**
38
+ *
39
+ * These attributes follow the OpenTelemetry generative AI semantic
40
+ * conventions:
41
+ * https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/
21
42
  *
22
43
  * @category models
23
44
  * @since 4.0.0
@@ -127,10 +148,18 @@ const addOpenAiResponseAttributes = Telemetry.addSpanAttributes("gen_ai.openai.r
127
148
  * Applies the specified OpenAi GenAI telemetry attributes to the provided
128
149
  * `Span`.
129
150
  *
151
+ * **When to use**
152
+ *
153
+ * Use to annotate an existing OpenTelemetry span with standard GenAI attributes
154
+ * plus OpenAI-specific request and response metadata.
155
+ *
130
156
  * **Gotchas**
131
157
  *
132
158
  * This method will mutate the `Span` **in-place**.
133
159
  *
160
+ * @see {@link OpenAiTelemetryAttributeOptions} for the accepted telemetry attributes
161
+ * @see {@link Telemetry.addGenAIAnnotations} for the provider-neutral annotation helper
162
+ *
134
163
  * @category tracing
135
164
  * @since 4.0.0
136
165
  */
@@ -139,10 +168,18 @@ export const addGenAIAnnotations: {
139
168
  * Applies the specified OpenAi GenAI telemetry attributes to the provided
140
169
  * `Span`.
141
170
  *
171
+ * **When to use**
172
+ *
173
+ * Use to annotate an existing OpenTelemetry span with standard GenAI attributes
174
+ * plus OpenAI-specific request and response metadata.
175
+ *
142
176
  * **Gotchas**
143
177
  *
144
178
  * This method will mutate the `Span` **in-place**.
145
179
  *
180
+ * @see {@link OpenAiTelemetryAttributeOptions} for the accepted telemetry attributes
181
+ * @see {@link Telemetry.addGenAIAnnotations} for the provider-neutral annotation helper
182
+ *
146
183
  * @category tracing
147
184
  * @since 4.0.0
148
185
  */
@@ -151,10 +188,18 @@ export const addGenAIAnnotations: {
151
188
  * Applies the specified OpenAi GenAI telemetry attributes to the provided
152
189
  * `Span`.
153
190
  *
191
+ * **When to use**
192
+ *
193
+ * Use to annotate an existing OpenTelemetry span with standard GenAI attributes
194
+ * plus OpenAI-specific request and response metadata.
195
+ *
154
196
  * **Gotchas**
155
197
  *
156
198
  * This method will mutate the `Span` **in-place**.
157
199
  *
200
+ * @see {@link OpenAiTelemetryAttributeOptions} for the accepted telemetry attributes
201
+ * @see {@link Telemetry.addGenAIAnnotations} for the provider-neutral annotation helper
202
+ *
158
203
  * @category tracing
159
204
  * @since 4.0.0
160
205
  */