@effect/ai-openai 4.0.0-beta.9 → 4.0.0-beta.91

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 (61) hide show
  1. package/dist/Generated.d.ts +66675 -37672
  2. package/dist/Generated.d.ts.map +1 -1
  3. package/dist/Generated.js +1 -1
  4. package/dist/Generated.js.map +1 -1
  5. package/dist/OpenAiClient.d.ts +170 -29
  6. package/dist/OpenAiClient.d.ts.map +1 -1
  7. package/dist/OpenAiClient.js +321 -46
  8. package/dist/OpenAiClient.js.map +1 -1
  9. package/dist/OpenAiClientGenerated.d.ts +91 -0
  10. package/dist/OpenAiClientGenerated.d.ts.map +1 -0
  11. package/dist/OpenAiClientGenerated.js +84 -0
  12. package/dist/OpenAiClientGenerated.js.map +1 -0
  13. package/dist/OpenAiConfig.d.ts +88 -10
  14. package/dist/OpenAiConfig.d.ts.map +1 -1
  15. package/dist/OpenAiConfig.js +42 -7
  16. package/dist/OpenAiConfig.js.map +1 -1
  17. package/dist/OpenAiEmbeddingModel.d.ts +188 -0
  18. package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
  19. package/dist/OpenAiEmbeddingModel.js +194 -0
  20. package/dist/OpenAiEmbeddingModel.js.map +1 -0
  21. package/dist/OpenAiError.d.ts +168 -35
  22. package/dist/OpenAiError.d.ts.map +1 -1
  23. package/dist/OpenAiError.js +1 -1
  24. package/dist/OpenAiLanguageModel.d.ts +357 -63
  25. package/dist/OpenAiLanguageModel.d.ts.map +1 -1
  26. package/dist/OpenAiLanguageModel.js +390 -168
  27. package/dist/OpenAiLanguageModel.js.map +1 -1
  28. package/dist/OpenAiSchema.d.ts +2325 -0
  29. package/dist/OpenAiSchema.d.ts.map +1 -0
  30. package/dist/OpenAiSchema.js +811 -0
  31. package/dist/OpenAiSchema.js.map +1 -0
  32. package/dist/OpenAiTelemetry.d.ts +63 -22
  33. package/dist/OpenAiTelemetry.d.ts.map +1 -1
  34. package/dist/OpenAiTelemetry.js +20 -10
  35. package/dist/OpenAiTelemetry.js.map +1 -1
  36. package/dist/OpenAiTool.d.ts +157 -67
  37. package/dist/OpenAiTool.d.ts.map +1 -1
  38. package/dist/OpenAiTool.js +125 -39
  39. package/dist/OpenAiTool.js.map +1 -1
  40. package/dist/index.d.ts +19 -33
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +19 -33
  43. package/dist/index.js.map +1 -1
  44. package/dist/internal/errors.js +4 -4
  45. package/dist/internal/errors.js.map +1 -1
  46. package/dist/internal/utilities.js +0 -4
  47. package/dist/internal/utilities.js.map +1 -1
  48. package/package.json +3 -3
  49. package/src/Generated.ts +9720 -4890
  50. package/src/OpenAiClient.ts +499 -98
  51. package/src/OpenAiClientGenerated.ts +202 -0
  52. package/src/OpenAiConfig.ts +89 -11
  53. package/src/OpenAiEmbeddingModel.ts +332 -0
  54. package/src/OpenAiError.ts +170 -35
  55. package/src/OpenAiLanguageModel.ts +776 -169
  56. package/src/OpenAiSchema.ts +1286 -0
  57. package/src/OpenAiTelemetry.ts +69 -28
  58. package/src/OpenAiTool.ts +126 -40
  59. package/src/index.ts +22 -33
  60. package/src/internal/errors.ts +6 -4
  61. package/src/internal/utilities.ts +0 -6
