@effect/ai-openai-compat 4.0.0-beta.67 → 4.0.0-beta.68

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,7 +77,7 @@ export interface Service {
77
77
  * Context service tag for accessing an OpenAI-compatible client from the
78
78
  * Effect context.
79
79
  *
80
- * @category service
80
+ * @category services
81
81
  * @since 4.0.0
82
82
  */
83
83
  export class OpenAiClient extends Context.Service<OpenAiClient, Service>()(
@@ -302,6 +302,7 @@ type JsonObject = { readonly [x: string]: Schema.Json }
302
302
  /**
303
303
  * Optional response fields that can be requested with the `include` parameter.
304
304
  *
305
+ * @category response
305
306
  * @since 4.0.0
306
307
  */
307
308
  export type IncludeEnum =
@@ -312,6 +313,7 @@ export type IncludeEnum =
312
313
  /**
313
314
  * Lifecycle status shared by message, reasoning, and tool-call items.
314
315
  *
316
+ * @category models
315
317
  * @since 4.0.0
316
318
  */
317
319
  export type MessageStatus = "in_progress" | "completed" | "incomplete"
@@ -339,6 +341,7 @@ type InputFileContent = {
339
341
  /**
340
342
  * Content blocks accepted in input messages.
341
343
  *
344
+ * @category request
342
345
  * @since 4.0.0
343
346
  */
344
347
  export type InputContent = InputTextContent | InputImageContent | InputFileContent
@@ -346,6 +349,7 @@ export type InputContent = InputTextContent | InputImageContent | InputFileConte
346
349
  /**
347
350
  * Text content block used for model-provided reasoning summaries.
348
351
  *
352
+ * @category response
349
353
  * @since 4.0.0
350
354
  */
351
355
  export type SummaryTextContent = {
@@ -407,6 +411,7 @@ type FilePathAnnotation = {
407
411
  /**
408
412
  * Citation and file-path annotations attached to output text content.
409
413
  *
414
+ * @category response
410
415
  * @since 4.0.0
411
416
  */
412
417
  export type Annotation =
@@ -445,6 +450,7 @@ type OutputMessage = {
445
450
  * Reasoning output item containing encrypted reasoning content, summaries, and
446
451
  * optional reasoning text.
447
452
  *
453
+ * @category response
448
454
  * @since 4.0.0
449
455
  */
450
456
  export type ReasoningItem = {
@@ -499,6 +505,7 @@ type ItemReference = {
499
505
  * Supports input messages, output messages, tool calls, tool outputs, reasoning
500
506
  * items, custom tool interactions, and item references.
501
507
  *
508
+ * @category request
502
509
  * @since 4.0.0
503
510
  */
504
511
  export type InputItem =
@@ -539,6 +546,7 @@ type CustomToolParam = {
539
546
  /**
540
547
  * Tool definitions that can be supplied to a Responses-style request.
541
548
  *
549
+ * @category request
542
550
  * @since 4.0.0
543
551
  */
544
552
  export type Tool =
@@ -567,6 +575,7 @@ type ToolChoice =
567
575
  * Text output format configuration for plain text, JSON object, or JSON Schema
568
576
  * responses.
569
577
  *
578
+ * @category configuration
570
579
  * @since 4.0.0
571
580
  */
572
581
  export type TextResponseFormatConfiguration =
@@ -588,6 +597,7 @@ export type TextResponseFormatConfiguration =
588
597
  * Request options for creating a Responses-style response with an
589
598
  * OpenAI-compatible provider.
590
599
  *
600
+ * @category request
591
601
  * @since 4.0.0
592
602
  */
593
603
  export type CreateResponse = {
@@ -627,6 +637,7 @@ export type CreateResponse = {
627
637
  /**
628
638
  * Token accounting reported on Responses-style response objects.
629
639
  *
640
+ * @category response
630
641
  * @since 4.0.0
631
642
  */
632
643
  export type ResponseUsage = {
@@ -647,6 +658,7 @@ type OutputItem =
647
658
  * Responses-style response object returned by compatible providers or embedded
648
659
  * in response stream lifecycle events.
649
660
  *
661
+ * @category response
650
662
  * @since 4.0.0
651
663
  */
652
664
  export type Response = {
@@ -775,6 +787,7 @@ type UnknownResponseStreamEvent = {
775
787
  /**
776
788
  * Server-sent event shapes emitted by Responses-style response streams.
777
789
  *
790
+ * @category streaming
778
791
  * @since 4.0.0
779
792
  */
780
793
  export type ResponseStreamEvent =
@@ -802,6 +815,7 @@ export type ResponseStreamEvent =
802
815
  * string. The `index` field identifies the input item that produced this
803
816
  * embedding.
804
817
  *
818
+ * @category response
805
819
  * @since 4.0.0
806
820
  */
807
821
  export type Embedding = {
@@ -813,6 +827,7 @@ export type Embedding = {
813
827
  /**
814
828
  * Request payload for the embeddings endpoint.
815
829
  *
830
+ * @category request
816
831
  * @since 4.0.0
817
832
  */
818
833
  export type CreateEmbeddingRequest = {
@@ -826,6 +841,7 @@ export type CreateEmbeddingRequest = {
826
841
  /**
827
842
  * Successful response payload returned by the embeddings endpoint.
828
843
  *
844
+ * @category response
829
845
  * @since 4.0.0
830
846
  */
831
847
  export type CreateEmbeddingResponse = {
@@ -841,18 +857,21 @@ export type CreateEmbeddingResponse = {
841
857
  /**
842
858
  * JSON request body accepted by the embeddings endpoint.
843
859
  *
860
+ * @category request
844
861
  * @since 4.0.0
845
862
  */
846
863
  export type CreateEmbeddingRequestJson = CreateEmbeddingRequest
847
864
  /**
848
865
  * Decoded successful embeddings response body.
849
866
  *
867
+ * @category response
850
868
  * @since 4.0.0
851
869
  */
852
870
  export type CreateEmbedding200 = CreateEmbeddingResponse
853
871
  /**
854
872
  * Structured content parts accepted in chat completion messages.
855
873
  *
874
+ * @category request
856
875
  * @since 4.0.0
857
876
  */
858
877
  export type ChatCompletionContentPart =
@@ -870,6 +889,7 @@ export type ChatCompletionContentPart =
870
889
  /**
871
890
  * Tool call data attached to an assistant chat completion message.
872
891
  *
892
+ * @category request
873
893
  * @since 4.0.0
874
894
  */
875
895
  export type ChatCompletionRequestToolCall = {
@@ -883,6 +903,7 @@ export type ChatCompletionRequestToolCall = {
883
903
  /**
884
904
  * Message shapes accepted by the chat completions endpoint.
885
905
  *
906
+ * @category request
886
907
  * @since 4.0.0
887
908
  */
888
909
  export type ChatCompletionRequestMessage =
@@ -899,6 +920,7 @@ export type ChatCompletionRequestMessage =
899
920
  /**
900
921
  * Function tool definition accepted by the chat completions endpoint.
901
922
  *
923
+ * @category request
902
924
  * @since 4.0.0
903
925
  */
904
926
  export type ChatCompletionTool = {
@@ -913,6 +935,7 @@ export type ChatCompletionTool = {
913
935
  /**
914
936
  * Controls whether the model may call tools and can force a specific function.
915
937
  *
938
+ * @category configuration
916
939
  * @since 4.0.0
917
940
  */
918
941
  export type ChatCompletionToolChoice =
@@ -928,6 +951,7 @@ export type ChatCompletionToolChoice =
928
951
  /**
929
952
  * JSON response format configuration for chat completion requests.
930
953
  *
954
+ * @category configuration
931
955
  * @since 4.0.0
932
956
  */
933
957
  export type ChatCompletionResponseFormat =
@@ -946,6 +970,7 @@ export type ChatCompletionResponseFormat =
946
970
  /**
947
971
  * Request payload for the OpenAI-compatible chat completions endpoint.
948
972
  *
973
+ * @category request
949
974
  * @since 4.0.0
950
975
  */
951
976
  export type ChatCompletionRequest = {
@@ -971,18 +996,21 @@ export type ChatCompletionRequest = {
971
996
  /**
972
997
  * JSON request body used by this client when creating a chat completion response.
973
998
  *
999
+ * @category request
974
1000
  * @since 4.0.0
975
1001
  */
976
1002
  export type CreateResponseRequestJson = ChatCompletionRequest
977
1003
  /**
978
1004
  * Decoded successful chat completion response body returned by `createResponse`.
979
1005
  *
1006
+ * @category response
980
1007
  * @since 4.0.0
981
1008
  */
982
1009
  export type CreateResponse200 = ChatCompletionResponse
983
1010
  /**
984
1011
  * Decoded server-sent event payload emitted by `createResponseStream`.
985
1012
  *
1013
+ * @category streaming
986
1014
  * @since 4.0.0
987
1015
  */
988
1016
  export type CreateResponse200Sse = ChatCompletionStreamEvent
@@ -1075,36 +1103,42 @@ const ChatCompletionChunk = Schema.Struct({
1075
1103
  /**
1076
1104
  * Decoded tool-call object from a chat completion response or streaming chunk.
1077
1105
  *
1106
+ * @category response
1078
1107
  * @since 4.0.0
1079
1108
  */
1080
1109
  export type ChatCompletionToolCall = typeof ChatCompletionToolCall.Type
1081
1110
  /**
1082
1111
  * Decoded message object from a non-streaming chat completion choice.
1083
1112
  *
1113
+ * @category response
1084
1114
  * @since 4.0.0
1085
1115
  */
1086
1116
  export type ChatCompletionMessage = typeof ChatCompletionMessage.Type
1087
1117
  /**
1088
1118
  * Decoded choice object returned by chat completion responses and chunks.
1089
1119
  *
1120
+ * @category response
1090
1121
  * @since 4.0.0
1091
1122
  */
1092
1123
  export type ChatCompletionChoice = typeof ChatCompletionChoice.Type
1093
1124
  /**
1094
1125
  * Decoded token usage summary returned by chat completions.
1095
1126
  *
1127
+ * @category response
1096
1128
  * @since 4.0.0
1097
1129
  */
1098
1130
  export type ChatCompletionUsage = typeof ChatCompletionUsage.Type
1099
1131
  /**
1100
1132
  * Decoded successful response from the chat completions endpoint.
1101
1133
  *
1134
+ * @category response
1102
1135
  * @since 4.0.0
1103
1136
  */
1104
1137
  export type ChatCompletionResponse = typeof ChatCompletionResponse.Type
1105
1138
  /**
1106
1139
  * Decoded streaming chunk emitted by the chat completions endpoint.
1107
1140
  *
1141
+ * @category streaming
1108
1142
  * @since 4.0.0
1109
1143
  */
1110
1144
  export type ChatCompletionChunk = typeof ChatCompletionChunk.Type
@@ -1112,6 +1146,7 @@ export type ChatCompletionChunk = typeof ChatCompletionChunk.Type
1112
1146
  * Streaming chat completion event, including decoded chunks and the `[DONE]`
1113
1147
  * sentinel.
1114
1148
  *
1149
+ * @category streaming
1115
1150
  * @since 4.0.0
1116
1151
  */
1117
1152
  export type ChatCompletionStreamEvent = ChatCompletionChunk | "[DONE]"
@@ -59,7 +59,7 @@ export declare namespace OpenAiConfig {
59
59
  * resolve the underlying HTTP client.
60
60
  *
61
61
  * @category models
62
- * @since 1.0.
62
+ * @since 4.0.0
63
63
  */
64
64
  export interface Service {
65
65
  readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined
@@ -114,6 +114,9 @@ export class Config extends Context.Service<
114
114
  declare module "effect/unstable/ai/Prompt" {
115
115
  /**
116
116
  * OpenAI-compatible options for file prompt parts.
117
+ *
118
+ * @category request
119
+ * @since 4.0.0
117
120
  */
118
121
  export interface FilePartOptions extends ProviderOptions {
119
122
  /**
@@ -129,6 +132,9 @@ declare module "effect/unstable/ai/Prompt" {
129
132
 
130
133
  /**
131
134
  * OpenAI-compatible options for reasoning prompt parts.
135
+ *
136
+ * @category request
137
+ * @since 4.0.0
132
138
  */
133
139
  export interface ReasoningPartOptions extends ProviderOptions {
134
140
  /**
@@ -150,6 +156,9 @@ declare module "effect/unstable/ai/Prompt" {
150
156
 
151
157
  /**
152
158
  * OpenAI-compatible options for assistant tool-call prompt parts.
159
+ *
160
+ * @category request
161
+ * @since 4.0.0
153
162
  */
154
163
  export interface ToolCallPartOptions extends ProviderOptions {
155
164
  /**
@@ -169,6 +178,9 @@ declare module "effect/unstable/ai/Prompt" {
169
178
 
170
179
  /**
171
180
  * OpenAI-compatible options for tool-result prompt parts.
181
+ *
182
+ * @category request
183
+ * @since 4.0.0
172
184
  */
173
185
  export interface ToolResultPartOptions extends ProviderOptions {
174
186
  /**
@@ -188,6 +200,9 @@ declare module "effect/unstable/ai/Prompt" {
188
200
 
189
201
  /**
190
202
  * OpenAI-compatible options for text prompt parts.
203
+ *
204
+ * @category request
205
+ * @since 4.0.0
191
206
  */
192
207
  export interface TextPartOptions extends ProviderOptions {
193
208
  /**
@@ -213,6 +228,9 @@ declare module "effect/unstable/ai/Prompt" {
213
228
  declare module "effect/unstable/ai/Response" {
214
229
  /**
215
230
  * OpenAI-compatible metadata attached to a complete text response part.
231
+ *
232
+ * @category response
233
+ * @since 4.0.0
216
234
  */
217
235
  export interface TextPartMetadata extends ProviderMetadata {
218
236
  /**
@@ -242,6 +260,9 @@ declare module "effect/unstable/ai/Response" {
242
260
 
243
261
  /**
244
262
  * OpenAI-compatible metadata emitted when a streamed text part starts.
263
+ *
264
+ * @category response
265
+ * @since 4.0.0
245
266
  */
246
267
  export interface TextStartPartMetadata extends ProviderMetadata {
247
268
  /**
@@ -257,6 +278,9 @@ declare module "effect/unstable/ai/Response" {
257
278
 
258
279
  /**
259
280
  * OpenAI-compatible metadata emitted when a streamed text part ends.
281
+ *
282
+ * @category response
283
+ * @since 4.0.0
260
284
  */
261
285
  export interface TextEndPartMetadata extends ProviderMetadata {
262
286
  /**
@@ -276,6 +300,9 @@ declare module "effect/unstable/ai/Response" {
276
300
 
277
301
  /**
278
302
  * OpenAI-compatible metadata attached to a complete reasoning response part.
303
+ *
304
+ * @category response
305
+ * @since 4.0.0
279
306
  */
280
307
  export interface ReasoningPartMetadata extends ProviderMetadata {
281
308
  /**
@@ -295,6 +322,9 @@ declare module "effect/unstable/ai/Response" {
295
322
 
296
323
  /**
297
324
  * OpenAI-compatible metadata emitted when a streamed reasoning part starts.
325
+ *
326
+ * @category response
327
+ * @since 4.0.0
298
328
  */
299
329
  export interface ReasoningStartPartMetadata extends ProviderMetadata {
300
330
  /**
@@ -314,6 +344,9 @@ declare module "effect/unstable/ai/Response" {
314
344
 
315
345
  /**
316
346
  * OpenAI-compatible metadata emitted for a streamed reasoning delta.
347
+ *
348
+ * @category response
349
+ * @since 4.0.0
317
350
  */
318
351
  export interface ReasoningDeltaPartMetadata extends ProviderMetadata {
319
352
  /**
@@ -329,6 +362,9 @@ declare module "effect/unstable/ai/Response" {
329
362
 
330
363
  /**
331
364
  * OpenAI-compatible metadata emitted when a streamed reasoning part ends.
365
+ *
366
+ * @category response
367
+ * @since 4.0.0
332
368
  */
333
369
  export interface ReasoningEndPartMetadata extends ProviderMetadata {
334
370
  /**
@@ -348,6 +384,9 @@ declare module "effect/unstable/ai/Response" {
348
384
 
349
385
  /**
350
386
  * OpenAI-compatible metadata attached to tool-call response parts.
387
+ *
388
+ * @category response
389
+ * @since 4.0.0
351
390
  */
352
391
  export interface ToolCallPartMetadata extends ProviderMetadata {
353
392
  /**
@@ -363,6 +402,9 @@ declare module "effect/unstable/ai/Response" {
363
402
 
364
403
  /**
365
404
  * OpenAI-compatible metadata attached to document source citations.
405
+ *
406
+ * @category response
407
+ * @since 4.0.0
366
408
  */
367
409
  export interface DocumentSourcePartMetadata extends ProviderMetadata {
368
410
  /**
@@ -416,6 +458,9 @@ declare module "effect/unstable/ai/Response" {
416
458
 
417
459
  /**
418
460
  * OpenAI-compatible metadata attached to URL source citations.
461
+ *
462
+ * @category response
463
+ * @since 4.0.0
419
464
  */
420
465
  export interface UrlSourcePartMetadata extends ProviderMetadata {
421
466
  /**
@@ -439,6 +484,9 @@ declare module "effect/unstable/ai/Response" {
439
484
 
440
485
  /**
441
486
  * OpenAI-compatible metadata attached to finish response parts.
487
+ *
488
+ * @category response
489
+ * @since 4.0.0
442
490
  */
443
491
  export interface FinishPartMetadata extends ProviderMetadata {
444
492
  /**
@@ -102,8 +102,8 @@ export type WellKnownServiceTier = "auto" | "default"
102
102
  * Options accepted by `addGenAIAnnotations`, combining standard GenAI telemetry
103
103
  * attributes with optional OpenAI-compatible request and response attributes.
104
104
  *
105
+ * @category models
105
106
  * @since 4.0.0
106
- * @since models
107
107
  */
108
108
  export type OpenAiTelemetryAttributeOptions = Telemetry.GenAITelemetryAttributeOptions & {
109
109
  openai?: {
@@ -125,8 +125,8 @@ const addOpenAiResponseAttributes = Telemetry.addSpanAttributes("gen_ai.openai.r
125
125
  *
126
126
  * **NOTE**: This method will mutate the `Span` **in-place**.
127
127
  *
128
+ * @category tracing
128
129
  * @since 4.0.0
129
- * @since utilities
130
130
  */
131
131
  export const addGenAIAnnotations: {
132
132
  /**
@@ -135,8 +135,8 @@ export const addGenAIAnnotations: {
135
135
  *
136
136
  * **NOTE**: This method will mutate the `Span` **in-place**.
137
137
  *
138
+ * @category tracing
138
139
  * @since 4.0.0
139
- * @since utilities
140
140
  */
141
141
  (options: OpenAiTelemetryAttributeOptions): (span: Span) => void
142
142
  /**
@@ -145,8 +145,8 @@ export const addGenAIAnnotations: {
145
145
  *
146
146
  * **NOTE**: This method will mutate the `Span` **in-place**.
147
147
  *
148
+ * @category tracing
148
149
  * @since 4.0.0
149
- * @since utilities
150
150
  */
151
151
  (span: Span, options: OpenAiTelemetryAttributeOptions): void
152
152
  } = dual(2, (span: Span, options: OpenAiTelemetryAttributeOptions) => {
package/src/index.ts CHANGED
@@ -5,11 +5,54 @@
5
5
  // @barrel: Auto-generated exports. Do not edit manually.
6
6
 
7
7
  /**
8
+ * The `OpenAiClient` module provides an Effect service for calling
9
+ * OpenAI-compatible chat completions and embeddings APIs. It builds on the
10
+ * Effect HTTP client, adds authentication and OpenAI header handling, and
11
+ * exposes typed helpers for regular responses, server-sent event streaming, and
12
+ * embedding requests.
13
+ *
14
+ * **Common tasks**
15
+ *
16
+ * - Create a client service directly with {@link make}
17
+ * - Provide the service as a layer with {@link layer} or {@link layerConfig}
18
+ * - Send non-streaming chat completion requests with `createResponse`
19
+ * - Send streaming chat completion requests with `createResponseStream`
20
+ * - Generate embeddings with `createEmbedding`
21
+ * - Reuse the exported request and response types when integrating compatible providers
22
+ *
23
+ * **Gotchas**
24
+ *
25
+ * - The default base URL is `https://api.openai.com/v1`; set `apiUrl` for other
26
+ * OpenAI-compatible providers.
27
+ * - `createResponseStream` forces `stream: true` and requests usage events with
28
+ * `stream_options.include_usage`.
29
+ * - HTTP and schema decoding failures are mapped into `AiError`.
30
+ *
8
31
  * @since 4.0.0
9
32
  */
10
33
  export * as OpenAiClient from "./OpenAiClient.ts"
11
34
 
12
35
  /**
36
+ * The `OpenAiConfig` module provides shared configuration for clients that
37
+ * talk to OpenAI-compatible APIs. It is used to customize the HTTP client
38
+ * wiring around a provider without changing the higher-level model,
39
+ * embeddings, or tool-calling APIs that consume the client.
40
+ *
41
+ * **Common tasks**
42
+ *
43
+ * - Install a client transform with {@link withClientTransform}
44
+ * - Add provider-specific HTTP behavior, such as headers, retries, proxies, or
45
+ * instrumentation
46
+ * - Read the active configuration from the Effect context when implementing
47
+ * OpenAI-compatible integrations
48
+ *
49
+ * **Gotchas**
50
+ *
51
+ * - The transform receives and returns an `HttpClient`, so it should preserve
52
+ * the existing client behavior unless it intentionally replaces it
53
+ * - Configuration is provided through Effect context and is scoped to the
54
+ * effect that receives the service
55
+ *
13
56
  * @since 4.0.0
14
57
  */
15
58
  export * as OpenAiConfig from "./OpenAiConfig.ts"
@@ -24,6 +67,19 @@ export * as OpenAiConfig from "./OpenAiConfig.ts"
24
67
  export * as OpenAiEmbeddingModel from "./OpenAiEmbeddingModel.ts"
25
68
 
26
69
  /**
70
+ * The `OpenAiError` module defines OpenAI-specific metadata that can be
71
+ * attached to the shared `AiError` error types used by the AI packages. It is
72
+ * primarily used by OpenAI-compatible clients to preserve provider details
73
+ * such as error codes, error types, request IDs, and rate limit headers while
74
+ * still exposing errors through the provider-neutral Effect AI error model.
75
+ *
76
+ * Use this module when mapping OpenAI API failures into `AiError` values and
77
+ * when consumers need enough structured metadata to debug failed requests,
78
+ * inspect quota or rate limit responses, or correlate an error with OpenAI
79
+ * support. The exported types are metadata shapes only; the module augmentation
80
+ * makes those shapes available on the corresponding shared AI error metadata
81
+ * interfaces without defining new runtime error classes.
82
+ *
27
83
  * @since 4.0.0
28
84
  */
29
85
  export * as OpenAiError from "./OpenAiError.ts"