@@ -0,0 +1,1286 @@
1
+ /**
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
+ * @since 4.0.0
8
+ */
9
+ import * as Effect from "effect/Effect"
10
+ import * as Predicate from "effect/Predicate"
11
+ import * as Schema from "effect/Schema"
12
+
13
+ const UnknownRecord = Schema.Record(Schema.String, Schema.Unknown)
14
+
15
+ const JsonObject = Schema.Record(Schema.String, Schema.Unknown)
16
+
17
+ const MessageRole = Schema.Literals(["system", "developer", "user", "assistant"])
18
+
19
+ const ImageDetail = Schema.Literals(["low", "high", "auto"])
20
+
21
+ /**
22
+ * Schema for optional `include` values supported by the local handwritten
23
+ * Responses client schema.
24
+ *
25
+ * **Details**
26
+ *
27
+ * These values request additional response fields such as image URLs, encrypted
28
+ * reasoning content, output logprobs, code interpreter outputs, or web search
29
+ * sources. This schema enumerates the include values supported by this client
30
+ * path.
31
+ *
32
+ * @category schemas
33
+ * @since 4.0.0
34
+ */
35
+ export const IncludeEnum = Schema.Literals([
36
+ "message.input_image.image_url",
37
+ "reasoning.encrypted_content",
38
+ "message.output_text.logprobs",
39
+ "code_interpreter_call.outputs",
40
+ "web_search_call.action.sources"
41
+ ])
42
+
43
+ /**
44
+ * Type of optional `include` values accepted by OpenAI Responses requests.
45
+ *
46
+ * @category models
47
+ * @since 4.0.0
48
+ */
49
+ export type IncludeEnum = typeof IncludeEnum.Type
50
+
51
+ /**
52
+ * Schema for lifecycle statuses shared by messages, reasoning items, and tool calls.
53
+ *
54
+ * **Details**
55
+ *
56
+ * Accepted values are `"in_progress"`, `"completed"`, and `"incomplete"`.
57
+ * This item-level status is used by message, reasoning, and tool-call shapes.
58
+ *
59
+ * @category schemas
60
+ * @since 4.0.0
61
+ */
62
+ export const MessageStatus = Schema.Literals(["in_progress", "completed", "incomplete"])
63
+
64
+ /**
65
+ * Lifecycle status shared by messages, reasoning items, and tool calls.
66
+ *
67
+ * **Details**
68
+ *
69
+ * Accepted values are `"in_progress"`, `"completed"`, and `"incomplete"`.
70
+ *
71
+ * @category models
72
+ * @since 4.0.0
73
+ */
74
+ export type MessageStatus = typeof MessageStatus.Type
75
+
76
+ const InputTextContent = Schema.Struct({
77
+ type: Schema.Literal("input_text"),
78
+ text: Schema.String
79
+ })
80
+
81
+ const InputImageContent = Schema.Struct({
82
+ type: Schema.Literal("input_image"),
83
+ image_url: Schema.optionalKey(Schema.NullOr(Schema.String)),
84
+ file_id: Schema.optionalKey(Schema.NullOr(Schema.String)),
85
+ detail: Schema.optionalKey(Schema.NullOr(ImageDetail))
86
+ })
87
+
88
+ const InputFileContent = Schema.Struct({
89
+ type: Schema.Literal("input_file"),
90
+ file_id: Schema.optionalKey(Schema.NullOr(Schema.String)),
91
+ filename: Schema.optionalKey(Schema.String),
92
+ file_url: Schema.optionalKey(Schema.String),
93
+ file_data: Schema.optionalKey(Schema.String)
94
+ })
95
+
96
+ /**
97
+ * Schema for content blocks accepted in OpenAI Responses input messages.
98
+ *
99
+ * **Details**
100
+ *
101
+ * Accepted block variants are `input_text`, `input_image`, and `input_file`.
102
+ *
103
+ * @see {@link InputItem} for request input item shapes that can contain these content blocks
104
+ *
105
+ * @category schemas
106
+ * @since 4.0.0
107
+ */
108
+ export const InputContent = Schema.Union([
109
+ InputTextContent,
110
+ InputImageContent,
111
+ InputFileContent
112
+ ])
113
+
114
+ /**
115
+ * Content block accepted in OpenAI Responses input messages.
116
+ *
117
+ * **Details**
118
+ *
119
+ * Accepted block variants are `input_text`, `input_image`, and `input_file`.
120
+ *
121
+ * @category models
122
+ * @since 4.0.0
123
+ */
124
+ export type InputContent = typeof InputContent.Type
125
+
126
+ /**
127
+ * Schema for a text block containing a model-provided reasoning summary.
128
+ *
129
+ * **Details**
130
+ *
131
+ * The decoded shape is `type: "summary_text"` plus `text` containing the
132
+ * reasoning summary text.
133
+ *
134
+ * @see {@link ReasoningItem} for reasoning output items that contain summary text blocks
135
+ *
136
+ * @category schemas
137
+ * @since 4.0.0
138
+ */
139
+ export const SummaryTextContent = Schema.Struct({
140
+ type: Schema.Literal("summary_text"),
141
+ text: Schema.String
142
+ })
143
+
144
+ /**
145
+ * Text content block used for model-provided reasoning summaries.
146
+ *
147
+ * @category models
148
+ * @since 4.0.0
149
+ */
150
+ export type SummaryTextContent = typeof SummaryTextContent.Type
151
+
152
+ const ReasoningTextContent = Schema.Struct({
153
+ type: Schema.Literal("reasoning_text"),
154
+ text: Schema.String
155
+ })
156
+
157
+ const RefusalContent = Schema.Struct({
158
+ type: Schema.Literal("refusal"),
159
+ refusal: Schema.String
160
+ })
161
+
162
+ const TextContent = Schema.Struct({
163
+ type: Schema.Literal("text"),
164
+ text: Schema.String
165
+ })
166
+
167
+ const ComputerScreenshotContent = Schema.Struct({
168
+ type: Schema.Literal("computer_screenshot"),
169
+ image_url: Schema.NullOr(Schema.String),
170
+ file_id: Schema.NullOr(Schema.String)
171
+ })
172
+
173
+ const FileCitationAnnotation = Schema.Struct({
174
+ type: Schema.Literal("file_citation"),
175
+ file_id: Schema.String,
176
+ index: Schema.Number,
177
+ filename: Schema.String
178
+ })
179
+
180
+ const UrlCitationAnnotation = Schema.Struct({
181
+ type: Schema.Literal("url_citation"),
182
+ url: Schema.String,
183
+ start_index: Schema.Number,
184
+ end_index: Schema.Number,
185
+ title: Schema.String
186
+ })
187
+
188
+ const ContainerFileCitationAnnotation = Schema.Struct({
189
+ type: Schema.Literal("container_file_citation"),
190
+ container_id: Schema.String,
191
+ file_id: Schema.String,
192
+ start_index: Schema.Number,
193
+ end_index: Schema.Number,
194
+ filename: Schema.String
195
+ })
196
+
197
+ const FilePathAnnotation = Schema.Struct({
198
+ type: Schema.Literal("file_path"),
199
+ file_id: Schema.String,
200
+ index: Schema.Number
201
+ })
202
+
203
+ /**
204
+ * Schema for citation and file-path annotations attached to output text content.
205
+ *
206
+ * **Details**
207
+ *
208
+ * Accepts annotation objects discriminated by `type`: `file_citation`,
209
+ * `url_citation`, `container_file_citation`, or `file_path`.
210
+ *
211
+ * @category schemas
212
+ * @since 4.0.0
213
+ */
214
+ export const Annotation = Schema.Union([
215
+ FileCitationAnnotation,
216
+ UrlCitationAnnotation,
217
+ ContainerFileCitationAnnotation,
218
+ FilePathAnnotation
219
+ ])
220
+
221
+ /**
222
+ * Citation or file-path annotation attached to output text content.
223
+ *
224
+ * **Details**
225
+ *
226
+ * Accepted annotation variants are `file_citation`, `url_citation`,
227
+ * `container_file_citation`, and `file_path`.
228
+ *
229
+ * @category models
230
+ * @since 4.0.0
231
+ */
232
+ export type Annotation = typeof Annotation.Type
233
+
234
+ const OutputTextContent = Schema.Struct({
235
+ type: Schema.Literal("output_text"),
236
+ text: Schema.String,
237
+ annotations: Schema.Array(Annotation),
238
+ logprobs: Schema.optionalKey(Schema.Array(Schema.Unknown))
239
+ })
240
+
241
+ const OutputMessageContent = Schema.Union([
242
+ InputTextContent,
243
+ OutputTextContent,
244
+ TextContent,
245
+ SummaryTextContent,
246
+ ReasoningTextContent,
247
+ RefusalContent,
248
+ InputImageContent,
249
+ ComputerScreenshotContent,
250
+ InputFileContent
251
+ ])
252
+
253
+ const OutputMessage = Schema.Struct({
254
+ id: Schema.String,
255
+ type: Schema.Literal("message"),
256
+ role: Schema.Literal("assistant"),
257
+ content: Schema.Array(OutputMessageContent),
258
+ status: MessageStatus
259
+ })
260
+
261
+ /**
262
+ * Schema for a reasoning output item containing encrypted content, summaries, and optional reasoning text.
263
+ *
264
+ * **When to use**
265
+ *
266
+ * Use when decoding or encoding OpenAI Responses reasoning items that may be
267
+ * carried into later request input.
268
+ *
269
+ * **Details**
270
+ *
271
+ * Reasoning items represent model reasoning content. `summary` is required,
272
+ * while `content` and `status` are optional.
273
+ *
274
+ * **Gotchas**
275
+ *
276
+ * `encrypted_content` is populated only when `reasoning.encrypted_content` is
277
+ * requested through `include`.
278
+ *
279
+ * @see {@link InputItem} for request input items that can carry reasoning items
280
+ * @see {@link IncludeEnum} for requesting encrypted reasoning content
281
+ *
282
+ * @category schemas
283
+ * @since 4.0.0
284
+ */
285
+ export const ReasoningItem = Schema.Struct({
286
+ type: Schema.Literal("reasoning"),
287
+ id: Schema.String,
288
+ encrypted_content: Schema.optionalKey(Schema.NullOr(Schema.String)),
289
+ summary: Schema.Array(SummaryTextContent),
290
+ content: Schema.optionalKey(Schema.Array(ReasoningTextContent)),
291
+ status: Schema.optionalKey(MessageStatus)
292
+ })
293
+
294
+ /**
295
+ * Reasoning output item containing encrypted content, summaries, and optional reasoning text.
296
+ *
297
+ * **When to use**
298
+ *
299
+ * Use when typing OpenAI Responses reasoning items that may be carried into
300
+ * later request input.
301
+ *
302
+ * **Details**
303
+ *
304
+ * Reasoning items represent model reasoning content. `summary` is required,
305
+ * while `content` and `status` are optional.
306
+ *
307
+ * **Gotchas**
308
+ *
309
+ * `encrypted_content` is populated only when `reasoning.encrypted_content` is
310
+ * requested through `include`.
311
+ *
312
+ * @category models
313
+ * @since 4.0.0
314
+ */
315
+ export type ReasoningItem = typeof ReasoningItem.Type
316
+
317
+ const FunctionCall = Schema.Struct({
318
+ id: Schema.optionalKey(Schema.String),
319
+ type: Schema.Literal("function_call"),
320
+ call_id: Schema.String,
321
+ name: Schema.String,
322
+ arguments: Schema.String,
323
+ status: Schema.optionalKey(MessageStatus)
324
+ })
325
+
326
+ const FunctionCallOutput = Schema.Struct({
327
+ id: Schema.optionalKey(Schema.NullOr(Schema.String)),
328
+ type: Schema.Literal("function_call_output"),
329
+ call_id: Schema.String,
330
+ output: Schema.Union([
331
+ Schema.String,
332
+ Schema.Array(InputContent)
333
+ ]),
334
+ status: Schema.optionalKey(Schema.NullOr(MessageStatus))
335
+ })
336
+
337
+ const ItemReference = Schema.Struct({
338
+ type: Schema.Literal("item_reference"),
339
+ id: Schema.String
340
+ })
341
+
342
+ const LocalShellCall = Schema.Struct({
343
+ id: Schema.optionalKey(Schema.String),
344
+ type: Schema.Literal("local_shell_call"),
345
+ call_id: Schema.String,
346
+ action: Schema.Unknown,
347
+ status: Schema.optionalKey(MessageStatus)
348
+ })
349
+
350
+ const LocalShellCallOutput = Schema.Struct({
351
+ id: Schema.optionalKey(Schema.String),
352
+ type: Schema.Literal("local_shell_call_output"),
353
+ call_id: Schema.String,
354
+ output: Schema.Unknown,
355
+ status: Schema.optionalKey(MessageStatus)
356
+ })
357
+
358
+ const ShellCall = Schema.Struct({
359
+ id: Schema.optionalKey(Schema.String),
360
+ type: Schema.Literal("shell_call"),
361
+ call_id: Schema.String,
362
+ action: Schema.Unknown,
363
+ status: Schema.optionalKey(MessageStatus)
364
+ })
365
+
366
+ const ShellCallOutput = Schema.Struct({
367
+ id: Schema.optionalKey(Schema.String),
368
+ type: Schema.Literal("shell_call_output"),
369
+ call_id: Schema.String,
370
+ output: Schema.Unknown,
371
+ status: Schema.optionalKey(MessageStatus)
372
+ })
373
+
374
+ const ApplyPatchCallOutput = Schema.Struct({
375
+ id: Schema.optionalKey(Schema.String),
376
+ type: Schema.Literal("apply_patch_call_output"),
377
+ call_id: Schema.String,
378
+ status: Schema.optionalKey(MessageStatus),
379
+ output: Schema.optionalKey(Schema.Unknown)
380
+ })
381
+
382
+ const McpApprovalResponse = Schema.Struct({
383
+ type: Schema.Literal("mcp_approval_response"),
384
+ approval_request_id: Schema.String,
385
+ approve: Schema.Boolean
386
+ })
387
+
388
+ const RequestMessageItem = Schema.Struct({
389
+ type: Schema.optionalKey(Schema.Literal("message")),
390
+ role: MessageRole,
391
+ status: Schema.optionalKey(MessageStatus),
392
+ content: Schema.Union([
393
+ Schema.String,
394
+ Schema.Array(InputContent)
395
+ ])
396
+ })
397
+
398
+ /**
399
+ * Schema for item shapes accepted by an OpenAI Responses request `input` field.
400
+ *
401
+ * **When to use**
402
+ *
403
+ * Use when validating structured `CreateResponse.input` array items.
404
+ *
405
+ * **Details**
406
+ *
407
+ * Accepted item families include request/output messages, function call and
408
+ * function call output, reasoning items, item references, shell and local shell
409
+ * calls and outputs, apply-patch output, and MCP approval responses.
410
+ *
411
+ * @see {@link CreateResponse} for the request schema that consumes input items
412
+ * @see {@link InputContent} for content blocks inside message items
413
+ *
414
+ * @category schemas
415
+ * @since 4.0.0
416
+ */
417
+ export const InputItem = Schema.Union([
418
+ RequestMessageItem,
419
+ OutputMessage,
420
+ FunctionCall,
421
+ FunctionCallOutput,
422
+ ReasoningItem,
423
+ ItemReference,
424
+ LocalShellCall,
425
+ LocalShellCallOutput,
426
+ ShellCall,
427
+ ShellCallOutput,
428
+ ApplyPatchCallOutput,
429
+ McpApprovalResponse
430
+ ])
431
+
432
+ /**
433
+ * Item shape accepted by an OpenAI Responses request `input` field.
434
+ *
435
+ * **When to use**
436
+ *
437
+ * Use when typing structured `CreateResponse.input` array items.
438
+ *
439
+ * **Details**
440
+ *
441
+ * Accepted item families include request/output messages, function call and
442
+ * function call output, reasoning items, item references, shell and local shell
443
+ * calls and outputs, apply-patch output, and MCP approval responses.
444
+ *
445
+ * @category models
446
+ * @since 4.0.0
447
+ */
448
+ export type InputItem = typeof InputItem.Type
449
+
450
+ const FunctionTool = Schema.Struct({
451
+ type: Schema.Literal("function"),
452
+ name: Schema.String,
453
+ description: Schema.optionalKey(Schema.NullOr(Schema.String)),
454
+ parameters: Schema.optionalKey(Schema.NullOr(JsonObject)),
455
+ strict: Schema.optionalKey(Schema.NullOr(Schema.Boolean))
456
+ })
457
+
458
+ const CustomTool = Schema.Struct({
459
+ type: Schema.Literal("custom"),
460
+ name: Schema.String,
461
+ description: Schema.optionalKey(Schema.String),
462
+ format: Schema.optionalKey(Schema.Unknown)
463
+ })
464
+
465
+ const ProviderDefinedTool = Schema.StructWithRest(
466
+ Schema.Struct({
467
+ type: Schema.Literals([
468
+ "apply_patch",
469
+ "code_interpreter",
470
+ "file_search",
471
+ "image_generation",
472
+ "local_shell",
473
+ "mcp",
474
+ "shell",
475
+ "web_search",
476
+ "web_search_preview"
477
+ ])
478
+ }),
479
+ [UnknownRecord]
480
+ )
481
+
482
+ /**
483
+ * Schema for tool definitions that can be supplied to an OpenAI Responses request.
484
+ *
485
+ * **When to use**
486
+ *
487
+ * Use when validating or encoding the `tools` array for a Responses request,
488
+ * including provider-defined tool records with provider-specific fields.
489
+ *
490
+ * **Details**
491
+ *
492
+ * Accepted variants are function tools, custom tools, and provider-defined
493
+ * OpenAI tools. Provider-defined `type` literals include `apply_patch`,
494
+ * `code_interpreter`, `file_search`, `image_generation`, `local_shell`, `mcp`,
495
+ * `shell`, `web_search`, and `web_search_preview`.
496
+ *
497
+ * **Gotchas**
498
+ *
499
+ * Provider-defined tools use `Schema.StructWithRest`, so this schema checks the
500
+ * provider tool `type` and permits additional provider fields rather than fully
501
+ * validating every provider-specific tool payload.
502
+ *
503
+ * @see {@link ToolChoice} for selecting whether and which tools the model may call
504
+ * @see {@link CreateResponse} for the request schema that consumes tools
505
+ *
506
+ * @category schemas
507
+ * @since 4.0.0
508
+ */
509
+ export const Tool = Schema.Union([
510
+ FunctionTool,
511
+ CustomTool,
512
+ ProviderDefinedTool
513
+ ])
514
+
515
+ /**
516
+ * Tool definition that can be supplied to an OpenAI Responses request.
517
+ *
518
+ * @category models
519
+ * @since 4.0.0
520
+ */
521
+ export type Tool = typeof Tool.Type
522
+
523
+ /**
524
+ * Schema for selecting whether and which tools the model may call in a Responses request.
525
+ *
526
+ * **When to use**
527
+ *
528
+ * Use when validating or encoding the `tool_choice` field that constrains model
529
+ * tool use separately from the tool definitions themselves.
530
+ *
531
+ * **Details**
532
+ *
533
+ * Accepted forms are `"none"`, `"auto"`, `"required"`, an allowed-tools set,
534
+ * a named function or custom tool, or a provider-defined tool choice.
535
+ *
536
+ * @see {@link Tool} for tool definitions referenced by tool choices
537
+ * @see {@link CreateResponse} for the request schema that consumes `tool_choice`
538
+ *
539
+ * @category schemas
540
+ * @since 4.0.0
541
+ */
542
+ export const ToolChoice = Schema.Union([
543
+ Schema.Literals(["none", "auto", "required"]),
544
+ Schema.Struct({
545
+ type: Schema.Literal("allowed_tools"),
546
+ mode: Schema.Literals(["auto", "required"]),
547
+ tools: Schema.Array(JsonObject)
548
+ }),
549
+ Schema.Struct({
550
+ type: Schema.Literal("function"),
551
+ name: Schema.String
552
+ }),
553
+ Schema.Struct({
554
+ type: Schema.Literal("custom"),
555
+ name: Schema.String
556
+ }),
557
+ Schema.StructWithRest(
558
+ Schema.Struct({
559
+ type: Schema.Literals([
560
+ "apply_patch",
561
+ "code_interpreter",
562
+ "file_search",
563
+ "image_generation",
564
+ "local_shell",
565
+ "mcp",
566
+ "shell",
567
+ "web_search",
568
+ "web_search_preview"
569
+ ])
570
+ }),
571
+ [UnknownRecord]
572
+ )
573
+ ])
574
+
575
+ /**
576
+ * Tool selection mode or named tool choice for a Responses request.
577
+ *
578
+ * **Details**
579
+ *
580
+ * Accepted forms are `"none"`, `"auto"`, `"required"`, an allowed-tools set,
581
+ * a named function or custom tool, or a provider-defined tool choice.
582
+ *
583
+ * @category models
584
+ * @since 4.0.0
585
+ */
586
+ export type ToolChoice = typeof ToolChoice.Type
587
+
588
+ /**
589
+ * Schema for text output format configuration, including plain text, JSON object, and JSON Schema responses.
590
+ *
591
+ * **When to use**
592
+ *
593
+ * Use when validating or encoding the `text.format` setting for a Responses
594
+ * request, especially when choosing structured JSON Schema output.
595
+ *
596
+ * **Details**
597
+ *
598
+ * Accepted variants are `text`, `json_schema`, and `json_object`.
599
+ *
600
+ * **Gotchas**
601
+ *
602
+ * `json_object` is the older JSON mode. Prefer `json_schema` for models that
603
+ * support it.
604
+ *
605
+ * @see {@link CreateResponse} for the request schema that consumes text format configuration
606
+ *
607
+ * @category schemas
608
+ * @since 4.0.0
609
+ */
610
+ export const TextResponseFormatConfiguration = Schema.Union([
611
+ Schema.Struct({ type: Schema.Literal("text") }),
612
+ Schema.Struct({
613
+ type: Schema.Literal("json_schema"),
614
+ description: Schema.optionalKey(Schema.String),
615
+ name: Schema.String,
616
+ schema: JsonObject,
617
+ strict: Schema.optionalKey(Schema.NullOr(Schema.Boolean))
618
+ }),
619
+ Schema.Struct({ type: Schema.Literal("json_object") })
620
+ ])
621
+
622
+ /**
623
+ * Text output format configuration for plain text, JSON object, or JSON Schema responses.
624
+ *
625
+ * @category models
626
+ * @since 4.0.0
627
+ */
628
+ export type TextResponseFormatConfiguration = typeof TextResponseFormatConfiguration.Type
629
+
630
+ /**
631
+ * Schema for request options used to create an OpenAI Responses API response.
632
+ *
633
+ * **When to use**
634
+ *
635
+ * Use to validate or encode payloads sent to the OpenAI Responses API.
636
+ *
637
+ * **Details**
638
+ *
639
+ * Validates the Responses API request payload, including input content, model
640
+ * selection, instructions, reasoning options, text output format, tools,
641
+ * `tool_choice`, streaming, storage, response continuation, sampling options,
642
+ * and optional response fields requested through `include`.
643
+ *
644
+ * **Gotchas**
645
+ *
646
+ * When `stream` is `true`, the API returns stream events instead of a single
647
+ * response object.
648
+ *
649
+ * @see {@link Response} for decoded non-streaming response objects
650
+ * @see {@link ResponseStreamEvent} for decoded streaming event objects
651
+ *
652
+ * @category schemas
653
+ * @since 4.0.0
654
+ */
655
+ export const CreateResponse = Schema.Struct({
656
+ metadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
657
+ top_logprobs: Schema.optional(Schema.Number),
658
+ temperature: Schema.optional(Schema.Number),
659
+ top_p: Schema.optional(Schema.Number),
660
+ user: Schema.optional(Schema.String),
661
+ service_tier: Schema.optional(Schema.String),
662
+ previous_response_id: Schema.optional(Schema.String),
663
+ model: Schema.optional(Schema.String),
664
+ reasoning: Schema.optional(Schema.Struct({
665
+ effort: Schema.optional(Schema.Literals(["none", "minimal", "low", "medium", "high", "xhigh"])),
666
+
667
+ summary: Schema.optional(Schema.Literals(["auto", "concise", "detailed"])),
668
+ generate_summary: Schema.optional(Schema.Literals(["auto", "concise", "detailed"]))
669
+ })),
670
+ background: Schema.optional(Schema.Boolean),
671
+ max_output_tokens: Schema.optional(Schema.Number),
672
+ max_tool_calls: Schema.optional(Schema.Number),
673
+ text: Schema.optional(
674
+ Schema.Struct({
675
+ format: Schema.optional(TextResponseFormatConfiguration),
676
+ verbosity: Schema.optional(Schema.Literals(["low", "medium", "high"]))
677
+ })
678
+ ),
679
+ tools: Schema.optional(Schema.Array(Tool)),
680
+ tool_choice: Schema.optional(ToolChoice),
681
+ truncation: Schema.optional(Schema.Literals(["auto", "disabled"])),
682
+ input: Schema.optional(
683
+ Schema.Union([
684
+ Schema.String,
685
+ Schema.Array(InputItem)
686
+ ])
687
+ ),
688
+ include: Schema.optional(Schema.Array(IncludeEnum)),
689
+ store: Schema.optional(Schema.Boolean),
690
+ instructions: Schema.optional(Schema.String),
691
+ stream: Schema.optional(Schema.Boolean),
692
+ conversation: Schema.optional(Schema.String),
693
+ modalities: Schema.optional(Schema.Array(Schema.Literals(["text", "audio"]))),
694
+ seed: Schema.optional(Schema.Number)
695
+ })
696
+
697
+ /**
698
+ * Request options used to create an OpenAI Responses API response.
699
+ *
700
+ * @category options
701
+ * @since 4.0.0
702
+ */
703
+ export type CreateResponse = typeof CreateResponse.Type
704
+
705
+ /**
706
+ * Schema for token accounting reported on OpenAI Responses API response objects.
707
+ *
708
+ * **Details**
709
+ *
710
+ * The required counters are `input_tokens`, `output_tokens`, and
711
+ * `total_tokens`. Provider-specific token detail objects are preserved through
712
+ * `input_tokens_details`, `output_tokens_details`, and additional fields.
713
+ *
714
+ * @category schemas
715
+ * @since 4.0.0
716
+ */
717
+ export const ResponseUsage = Schema.StructWithRest(
718
+ Schema.Struct({
719
+ input_tokens: Schema.Number,
720
+ output_tokens: Schema.Number,
721
+ total_tokens: Schema.Number,
722
+ input_tokens_details: Schema.optionalKey(Schema.Unknown),
723
+ output_tokens_details: Schema.optionalKey(Schema.Unknown)
724
+ }),
725
+ [UnknownRecord]
726
+ )
727
+
728
+ /**
729
+ * Token accounting reported on OpenAI Responses API response objects.
730
+ *
731
+ * **Details**
732
+ *
733
+ * Includes total input, output, and combined token counts, with provider-specific
734
+ * token detail fields preserved when present.
735
+ *
736
+ * @category models
737
+ * @since 4.0.0
738
+ */
739
+ export type ResponseUsage = typeof ResponseUsage.Type
740
+
741
+ const ApplyPatchOperation = Schema.Struct({
742
+ type: Schema.String,
743
+ path: Schema.String,
744
+ diff: Schema.optionalKey(Schema.String)
745
+ })
746
+
747
+ const ApplyPatchCall = Schema.Struct({
748
+ id: Schema.String,
749
+ type: Schema.Literal("apply_patch_call"),
750
+ call_id: Schema.String,
751
+ operation: ApplyPatchOperation,
752
+ status: Schema.optionalKey(MessageStatus)
753
+ })
754
+
755
+ const CodeInterpreterCall = Schema.Struct({
756
+ id: Schema.String,
757
+ type: Schema.Literal("code_interpreter_call"),
758
+ code: Schema.optionalKey(Schema.String),
759
+ container_id: Schema.String,
760
+ outputs: Schema.optionalKey(Schema.Array(Schema.Unknown)),
761
+ status: Schema.optionalKey(MessageStatus)
762
+ })
763
+
764
+ const ComputerCall = Schema.Struct({
765
+ id: Schema.String,
766
+ type: Schema.Literal("computer_call"),
767
+ status: Schema.optionalKey(MessageStatus)
768
+ })
769
+
770
+ const FileSearchCall = Schema.Struct({
771
+ id: Schema.String,
772
+ type: Schema.Literal("file_search_call"),
773
+ status: Schema.optionalKey(Schema.String),
774
+ queries: Schema.optionalKey(Schema.Array(Schema.String)),
775
+ results: Schema.optionalKey(Schema.NullOr(Schema.Unknown))
776
+ })
777
+
778
+ const ImageGenerationCall = Schema.Struct({
779
+ id: Schema.String,
780
+ type: Schema.Literal("image_generation_call"),
781
+ result: Schema.optionalKey(Schema.String),
782
+ status: Schema.optionalKey(MessageStatus)
783
+ })
784
+
785
+ const McpCall = Schema.Struct({
786
+ id: Schema.String,
787
+ type: Schema.Literal("mcp_call"),
788
+ approval_request_id: Schema.optionalKey(Schema.NullOr(Schema.String)),
789
+ name: Schema.String,
790
+ arguments: Schema.Unknown,
791
+ output: Schema.optionalKey(Schema.Unknown),
792
+ error: Schema.optionalKey(Schema.Unknown),
793
+ server_label: Schema.optionalKey(Schema.NullOr(Schema.String))
794
+ })
795
+
796
+ const McpListTools = Schema.Struct({
797
+ id: Schema.String,
798
+ type: Schema.Literal("mcp_list_tools")
799
+ })
800
+
801
+ const McpApprovalRequest = Schema.Struct({
802
+ id: Schema.String,
803
+ type: Schema.Literal("mcp_approval_request"),
804
+ approval_request_id: Schema.optionalKey(Schema.String),
805
+ name: Schema.String,
806
+ arguments: Schema.Unknown
807
+ })
808
+
809
+ const WebSearchCall = Schema.Struct({
810
+ id: Schema.String,
811
+ type: Schema.Literal("web_search_call"),
812
+ action: Schema.optionalKey(Schema.Unknown),
813
+ status: Schema.optionalKey(Schema.String)
814
+ })
815
+
816
+ const OutputItem = Schema.Union([
817
+ ApplyPatchCall,
818
+ CodeInterpreterCall,
819
+ ComputerCall,
820
+ FileSearchCall,
821
+ FunctionCall,
822
+ ImageGenerationCall,
823
+ LocalShellCall,
824
+ McpCall,
825
+ McpListTools,
826
+ McpApprovalRequest,
827
+ OutputMessage,
828
+ ReasoningItem,
829
+ ShellCall,
830
+ WebSearchCall
831
+ ])
832
+
833
+ /**
834
+ * Schema for an OpenAI Responses API response object.
835
+ *
836
+ * **When to use**
837
+ *
838
+ * Use to decode non-streaming OpenAI Responses API responses.
839
+ *
840
+ * **Details**
841
+ *
842
+ * Response objects include the response id, model, creation time, output items,
843
+ * optional token usage, optional incomplete details, and optional service tier.
844
+ *
845
+ * @see {@link CreateResponse} for the request schema that creates responses
846
+ * @see {@link ResponseUsage} for token accounting on responses
847
+ * @see {@link ResponseStreamEvent} for streaming response events
848
+ *
849
+ * @category schemas
850
+ * @since 4.0.0
851
+ */
852
+ export const Response = Schema.Struct({
853
+ id: Schema.String,
854
+ object: Schema.optionalKey(Schema.Literal("response")),
855
+ model: Schema.String,
856
+ created_at: Schema.Number,
857
+ output: Schema.Array(OutputItem).pipe(
858
+ Schema.withDecodingDefault(Effect.succeed([]))
859
+ ),
860
+ usage: Schema.optionalKey(Schema.NullOr(ResponseUsage)),
861
+ incomplete_details: Schema.optionalKey(
862
+ Schema.NullOr(
863
+ Schema.Struct({
864
+ reason: Schema.optionalKey(Schema.Literals(["max_output_tokens", "content_filter"]))
865
+ })
866
+ )
867
+ ),
868
+ service_tier: Schema.optionalKey(Schema.String)
869
+ })
870
+
871
+ /**
872
+ * OpenAI Responses API response object.
873
+ *
874
+ * **When to use**
875
+ *
876
+ * Use when typing non-streaming OpenAI Responses API responses.
877
+ *
878
+ * **Details**
879
+ *
880
+ * Response objects include metadata, output items, optional token usage, and
881
+ * optional incomplete details.
882
+ *
883
+ * @category models
884
+ * @since 4.0.0
885
+ */
886
+ export type Response = typeof Response.Type
887
+
888
+ const ResponseCreatedEvent = Schema.Struct({
889
+ type: Schema.Literal("response.created"),
890
+ response: Response,
891
+ sequence_number: Schema.Number
892
+ })
893
+
894
+ const ResponseCompletedEvent = Schema.Struct({
895
+ type: Schema.Literal("response.completed"),
896
+ response: Response,
897
+ sequence_number: Schema.Number
898
+ })
899
+
900
+ const ResponseIncompleteEvent = Schema.Struct({
901
+ type: Schema.Literal("response.incomplete"),
902
+ response: Response,
903
+ sequence_number: Schema.Number
904
+ })
905
+
906
+ const ResponseFailedEvent = Schema.Struct({
907
+ type: Schema.Literal("response.failed"),
908
+ response: Response,
909
+ sequence_number: Schema.Number
910
+ })
911
+
912
+ const ResponseOutputItemAddedEvent = Schema.Struct({
913
+ type: Schema.Literal("response.output_item.added"),
914
+ output_index: Schema.Number,
915
+ sequence_number: Schema.Number,
916
+ item: OutputItem
917
+ })
918
+
919
+ const ResponseOutputItemDoneEvent = Schema.Struct({
920
+ type: Schema.Literal("response.output_item.done"),
921
+ output_index: Schema.Number,
922
+ sequence_number: Schema.Number,
923
+ item: OutputItem
924
+ })
925
+
926
+ const ResponseOutputTextDeltaEvent = Schema.Struct({
927
+ type: Schema.Literal("response.output_text.delta"),
928
+ item_id: Schema.String,
929
+ output_index: Schema.Number,
930
+ content_index: Schema.Number,
931
+ delta: Schema.String,
932
+ sequence_number: Schema.Number,
933
+ logprobs: Schema.optionalKey(Schema.Array(Schema.Unknown))
934
+ })
935
+
936
+ const ResponseOutputTextAnnotationAddedEvent = Schema.Struct({
937
+ type: Schema.Literal("response.output_text.annotation.added"),
938
+ item_id: Schema.String,
939
+ output_index: Schema.Number,
940
+ content_index: Schema.Number,
941
+ annotation_index: Schema.Number,
942
+ sequence_number: Schema.Number,
943
+ annotation: Annotation
944
+ })
945
+
946
+ const ResponseReasoningSummaryPartAddedEvent = Schema.Struct({
947
+ type: Schema.Literal("response.reasoning_summary_part.added"),
948
+ item_id: Schema.String,
949
+ output_index: Schema.Number,
950
+ summary_index: Schema.Number,
951
+ sequence_number: Schema.Number,
952
+ part: SummaryTextContent
953
+ })
954
+
955
+ const ResponseReasoningSummaryPartDoneEvent = Schema.Struct({
956
+ type: Schema.Literal("response.reasoning_summary_part.done"),
957
+ item_id: Schema.String,
958
+ output_index: Schema.Number,
959
+ summary_index: Schema.Number,
960
+ sequence_number: Schema.Number,
961
+ part: SummaryTextContent
962
+ })
963
+
964
+ const ResponseReasoningSummaryTextDeltaEvent = Schema.Struct({
965
+ type: Schema.Literal("response.reasoning_summary_text.delta"),
966
+ item_id: Schema.String,
967
+ output_index: Schema.Number,
968
+ summary_index: Schema.Number,
969
+ delta: Schema.String,
970
+ sequence_number: Schema.Number
971
+ })
972
+
973
+ const ResponseFunctionCallArgumentsDeltaEvent = Schema.Struct({
974
+ type: Schema.Literal("response.function_call_arguments.delta"),
975
+ item_id: Schema.String,
976
+ output_index: Schema.Number,
977
+ sequence_number: Schema.Number,
978
+ delta: Schema.String
979
+ })
980
+
981
+ const ResponseFunctionCallArgumentsDoneEvent = Schema.Struct({
982
+ type: Schema.Literal("response.function_call_arguments.done"),
983
+ item_id: Schema.String,
984
+ output_index: Schema.Number,
985
+ sequence_number: Schema.Number,
986
+ arguments: Schema.String
987
+ })
988
+
989
+ const ResponseCodeInterpreterCallCodeDeltaEvent = Schema.Struct({
990
+ type: Schema.Literal("response.code_interpreter_call_code.delta"),
991
+ item_id: Schema.String,
992
+ output_index: Schema.Number,
993
+ sequence_number: Schema.Number,
994
+ delta: Schema.String
995
+ })
996
+
997
+ const ResponseCodeInterpreterCallCodeDoneEvent = Schema.Struct({
998
+ type: Schema.Literal("response.code_interpreter_call_code.done"),
999
+ item_id: Schema.String,
1000
+ output_index: Schema.Number,
1001
+ sequence_number: Schema.Number,
1002
+ code: Schema.String
1003
+ })
1004
+
1005
+ const ResponseApplyPatchCallOperationDiffDeltaEvent = Schema.Struct({
1006
+ type: Schema.Literal("response.apply_patch_call_operation_diff.delta"),
1007
+ item_id: Schema.String,
1008
+ output_index: Schema.Number,
1009
+ sequence_number: Schema.Number,
1010
+ delta: Schema.String
1011
+ })
1012
+
1013
+ const ResponseApplyPatchCallOperationDiffDoneEvent = Schema.Struct({
1014
+ type: Schema.Literal("response.apply_patch_call_operation_diff.done"),
1015
+ item_id: Schema.String,
1016
+ output_index: Schema.Number,
1017
+ sequence_number: Schema.Number,
1018
+ delta: Schema.optionalKey(Schema.String)
1019
+ })
1020
+
1021
+ const ResponseImageGenerationCallPartialImageEvent = Schema.Struct({
1022
+ type: Schema.Literal("response.image_generation_call.partial_image"),
1023
+ item_id: Schema.String,
1024
+ output_index: Schema.Number,
1025
+ sequence_number: Schema.Number,
1026
+ partial_image_b64: Schema.String
1027
+ })
1028
+
1029
+ const ResponseErrorEvent = Schema.Struct({
1030
+ type: Schema.Literal("error"),
1031
+ code: Schema.NullOr(Schema.String),
1032
+ message: Schema.String,
1033
+ param: Schema.NullOr(Schema.String),
1034
+ sequence_number: Schema.Number,
1035
+ status: Schema.optionalKey(Schema.Number)
1036
+ })
1037
+
1038
+ const knownResponseStreamEventTypes = new Set([
1039
+ "response.created",
1040
+ "response.completed",
1041
+ "response.incomplete",
1042
+ "response.failed",
1043
+ "response.output_item.added",
1044
+ "response.output_item.done",
1045
+ "response.output_text.delta",
1046
+ "response.output_text.annotation.added",
1047
+ "response.reasoning_summary_part.added",
1048
+ "response.reasoning_summary_part.done",
1049
+ "response.reasoning_summary_text.delta",
1050
+ "response.function_call_arguments.delta",
1051
+ "response.function_call_arguments.done",
1052
+ "response.code_interpreter_call_code.delta",
1053
+ "response.code_interpreter_call_code.done",
1054
+ "response.apply_patch_call_operation_diff.delta",
1055
+ "response.apply_patch_call_operation_diff.done",
1056
+ "response.image_generation_call.partial_image",
1057
+ "error"
1058
+ ])
1059
+
1060
+ /**
1061
+ * Fallback event shape for future or provider-specific response stream events.
1062
+ *
1063
+ * @category models
1064
+ * @since 4.0.0
1065
+ */
1066
+ export type UnknownResponseStreamEvent = {
1067
+ readonly type: string
1068
+ readonly [key: string]: unknown
1069
+ }
1070
+
1071
+ const UnknownResponseStreamEvent = Schema.declare<UnknownResponseStreamEvent>(
1072
+ (value): value is UnknownResponseStreamEvent =>
1073
+ Predicate.hasProperty(value, "type") &&
1074
+ typeof value.type === "string" &&
1075
+ !knownResponseStreamEventTypes.has(value.type),
1076
+ {
1077
+ identifier: "UnknownResponseStreamEvent",
1078
+ description: "Fallback for unknown future stream events"
1079
+ }
1080
+ )
1081
+
1082
+ /**
1083
+ * Schema for server-sent event shapes emitted by OpenAI Responses API streams.
1084
+ *
1085
+ * **When to use**
1086
+ *
1087
+ * Use to decode events from a streaming OpenAI Responses API request.
1088
+ *
1089
+ * **Details**
1090
+ *
1091
+ * Known event variants include response lifecycle events, output item events,
1092
+ * text and reasoning deltas, tool-call deltas, partial image events, and error
1093
+ * events.
1094
+ *
1095
+ * **Gotchas**
1096
+ *
1097
+ * Future event types decode through the fallback only when their `type` is not
1098
+ * one of the known event types. Malformed known events still fail to decode.
1099
+ *
1100
+ * @see {@link Response} for complete response objects carried by lifecycle events
1101
+ * @see {@link UnknownResponseStreamEvent} for the fallback shape for future event types
1102
+ *
1103
+ * @category schemas
1104
+ * @since 4.0.0
1105
+ */
1106
+ export const ResponseStreamEvent = Schema.Union([
1107
+ ResponseCreatedEvent,
1108
+ ResponseCompletedEvent,
1109
+ ResponseIncompleteEvent,
1110
+ ResponseFailedEvent,
1111
+ ResponseOutputItemAddedEvent,
1112
+ ResponseOutputItemDoneEvent,
1113
+ ResponseOutputTextDeltaEvent,
1114
+ ResponseOutputTextAnnotationAddedEvent,
1115
+ ResponseReasoningSummaryPartAddedEvent,
1116
+ ResponseReasoningSummaryPartDoneEvent,
1117
+ ResponseReasoningSummaryTextDeltaEvent,
1118
+ ResponseFunctionCallArgumentsDeltaEvent,
1119
+ ResponseFunctionCallArgumentsDoneEvent,
1120
+ ResponseCodeInterpreterCallCodeDeltaEvent,
1121
+ ResponseCodeInterpreterCallCodeDoneEvent,
1122
+ ResponseApplyPatchCallOperationDiffDeltaEvent,
1123
+ ResponseApplyPatchCallOperationDiffDoneEvent,
1124
+ ResponseImageGenerationCallPartialImageEvent,
1125
+ ResponseErrorEvent,
1126
+ UnknownResponseStreamEvent
1127
+ ])
1128
+
1129
+ /**
1130
+ * Server-sent event shape emitted by OpenAI Responses API streams.
1131
+ *
1132
+ * **When to use**
1133
+ *
1134
+ * Use when typing events from a streaming OpenAI Responses API request.
1135
+ *
1136
+ * **Details**
1137
+ *
1138
+ * Includes known response stream events plus a fallback shape for unknown future
1139
+ * event types.
1140
+ *
1141
+ * @category models
1142
+ * @since 4.0.0
1143
+ */
1144
+ export type ResponseStreamEvent = typeof ResponseStreamEvent.Type
1145
+
1146
+ /**
1147
+ * Schema for one embedding item returned by the OpenAI embeddings API.
1148
+ *
1149
+ * **When to use**
1150
+ *
1151
+ * Use when validating individual embedding entries at the OpenAI client boundary
1152
+ * before assuming the embedding payload is a numeric vector.
1153
+ *
1154
+ * **Details**
1155
+ *
1156
+ * An embedding item contains its `index`, optional `object` marker, and an
1157
+ * `embedding` represented either as a numeric vector or as a string.
1158
+ *
1159
+ * **Gotchas**
1160
+ *
1161
+ * Callers that need numeric vectors must account for string embeddings, such as
1162
+ * base64-encoded embeddings returned for string encoding formats.
1163
+ *
1164
+ * @category schemas
1165
+ * @since 4.0.0
1166
+ */
1167
+ export const Embedding = Schema.Struct({
1168
+ embedding: Schema.Union([
1169
+ Schema.Array(Schema.Number),
1170
+ Schema.String
1171
+ ]),
1172
+ index: Schema.Number,
1173
+ object: Schema.optionalKey(Schema.String)
1174
+ })
1175
+
1176
+ /**
1177
+ * One embedding item returned by the OpenAI embeddings API.
1178
+ *
1179
+ * **Details**
1180
+ *
1181
+ * Contains the item index and embedding payload. The embedding payload may be a
1182
+ * numeric vector or a string.
1183
+ *
1184
+ * @category models
1185
+ * @since 4.0.0
1186
+ */
1187
+ export type Embedding = typeof Embedding.Type
1188
+
1189
+ /**
1190
+ * Schema for the request payload sent to the OpenAI embeddings endpoint.
1191
+ *
1192
+ * **When to use**
1193
+ *
1194
+ * Use when validating or encoding embeddings requests before sending them to
1195
+ * OpenAI, while leaving model-specific limits to the provider.
1196
+ *
1197
+ * **Details**
1198
+ *
1199
+ * Requires `input` and `model`. `input` may be a string, an array of strings,
1200
+ * a token array, or an array of token arrays. Optional fields configure the
1201
+ * embedding encoding format, requested dimensions, and user identifier.
1202
+ *
1203
+ * **Gotchas**
1204
+ *
1205
+ * This schema validates the transport shape, but OpenAI still enforces
1206
+ * provider-side constraints such as non-empty input, integer token ids, input
1207
+ * size limits, positive dimensions, and model-specific dimension support.
1208
+ *
1209
+ * @category schemas
1210
+ * @since 4.0.0
1211
+ */
1212
+ export const CreateEmbeddingRequest = Schema.Struct({
1213
+ input: Schema.Union([
1214
+ Schema.String,
1215
+ Schema.Array(Schema.String),
1216
+ Schema.Array(Schema.Number),
1217
+ Schema.Array(Schema.Array(Schema.Number))
1218
+ ]),
1219
+ model: Schema.String,
1220
+ encoding_format: Schema.optionalKey(Schema.Literals(["float", "base64"])),
1221
+ dimensions: Schema.optionalKey(Schema.Number),
1222
+ user: Schema.optionalKey(Schema.String)
1223
+ })
1224
+
1225
+ /**
1226
+ * Request payload sent to the OpenAI embeddings endpoint.
1227
+ *
1228
+ * @category models
1229
+ * @since 4.0.0
1230
+ */
1231
+ export type CreateEmbeddingRequest = typeof CreateEmbeddingRequest.Type
1232
+
1233
+ /**
1234
+ * Schema for a successful response payload returned by the OpenAI embeddings endpoint.
1235
+ *
1236
+ * **When to use**
1237
+ *
1238
+ * Use when you need to validate embeddings responses at an OpenAI client
1239
+ * boundary before trusting item shapes, especially when numeric and string
1240
+ * embeddings are both allowed.
1241
+ *
1242
+ * **Details**
1243
+ *
1244
+ * The response contains an array of `Embedding` items, the model name, an
1245
+ * optional `object: "list"` marker, and optional token usage counts for prompt
1246
+ * and total tokens.
1247
+ *
1248
+ * **Gotchas**
1249
+ *
1250
+ * Each `Embedding` may contain either a numeric vector or a string embedding.
1251
+ * Callers that require numeric vectors must account for string embeddings.
1252
+ *
1253
+ * @see {@link CreateEmbeddingRequest} for the request schema sent to the embeddings endpoint
1254
+ * @see {@link Embedding} for individual embedding items in the response
1255
+ *
1256
+ * @category schemas
1257
+ * @since 4.0.0
1258
+ */
1259
+ export const CreateEmbeddingResponse = Schema.Struct({
1260
+ data: Schema.Array(Embedding),
1261
+ model: Schema.String,
1262
+ object: Schema.optionalKey(Schema.Literal("list")),
1263
+ usage: Schema.optionalKey(
1264
+ Schema.Struct({
1265
+ prompt_tokens: Schema.Number,
1266
+ total_tokens: Schema.Number
1267
+ })
1268
+ )
1269
+ })
1270
+
1271
+ /**
1272
+ * Successful response payload returned by the OpenAI embeddings endpoint.
1273
+ *
1274
+ * **When to use**
1275
+ *
1276
+ * Use when typing successful OpenAI embeddings responses.
1277
+ *
1278
+ * **Details**
1279
+ *
1280
+ * Contains embedding items, the model name, optional list marker, and optional
1281
+ * token usage counts.
1282
+ *
1283
+ * @category models
1284
+ * @since 4.0.0
1285
+ */
1286
+ export type CreateEmbeddingResponse = typeof CreateEmbeddingResponse.Type