@effect/ai-openai 4.0.0-beta.7 → 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.
- package/dist/Generated.d.ts +66734 -37723
- package/dist/Generated.d.ts.map +1 -1
- package/dist/Generated.js +1 -1
- package/dist/Generated.js.map +1 -1
- package/dist/OpenAiClient.d.ts +167 -27
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +337 -44
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiClientGenerated.d.ts +91 -0
- package/dist/OpenAiClientGenerated.d.ts.map +1 -0
- package/dist/OpenAiClientGenerated.js +84 -0
- package/dist/OpenAiClientGenerated.js.map +1 -0
- package/dist/OpenAiConfig.d.ts +114 -10
- package/dist/OpenAiConfig.d.ts.map +1 -1
- package/dist/OpenAiConfig.js +68 -7
- package/dist/OpenAiConfig.js.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +213 -0
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
- package/dist/OpenAiEmbeddingModel.js +219 -0
- package/dist/OpenAiEmbeddingModel.js.map +1 -0
- package/dist/OpenAiError.d.ts +168 -35
- package/dist/OpenAiError.d.ts.map +1 -1
- package/dist/OpenAiError.js +1 -1
- package/dist/OpenAiLanguageModel.d.ts +384 -62
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +416 -166
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiSchema.d.ts +2298 -0
- package/dist/OpenAiSchema.d.ts.map +1 -0
- package/dist/OpenAiSchema.js +814 -0
- package/dist/OpenAiSchema.js.map +1 -0
- package/dist/OpenAiTelemetry.d.ts +59 -18
- package/dist/OpenAiTelemetry.d.ts.map +1 -1
- package/dist/OpenAiTelemetry.js +35 -8
- package/dist/OpenAiTelemetry.js.map +1 -1
- package/dist/OpenAiTool.d.ts +157 -62
- package/dist/OpenAiTool.d.ts.map +1 -1
- package/dist/OpenAiTool.js +134 -39
- package/dist/OpenAiTool.js.map +1 -1
- package/dist/index.d.ts +19 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -33
- package/dist/index.js.map +1 -1
- package/dist/internal/errors.js +4 -4
- package/dist/internal/errors.js.map +1 -1
- package/package.json +3 -3
- package/src/Generated.ts +9858 -5044
- package/src/OpenAiClient.ts +513 -95
- package/src/OpenAiClientGenerated.ts +202 -0
- package/src/OpenAiConfig.ts +115 -11
- package/src/OpenAiEmbeddingModel.ts +357 -0
- package/src/OpenAiError.ts +170 -35
- package/src/OpenAiLanguageModel.ts +802 -167
- package/src/OpenAiSchema.ts +1289 -0
- package/src/OpenAiTelemetry.ts +81 -23
- package/src/OpenAiTool.ts +135 -40
- package/src/index.ts +22 -33
- package/src/internal/errors.ts +6 -4
|
@@ -0,0 +1,1289 @@
|
|
|
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
|
+
* **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.
|
|
36
|
+
*
|
|
37
|
+
* @since 4.0.0
|
|
38
|
+
*/
|
|
39
|
+
import * as Effect from "effect/Effect"
|
|
40
|
+
import * as Predicate from "effect/Predicate"
|
|
41
|
+
import * as Schema from "effect/Schema"
|
|
42
|
+
|
|
43
|
+
const UnknownRecord = Schema.Record(Schema.String, Schema.Unknown)
|
|
44
|
+
|
|
45
|
+
const JsonObject = Schema.Record(Schema.String, Schema.Unknown)
|
|
46
|
+
|
|
47
|
+
const MessageRole = Schema.Literals(["system", "developer", "user", "assistant"])
|
|
48
|
+
|
|
49
|
+
const ImageDetail = Schema.Literals(["low", "high", "auto"])
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Schema for optional `include` values supported by the local handwritten
|
|
53
|
+
* Responses client schema.
|
|
54
|
+
*
|
|
55
|
+
* **Details**
|
|
56
|
+
*
|
|
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.
|
|
61
|
+
*
|
|
62
|
+
* @category schemas
|
|
63
|
+
* @since 4.0.0
|
|
64
|
+
*/
|
|
65
|
+
export const IncludeEnum = Schema.Literals([
|
|
66
|
+
"message.input_image.image_url",
|
|
67
|
+
"reasoning.encrypted_content",
|
|
68
|
+
"message.output_text.logprobs",
|
|
69
|
+
"code_interpreter_call.outputs",
|
|
70
|
+
"web_search_call.action.sources"
|
|
71
|
+
])
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Type of optional `include` values accepted by OpenAI Responses requests.
|
|
75
|
+
*
|
|
76
|
+
* @category models
|
|
77
|
+
* @since 4.0.0
|
|
78
|
+
*/
|
|
79
|
+
export type IncludeEnum = typeof IncludeEnum.Type
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Schema for lifecycle statuses shared by messages, reasoning items, and tool calls.
|
|
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
|
+
*
|
|
89
|
+
* @category schemas
|
|
90
|
+
* @since 4.0.0
|
|
91
|
+
*/
|
|
92
|
+
export const MessageStatus = Schema.Literals(["in_progress", "completed", "incomplete"])
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Lifecycle status shared by messages, reasoning items, and tool calls.
|
|
96
|
+
*
|
|
97
|
+
* **Details**
|
|
98
|
+
*
|
|
99
|
+
* Accepted values are `"in_progress"`, `"completed"`, and `"incomplete"`.
|
|
100
|
+
*
|
|
101
|
+
* @category models
|
|
102
|
+
* @since 4.0.0
|
|
103
|
+
*/
|
|
104
|
+
export type MessageStatus = typeof MessageStatus.Type
|
|
105
|
+
|
|
106
|
+
const InputTextContent = Schema.Struct({
|
|
107
|
+
type: Schema.Literal("input_text"),
|
|
108
|
+
text: Schema.String
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
const InputImageContent = Schema.Struct({
|
|
112
|
+
type: Schema.Literal("input_image"),
|
|
113
|
+
image_url: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
114
|
+
file_id: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
115
|
+
detail: Schema.optionalKey(Schema.NullOr(ImageDetail))
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const InputFileContent = Schema.Struct({
|
|
119
|
+
type: Schema.Literal("input_file"),
|
|
120
|
+
file_id: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
121
|
+
filename: Schema.optionalKey(Schema.String),
|
|
122
|
+
file_url: Schema.optionalKey(Schema.String),
|
|
123
|
+
file_data: Schema.optionalKey(Schema.String)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Schema for content blocks accepted in OpenAI Responses input messages.
|
|
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
|
+
*
|
|
135
|
+
* @category schemas
|
|
136
|
+
* @since 4.0.0
|
|
137
|
+
*/
|
|
138
|
+
export const InputContent = Schema.Union([
|
|
139
|
+
InputTextContent,
|
|
140
|
+
InputImageContent,
|
|
141
|
+
InputFileContent
|
|
142
|
+
])
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Content block accepted in OpenAI Responses input messages.
|
|
146
|
+
*
|
|
147
|
+
* **Details**
|
|
148
|
+
*
|
|
149
|
+
* Accepted block variants are `input_text`, `input_image`, and `input_file`.
|
|
150
|
+
*
|
|
151
|
+
* @category models
|
|
152
|
+
* @since 4.0.0
|
|
153
|
+
*/
|
|
154
|
+
export type InputContent = typeof InputContent.Type
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Schema for a text block containing a model-provided reasoning summary.
|
|
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
|
+
*
|
|
166
|
+
* @category schemas
|
|
167
|
+
* @since 4.0.0
|
|
168
|
+
*/
|
|
169
|
+
export const SummaryTextContent = Schema.Struct({
|
|
170
|
+
type: Schema.Literal("summary_text"),
|
|
171
|
+
text: Schema.String
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Text content block used for model-provided reasoning summaries.
|
|
176
|
+
*
|
|
177
|
+
* @category models
|
|
178
|
+
* @since 4.0.0
|
|
179
|
+
*/
|
|
180
|
+
export type SummaryTextContent = typeof SummaryTextContent.Type
|
|
181
|
+
|
|
182
|
+
const ReasoningTextContent = Schema.Struct({
|
|
183
|
+
type: Schema.Literal("reasoning_text"),
|
|
184
|
+
text: Schema.String
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
const RefusalContent = Schema.Struct({
|
|
188
|
+
type: Schema.Literal("refusal"),
|
|
189
|
+
refusal: Schema.String
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
const TextContent = Schema.Struct({
|
|
193
|
+
type: Schema.Literal("text"),
|
|
194
|
+
text: Schema.String
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
const ComputerScreenshotContent = Schema.Struct({
|
|
198
|
+
type: Schema.Literal("computer_screenshot"),
|
|
199
|
+
image_url: Schema.NullOr(Schema.String),
|
|
200
|
+
file_id: Schema.NullOr(Schema.String)
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
const FileCitationAnnotation = Schema.Struct({
|
|
204
|
+
type: Schema.Literal("file_citation"),
|
|
205
|
+
file_id: Schema.String,
|
|
206
|
+
index: Schema.Number,
|
|
207
|
+
filename: Schema.String
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
const UrlCitationAnnotation = Schema.Struct({
|
|
211
|
+
type: Schema.Literal("url_citation"),
|
|
212
|
+
url: Schema.String,
|
|
213
|
+
start_index: Schema.Number,
|
|
214
|
+
end_index: Schema.Number,
|
|
215
|
+
title: Schema.String
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
const ContainerFileCitationAnnotation = Schema.Struct({
|
|
219
|
+
type: Schema.Literal("container_file_citation"),
|
|
220
|
+
container_id: Schema.String,
|
|
221
|
+
file_id: Schema.String,
|
|
222
|
+
start_index: Schema.Number,
|
|
223
|
+
end_index: Schema.Number,
|
|
224
|
+
filename: Schema.String
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
const FilePathAnnotation = Schema.Struct({
|
|
228
|
+
type: Schema.Literal("file_path"),
|
|
229
|
+
file_id: Schema.String,
|
|
230
|
+
index: Schema.Number
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Schema for citation and file-path annotations attached to output text content.
|
|
235
|
+
*
|
|
236
|
+
* **Details**
|
|
237
|
+
*
|
|
238
|
+
* Accepts annotation objects discriminated by `type`: `file_citation`,
|
|
239
|
+
* `url_citation`, `container_file_citation`, or `file_path`.
|
|
240
|
+
*
|
|
241
|
+
* @category schemas
|
|
242
|
+
* @since 4.0.0
|
|
243
|
+
*/
|
|
244
|
+
export const Annotation = Schema.Union([
|
|
245
|
+
FileCitationAnnotation,
|
|
246
|
+
UrlCitationAnnotation,
|
|
247
|
+
ContainerFileCitationAnnotation,
|
|
248
|
+
FilePathAnnotation
|
|
249
|
+
])
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Citation or file-path annotation attached to output text content.
|
|
253
|
+
*
|
|
254
|
+
* **Details**
|
|
255
|
+
*
|
|
256
|
+
* Accepted annotation variants are `file_citation`, `url_citation`,
|
|
257
|
+
* `container_file_citation`, and `file_path`.
|
|
258
|
+
*
|
|
259
|
+
* @category models
|
|
260
|
+
* @since 4.0.0
|
|
261
|
+
*/
|
|
262
|
+
export type Annotation = typeof Annotation.Type
|
|
263
|
+
|
|
264
|
+
const OutputTextContent = Schema.Struct({
|
|
265
|
+
type: Schema.Literal("output_text"),
|
|
266
|
+
text: Schema.String,
|
|
267
|
+
annotations: Schema.Array(Annotation),
|
|
268
|
+
logprobs: Schema.optionalKey(Schema.Array(Schema.Unknown))
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
const OutputMessageContent = Schema.Union([
|
|
272
|
+
InputTextContent,
|
|
273
|
+
OutputTextContent,
|
|
274
|
+
TextContent,
|
|
275
|
+
SummaryTextContent,
|
|
276
|
+
ReasoningTextContent,
|
|
277
|
+
RefusalContent,
|
|
278
|
+
InputImageContent,
|
|
279
|
+
ComputerScreenshotContent,
|
|
280
|
+
InputFileContent
|
|
281
|
+
])
|
|
282
|
+
|
|
283
|
+
const OutputMessage = Schema.Struct({
|
|
284
|
+
id: Schema.String,
|
|
285
|
+
type: Schema.Literal("message"),
|
|
286
|
+
role: Schema.Literal("assistant"),
|
|
287
|
+
content: Schema.Array(OutputMessageContent),
|
|
288
|
+
status: MessageStatus
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Schema for a reasoning output item containing encrypted content, summaries, and optional reasoning text.
|
|
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
|
+
*
|
|
312
|
+
* @category schemas
|
|
313
|
+
* @since 4.0.0
|
|
314
|
+
*/
|
|
315
|
+
export const ReasoningItem = Schema.Struct({
|
|
316
|
+
type: Schema.Literal("reasoning"),
|
|
317
|
+
id: Schema.String,
|
|
318
|
+
encrypted_content: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
319
|
+
summary: Schema.Array(SummaryTextContent),
|
|
320
|
+
content: Schema.optionalKey(Schema.Array(ReasoningTextContent)),
|
|
321
|
+
status: Schema.optionalKey(MessageStatus)
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Reasoning output item containing encrypted content, summaries, and optional reasoning text.
|
|
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
|
+
*
|
|
342
|
+
* @category models
|
|
343
|
+
* @since 4.0.0
|
|
344
|
+
*/
|
|
345
|
+
export type ReasoningItem = typeof ReasoningItem.Type
|
|
346
|
+
|
|
347
|
+
const FunctionCall = Schema.Struct({
|
|
348
|
+
id: Schema.optionalKey(Schema.String),
|
|
349
|
+
type: Schema.Literal("function_call"),
|
|
350
|
+
call_id: Schema.String,
|
|
351
|
+
name: Schema.String,
|
|
352
|
+
arguments: Schema.String,
|
|
353
|
+
status: Schema.optionalKey(MessageStatus)
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
const FunctionCallOutput = Schema.Struct({
|
|
357
|
+
id: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
358
|
+
type: Schema.Literal("function_call_output"),
|
|
359
|
+
call_id: Schema.String,
|
|
360
|
+
output: Schema.Union([
|
|
361
|
+
Schema.String,
|
|
362
|
+
Schema.Array(InputContent)
|
|
363
|
+
]),
|
|
364
|
+
status: Schema.optionalKey(Schema.NullOr(MessageStatus))
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
const ItemReference = Schema.Struct({
|
|
368
|
+
type: Schema.Literal("item_reference"),
|
|
369
|
+
id: Schema.String
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
const LocalShellCall = Schema.Struct({
|
|
373
|
+
id: Schema.optionalKey(Schema.String),
|
|
374
|
+
type: Schema.Literal("local_shell_call"),
|
|
375
|
+
call_id: Schema.String,
|
|
376
|
+
action: Schema.Unknown,
|
|
377
|
+
status: Schema.optionalKey(MessageStatus)
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
const LocalShellCallOutput = Schema.Struct({
|
|
381
|
+
id: Schema.optionalKey(Schema.String),
|
|
382
|
+
type: Schema.Literal("local_shell_call_output"),
|
|
383
|
+
call_id: Schema.String,
|
|
384
|
+
output: Schema.Unknown,
|
|
385
|
+
status: Schema.optionalKey(MessageStatus)
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
const ShellCall = Schema.Struct({
|
|
389
|
+
id: Schema.optionalKey(Schema.String),
|
|
390
|
+
type: Schema.Literal("shell_call"),
|
|
391
|
+
call_id: Schema.String,
|
|
392
|
+
action: Schema.Unknown,
|
|
393
|
+
status: Schema.optionalKey(MessageStatus)
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
const ShellCallOutput = Schema.Struct({
|
|
397
|
+
id: Schema.optionalKey(Schema.String),
|
|
398
|
+
type: Schema.Literal("shell_call_output"),
|
|
399
|
+
call_id: Schema.String,
|
|
400
|
+
output: Schema.Unknown,
|
|
401
|
+
status: Schema.optionalKey(MessageStatus)
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
const ApplyPatchCallOutput = Schema.Struct({
|
|
405
|
+
id: Schema.optionalKey(Schema.String),
|
|
406
|
+
type: Schema.Literal("apply_patch_call_output"),
|
|
407
|
+
call_id: Schema.String,
|
|
408
|
+
status: Schema.optionalKey(MessageStatus),
|
|
409
|
+
output: Schema.optionalKey(Schema.Unknown)
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
const McpApprovalResponse = Schema.Struct({
|
|
413
|
+
type: Schema.Literal("mcp_approval_response"),
|
|
414
|
+
approval_request_id: Schema.String,
|
|
415
|
+
approve: Schema.Boolean
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
const RequestMessageItem = Schema.Struct({
|
|
419
|
+
type: Schema.optionalKey(Schema.Literal("message")),
|
|
420
|
+
role: MessageRole,
|
|
421
|
+
status: Schema.optionalKey(MessageStatus),
|
|
422
|
+
content: Schema.Union([
|
|
423
|
+
Schema.String,
|
|
424
|
+
Schema.Array(InputContent)
|
|
425
|
+
])
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Schema for item shapes accepted by an OpenAI Responses request `input` field.
|
|
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
|
+
*
|
|
444
|
+
* @category schemas
|
|
445
|
+
* @since 4.0.0
|
|
446
|
+
*/
|
|
447
|
+
export const InputItem = Schema.Union([
|
|
448
|
+
RequestMessageItem,
|
|
449
|
+
OutputMessage,
|
|
450
|
+
FunctionCall,
|
|
451
|
+
FunctionCallOutput,
|
|
452
|
+
ReasoningItem,
|
|
453
|
+
ItemReference,
|
|
454
|
+
LocalShellCall,
|
|
455
|
+
LocalShellCallOutput,
|
|
456
|
+
ShellCall,
|
|
457
|
+
ShellCallOutput,
|
|
458
|
+
ApplyPatchCallOutput,
|
|
459
|
+
McpApprovalResponse
|
|
460
|
+
])
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Item shape accepted by an OpenAI Responses request `input` field.
|
|
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
|
+
*
|
|
475
|
+
* @category models
|
|
476
|
+
* @since 4.0.0
|
|
477
|
+
*/
|
|
478
|
+
export type InputItem = typeof InputItem.Type
|
|
479
|
+
|
|
480
|
+
const FunctionTool = Schema.Struct({
|
|
481
|
+
type: Schema.Literal("function"),
|
|
482
|
+
name: Schema.String,
|
|
483
|
+
description: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
484
|
+
parameters: Schema.optionalKey(Schema.NullOr(JsonObject)),
|
|
485
|
+
strict: Schema.optionalKey(Schema.NullOr(Schema.Boolean))
|
|
486
|
+
})
|
|
487
|
+
|
|
488
|
+
const CustomTool = Schema.Struct({
|
|
489
|
+
type: Schema.Literal("custom"),
|
|
490
|
+
name: Schema.String,
|
|
491
|
+
description: Schema.optionalKey(Schema.String),
|
|
492
|
+
format: Schema.optionalKey(Schema.Unknown)
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
const ProviderDefinedTool = Schema.StructWithRest(
|
|
496
|
+
Schema.Struct({
|
|
497
|
+
type: Schema.Literals([
|
|
498
|
+
"apply_patch",
|
|
499
|
+
"code_interpreter",
|
|
500
|
+
"file_search",
|
|
501
|
+
"image_generation",
|
|
502
|
+
"local_shell",
|
|
503
|
+
"mcp",
|
|
504
|
+
"shell",
|
|
505
|
+
"web_search",
|
|
506
|
+
"web_search_preview"
|
|
507
|
+
])
|
|
508
|
+
}),
|
|
509
|
+
[UnknownRecord]
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Schema for tool definitions that can be supplied to an OpenAI Responses request.
|
|
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
|
+
*
|
|
531
|
+
* @category schemas
|
|
532
|
+
* @since 4.0.0
|
|
533
|
+
*/
|
|
534
|
+
export const Tool = Schema.Union([
|
|
535
|
+
FunctionTool,
|
|
536
|
+
CustomTool,
|
|
537
|
+
ProviderDefinedTool
|
|
538
|
+
])
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Tool definition that can be supplied to an OpenAI Responses request.
|
|
542
|
+
*
|
|
543
|
+
* @category models
|
|
544
|
+
* @since 4.0.0
|
|
545
|
+
*/
|
|
546
|
+
export type Tool = typeof Tool.Type
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Schema for selecting whether and which tools the model may call in a Responses request.
|
|
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
|
+
*
|
|
559
|
+
* @category schemas
|
|
560
|
+
* @since 4.0.0
|
|
561
|
+
*/
|
|
562
|
+
export const ToolChoice = Schema.Union([
|
|
563
|
+
Schema.Literals(["none", "auto", "required"]),
|
|
564
|
+
Schema.Struct({
|
|
565
|
+
type: Schema.Literal("allowed_tools"),
|
|
566
|
+
mode: Schema.Literals(["auto", "required"]),
|
|
567
|
+
tools: Schema.Array(JsonObject)
|
|
568
|
+
}),
|
|
569
|
+
Schema.Struct({
|
|
570
|
+
type: Schema.Literal("function"),
|
|
571
|
+
name: Schema.String
|
|
572
|
+
}),
|
|
573
|
+
Schema.Struct({
|
|
574
|
+
type: Schema.Literal("custom"),
|
|
575
|
+
name: Schema.String
|
|
576
|
+
}),
|
|
577
|
+
Schema.StructWithRest(
|
|
578
|
+
Schema.Struct({
|
|
579
|
+
type: Schema.Literals([
|
|
580
|
+
"apply_patch",
|
|
581
|
+
"code_interpreter",
|
|
582
|
+
"file_search",
|
|
583
|
+
"image_generation",
|
|
584
|
+
"local_shell",
|
|
585
|
+
"mcp",
|
|
586
|
+
"shell",
|
|
587
|
+
"web_search",
|
|
588
|
+
"web_search_preview"
|
|
589
|
+
])
|
|
590
|
+
}),
|
|
591
|
+
[UnknownRecord]
|
|
592
|
+
)
|
|
593
|
+
])
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Tool selection mode or named tool choice for a Responses request.
|
|
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
|
+
*
|
|
603
|
+
* @category models
|
|
604
|
+
* @since 4.0.0
|
|
605
|
+
*/
|
|
606
|
+
export type ToolChoice = typeof ToolChoice.Type
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Schema for text output format configuration, including plain text, JSON object, and JSON Schema responses.
|
|
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
|
+
*
|
|
622
|
+
* @category schemas
|
|
623
|
+
* @since 4.0.0
|
|
624
|
+
*/
|
|
625
|
+
export const TextResponseFormatConfiguration = Schema.Union([
|
|
626
|
+
Schema.Struct({ type: Schema.Literal("text") }),
|
|
627
|
+
Schema.Struct({
|
|
628
|
+
type: Schema.Literal("json_schema"),
|
|
629
|
+
description: Schema.optionalKey(Schema.String),
|
|
630
|
+
name: Schema.String,
|
|
631
|
+
schema: JsonObject,
|
|
632
|
+
strict: Schema.optionalKey(Schema.NullOr(Schema.Boolean))
|
|
633
|
+
}),
|
|
634
|
+
Schema.Struct({ type: Schema.Literal("json_object") })
|
|
635
|
+
])
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Text output format configuration for plain text, JSON object, or JSON Schema responses.
|
|
639
|
+
*
|
|
640
|
+
* @category models
|
|
641
|
+
* @since 4.0.0
|
|
642
|
+
*/
|
|
643
|
+
export type TextResponseFormatConfiguration = typeof TextResponseFormatConfiguration.Type
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Schema for request options used to create an OpenAI Responses API response.
|
|
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
|
+
*
|
|
667
|
+
* @category schemas
|
|
668
|
+
* @since 4.0.0
|
|
669
|
+
*/
|
|
670
|
+
export const CreateResponse = Schema.Struct({
|
|
671
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
672
|
+
top_logprobs: Schema.optional(Schema.Number),
|
|
673
|
+
temperature: Schema.optional(Schema.Number),
|
|
674
|
+
top_p: Schema.optional(Schema.Number),
|
|
675
|
+
user: Schema.optional(Schema.String),
|
|
676
|
+
service_tier: Schema.optional(Schema.String),
|
|
677
|
+
previous_response_id: Schema.optional(Schema.String),
|
|
678
|
+
model: Schema.optional(Schema.String),
|
|
679
|
+
reasoning: Schema.optional(Schema.Struct({
|
|
680
|
+
effort: Schema.optional(Schema.Literals(["none", "minimal", "low", "medium", "high", "xhigh"])),
|
|
681
|
+
|
|
682
|
+
summary: Schema.optional(Schema.Literals(["auto", "concise", "detailed"])),
|
|
683
|
+
generate_summary: Schema.optional(Schema.Literals(["auto", "concise", "detailed"]))
|
|
684
|
+
})),
|
|
685
|
+
background: Schema.optional(Schema.Boolean),
|
|
686
|
+
max_output_tokens: Schema.optional(Schema.Number),
|
|
687
|
+
max_tool_calls: Schema.optional(Schema.Number),
|
|
688
|
+
text: Schema.optional(
|
|
689
|
+
Schema.Struct({
|
|
690
|
+
format: Schema.optional(TextResponseFormatConfiguration),
|
|
691
|
+
verbosity: Schema.optional(Schema.Literals(["low", "medium", "high"]))
|
|
692
|
+
})
|
|
693
|
+
),
|
|
694
|
+
tools: Schema.optional(Schema.Array(Tool)),
|
|
695
|
+
tool_choice: Schema.optional(ToolChoice),
|
|
696
|
+
truncation: Schema.optional(Schema.Literals(["auto", "disabled"])),
|
|
697
|
+
input: Schema.optional(
|
|
698
|
+
Schema.Union([
|
|
699
|
+
Schema.String,
|
|
700
|
+
Schema.Array(InputItem)
|
|
701
|
+
])
|
|
702
|
+
),
|
|
703
|
+
include: Schema.optional(Schema.Array(IncludeEnum)),
|
|
704
|
+
store: Schema.optional(Schema.Boolean),
|
|
705
|
+
instructions: Schema.optional(Schema.String),
|
|
706
|
+
stream: Schema.optional(Schema.Boolean),
|
|
707
|
+
conversation: Schema.optional(Schema.String),
|
|
708
|
+
modalities: Schema.optional(Schema.Array(Schema.Literals(["text", "audio"]))),
|
|
709
|
+
seed: Schema.optional(Schema.Number)
|
|
710
|
+
})
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Request options used to create an OpenAI Responses API response.
|
|
714
|
+
*
|
|
715
|
+
* @category models
|
|
716
|
+
* @since 4.0.0
|
|
717
|
+
*/
|
|
718
|
+
export type CreateResponse = typeof CreateResponse.Type
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Schema for token accounting reported on OpenAI Responses API response objects.
|
|
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
|
+
*
|
|
729
|
+
* @category schemas
|
|
730
|
+
* @since 4.0.0
|
|
731
|
+
*/
|
|
732
|
+
export const ResponseUsage = Schema.StructWithRest(
|
|
733
|
+
Schema.Struct({
|
|
734
|
+
input_tokens: Schema.Number,
|
|
735
|
+
output_tokens: Schema.Number,
|
|
736
|
+
total_tokens: Schema.Number,
|
|
737
|
+
input_tokens_details: Schema.optionalKey(Schema.Unknown),
|
|
738
|
+
output_tokens_details: Schema.optionalKey(Schema.Unknown)
|
|
739
|
+
}),
|
|
740
|
+
[UnknownRecord]
|
|
741
|
+
)
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Token accounting reported on OpenAI Responses API response objects.
|
|
745
|
+
*
|
|
746
|
+
* **Details**
|
|
747
|
+
*
|
|
748
|
+
* Includes total input, output, and combined token counts, with provider-specific
|
|
749
|
+
* token detail fields preserved when present.
|
|
750
|
+
*
|
|
751
|
+
* @category models
|
|
752
|
+
* @since 4.0.0
|
|
753
|
+
*/
|
|
754
|
+
export type ResponseUsage = typeof ResponseUsage.Type
|
|
755
|
+
|
|
756
|
+
const ApplyPatchOperation = Schema.Struct({
|
|
757
|
+
type: Schema.String,
|
|
758
|
+
path: Schema.String,
|
|
759
|
+
diff: Schema.optionalKey(Schema.String)
|
|
760
|
+
})
|
|
761
|
+
|
|
762
|
+
const ApplyPatchCall = Schema.Struct({
|
|
763
|
+
id: Schema.String,
|
|
764
|
+
type: Schema.Literal("apply_patch_call"),
|
|
765
|
+
call_id: Schema.String,
|
|
766
|
+
operation: ApplyPatchOperation,
|
|
767
|
+
status: Schema.optionalKey(MessageStatus)
|
|
768
|
+
})
|
|
769
|
+
|
|
770
|
+
const CodeInterpreterCall = Schema.Struct({
|
|
771
|
+
id: Schema.String,
|
|
772
|
+
type: Schema.Literal("code_interpreter_call"),
|
|
773
|
+
code: Schema.optionalKey(Schema.String),
|
|
774
|
+
container_id: Schema.String,
|
|
775
|
+
outputs: Schema.optionalKey(Schema.Array(Schema.Unknown)),
|
|
776
|
+
status: Schema.optionalKey(MessageStatus)
|
|
777
|
+
})
|
|
778
|
+
|
|
779
|
+
const ComputerCall = Schema.Struct({
|
|
780
|
+
id: Schema.String,
|
|
781
|
+
type: Schema.Literal("computer_call"),
|
|
782
|
+
status: Schema.optionalKey(MessageStatus)
|
|
783
|
+
})
|
|
784
|
+
|
|
785
|
+
const FileSearchCall = Schema.Struct({
|
|
786
|
+
id: Schema.String,
|
|
787
|
+
type: Schema.Literal("file_search_call"),
|
|
788
|
+
status: Schema.optionalKey(Schema.String),
|
|
789
|
+
queries: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
790
|
+
results: Schema.optionalKey(Schema.NullOr(Schema.Unknown))
|
|
791
|
+
})
|
|
792
|
+
|
|
793
|
+
const ImageGenerationCall = Schema.Struct({
|
|
794
|
+
id: Schema.String,
|
|
795
|
+
type: Schema.Literal("image_generation_call"),
|
|
796
|
+
result: Schema.optionalKey(Schema.String),
|
|
797
|
+
status: Schema.optionalKey(MessageStatus)
|
|
798
|
+
})
|
|
799
|
+
|
|
800
|
+
const McpCall = Schema.Struct({
|
|
801
|
+
id: Schema.String,
|
|
802
|
+
type: Schema.Literal("mcp_call"),
|
|
803
|
+
approval_request_id: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
|
804
|
+
name: Schema.String,
|
|
805
|
+
arguments: Schema.Unknown,
|
|
806
|
+
output: Schema.optionalKey(Schema.Unknown),
|
|
807
|
+
error: Schema.optionalKey(Schema.Unknown),
|
|
808
|
+
server_label: Schema.optionalKey(Schema.NullOr(Schema.String))
|
|
809
|
+
})
|
|
810
|
+
|
|
811
|
+
const McpListTools = Schema.Struct({
|
|
812
|
+
id: Schema.String,
|
|
813
|
+
type: Schema.Literal("mcp_list_tools")
|
|
814
|
+
})
|
|
815
|
+
|
|
816
|
+
const McpApprovalRequest = Schema.Struct({
|
|
817
|
+
id: Schema.String,
|
|
818
|
+
type: Schema.Literal("mcp_approval_request"),
|
|
819
|
+
approval_request_id: Schema.optionalKey(Schema.String),
|
|
820
|
+
name: Schema.String,
|
|
821
|
+
arguments: Schema.Unknown
|
|
822
|
+
})
|
|
823
|
+
|
|
824
|
+
const WebSearchCall = Schema.Struct({
|
|
825
|
+
id: Schema.String,
|
|
826
|
+
type: Schema.Literal("web_search_call"),
|
|
827
|
+
action: Schema.optionalKey(Schema.Unknown),
|
|
828
|
+
status: Schema.optionalKey(Schema.String)
|
|
829
|
+
})
|
|
830
|
+
|
|
831
|
+
const OutputItem = Schema.Union([
|
|
832
|
+
ApplyPatchCall,
|
|
833
|
+
CodeInterpreterCall,
|
|
834
|
+
ComputerCall,
|
|
835
|
+
FileSearchCall,
|
|
836
|
+
FunctionCall,
|
|
837
|
+
ImageGenerationCall,
|
|
838
|
+
LocalShellCall,
|
|
839
|
+
McpCall,
|
|
840
|
+
McpListTools,
|
|
841
|
+
McpApprovalRequest,
|
|
842
|
+
OutputMessage,
|
|
843
|
+
ReasoningItem,
|
|
844
|
+
ShellCall,
|
|
845
|
+
WebSearchCall
|
|
846
|
+
])
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* Schema for an OpenAI Responses API response object.
|
|
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
|
+
*
|
|
864
|
+
* @category schemas
|
|
865
|
+
* @since 4.0.0
|
|
866
|
+
*/
|
|
867
|
+
export const Response = Schema.Struct({
|
|
868
|
+
id: Schema.String,
|
|
869
|
+
object: Schema.optionalKey(Schema.Literal("response")),
|
|
870
|
+
model: Schema.String,
|
|
871
|
+
created_at: Schema.Number,
|
|
872
|
+
output: Schema.Array(OutputItem).pipe(
|
|
873
|
+
Schema.withDecodingDefault(Effect.succeed([]))
|
|
874
|
+
),
|
|
875
|
+
usage: Schema.optionalKey(Schema.NullOr(ResponseUsage)),
|
|
876
|
+
incomplete_details: Schema.optionalKey(
|
|
877
|
+
Schema.NullOr(
|
|
878
|
+
Schema.Struct({
|
|
879
|
+
reason: Schema.optionalKey(Schema.Literals(["max_output_tokens", "content_filter"]))
|
|
880
|
+
})
|
|
881
|
+
)
|
|
882
|
+
),
|
|
883
|
+
service_tier: Schema.optionalKey(Schema.String)
|
|
884
|
+
})
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* OpenAI Responses API response object.
|
|
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
|
+
*
|
|
898
|
+
* @category models
|
|
899
|
+
* @since 4.0.0
|
|
900
|
+
*/
|
|
901
|
+
export type Response = typeof Response.Type
|
|
902
|
+
|
|
903
|
+
const ResponseCreatedEvent = Schema.Struct({
|
|
904
|
+
type: Schema.Literal("response.created"),
|
|
905
|
+
response: Response,
|
|
906
|
+
sequence_number: Schema.Number
|
|
907
|
+
})
|
|
908
|
+
|
|
909
|
+
const ResponseCompletedEvent = Schema.Struct({
|
|
910
|
+
type: Schema.Literal("response.completed"),
|
|
911
|
+
response: Response,
|
|
912
|
+
sequence_number: Schema.Number
|
|
913
|
+
})
|
|
914
|
+
|
|
915
|
+
const ResponseIncompleteEvent = Schema.Struct({
|
|
916
|
+
type: Schema.Literal("response.incomplete"),
|
|
917
|
+
response: Response,
|
|
918
|
+
sequence_number: Schema.Number
|
|
919
|
+
})
|
|
920
|
+
|
|
921
|
+
const ResponseFailedEvent = Schema.Struct({
|
|
922
|
+
type: Schema.Literal("response.failed"),
|
|
923
|
+
response: Response,
|
|
924
|
+
sequence_number: Schema.Number
|
|
925
|
+
})
|
|
926
|
+
|
|
927
|
+
const ResponseOutputItemAddedEvent = Schema.Struct({
|
|
928
|
+
type: Schema.Literal("response.output_item.added"),
|
|
929
|
+
output_index: Schema.Number,
|
|
930
|
+
sequence_number: Schema.Number,
|
|
931
|
+
item: OutputItem
|
|
932
|
+
})
|
|
933
|
+
|
|
934
|
+
const ResponseOutputItemDoneEvent = Schema.Struct({
|
|
935
|
+
type: Schema.Literal("response.output_item.done"),
|
|
936
|
+
output_index: Schema.Number,
|
|
937
|
+
sequence_number: Schema.Number,
|
|
938
|
+
item: OutputItem
|
|
939
|
+
})
|
|
940
|
+
|
|
941
|
+
const ResponseOutputTextDeltaEvent = Schema.Struct({
|
|
942
|
+
type: Schema.Literal("response.output_text.delta"),
|
|
943
|
+
item_id: Schema.String,
|
|
944
|
+
output_index: Schema.Number,
|
|
945
|
+
content_index: Schema.Number,
|
|
946
|
+
delta: Schema.String,
|
|
947
|
+
sequence_number: Schema.Number,
|
|
948
|
+
logprobs: Schema.optionalKey(Schema.Array(Schema.Unknown))
|
|
949
|
+
})
|
|
950
|
+
|
|
951
|
+
const ResponseOutputTextAnnotationAddedEvent = Schema.Struct({
|
|
952
|
+
type: Schema.Literal("response.output_text.annotation.added"),
|
|
953
|
+
item_id: Schema.String,
|
|
954
|
+
output_index: Schema.Number,
|
|
955
|
+
content_index: Schema.Number,
|
|
956
|
+
annotation_index: Schema.Number,
|
|
957
|
+
sequence_number: Schema.Number,
|
|
958
|
+
annotation: Annotation
|
|
959
|
+
})
|
|
960
|
+
|
|
961
|
+
const ResponseReasoningSummaryPartAddedEvent = Schema.Struct({
|
|
962
|
+
type: Schema.Literal("response.reasoning_summary_part.added"),
|
|
963
|
+
item_id: Schema.String,
|
|
964
|
+
output_index: Schema.Number,
|
|
965
|
+
summary_index: Schema.Number,
|
|
966
|
+
sequence_number: Schema.Number,
|
|
967
|
+
part: SummaryTextContent
|
|
968
|
+
})
|
|
969
|
+
|
|
970
|
+
const ResponseReasoningSummaryPartDoneEvent = Schema.Struct({
|
|
971
|
+
type: Schema.Literal("response.reasoning_summary_part.done"),
|
|
972
|
+
item_id: Schema.String,
|
|
973
|
+
output_index: Schema.Number,
|
|
974
|
+
summary_index: Schema.Number,
|
|
975
|
+
sequence_number: Schema.Number,
|
|
976
|
+
part: SummaryTextContent
|
|
977
|
+
})
|
|
978
|
+
|
|
979
|
+
const ResponseReasoningSummaryTextDeltaEvent = Schema.Struct({
|
|
980
|
+
type: Schema.Literal("response.reasoning_summary_text.delta"),
|
|
981
|
+
item_id: Schema.String,
|
|
982
|
+
output_index: Schema.Number,
|
|
983
|
+
summary_index: Schema.Number,
|
|
984
|
+
delta: Schema.String,
|
|
985
|
+
sequence_number: Schema.Number
|
|
986
|
+
})
|
|
987
|
+
|
|
988
|
+
const ResponseFunctionCallArgumentsDeltaEvent = Schema.Struct({
|
|
989
|
+
type: Schema.Literal("response.function_call_arguments.delta"),
|
|
990
|
+
item_id: Schema.String,
|
|
991
|
+
output_index: Schema.Number,
|
|
992
|
+
sequence_number: Schema.Number,
|
|
993
|
+
delta: Schema.String
|
|
994
|
+
})
|
|
995
|
+
|
|
996
|
+
const ResponseFunctionCallArgumentsDoneEvent = Schema.Struct({
|
|
997
|
+
type: Schema.Literal("response.function_call_arguments.done"),
|
|
998
|
+
item_id: Schema.String,
|
|
999
|
+
output_index: Schema.Number,
|
|
1000
|
+
sequence_number: Schema.Number,
|
|
1001
|
+
arguments: Schema.String
|
|
1002
|
+
})
|
|
1003
|
+
|
|
1004
|
+
const ResponseCodeInterpreterCallCodeDeltaEvent = Schema.Struct({
|
|
1005
|
+
type: Schema.Literal("response.code_interpreter_call_code.delta"),
|
|
1006
|
+
item_id: Schema.String,
|
|
1007
|
+
output_index: Schema.Number,
|
|
1008
|
+
sequence_number: Schema.Number,
|
|
1009
|
+
delta: Schema.String
|
|
1010
|
+
})
|
|
1011
|
+
|
|
1012
|
+
const ResponseCodeInterpreterCallCodeDoneEvent = Schema.Struct({
|
|
1013
|
+
type: Schema.Literal("response.code_interpreter_call_code.done"),
|
|
1014
|
+
item_id: Schema.String,
|
|
1015
|
+
output_index: Schema.Number,
|
|
1016
|
+
sequence_number: Schema.Number,
|
|
1017
|
+
code: Schema.String
|
|
1018
|
+
})
|
|
1019
|
+
|
|
1020
|
+
const ResponseApplyPatchCallOperationDiffDeltaEvent = Schema.Struct({
|
|
1021
|
+
type: Schema.Literal("response.apply_patch_call_operation_diff.delta"),
|
|
1022
|
+
item_id: Schema.String,
|
|
1023
|
+
output_index: Schema.Number,
|
|
1024
|
+
sequence_number: Schema.Number,
|
|
1025
|
+
delta: Schema.String
|
|
1026
|
+
})
|
|
1027
|
+
|
|
1028
|
+
const ResponseApplyPatchCallOperationDiffDoneEvent = Schema.Struct({
|
|
1029
|
+
type: Schema.Literal("response.apply_patch_call_operation_diff.done"),
|
|
1030
|
+
item_id: Schema.String,
|
|
1031
|
+
output_index: Schema.Number,
|
|
1032
|
+
sequence_number: Schema.Number,
|
|
1033
|
+
delta: Schema.optionalKey(Schema.String)
|
|
1034
|
+
})
|
|
1035
|
+
|
|
1036
|
+
const ResponseImageGenerationCallPartialImageEvent = Schema.Struct({
|
|
1037
|
+
type: Schema.Literal("response.image_generation_call.partial_image"),
|
|
1038
|
+
item_id: Schema.String,
|
|
1039
|
+
output_index: Schema.Number,
|
|
1040
|
+
sequence_number: Schema.Number,
|
|
1041
|
+
partial_image_b64: Schema.String
|
|
1042
|
+
})
|
|
1043
|
+
|
|
1044
|
+
const ResponseErrorEvent = Schema.Struct({
|
|
1045
|
+
type: Schema.Literal("error"),
|
|
1046
|
+
code: Schema.NullOr(Schema.String),
|
|
1047
|
+
message: Schema.String,
|
|
1048
|
+
param: Schema.NullOr(Schema.String),
|
|
1049
|
+
sequence_number: Schema.Number,
|
|
1050
|
+
status: Schema.optionalKey(Schema.Number)
|
|
1051
|
+
})
|
|
1052
|
+
|
|
1053
|
+
const knownResponseStreamEventTypes = new Set([
|
|
1054
|
+
"response.created",
|
|
1055
|
+
"response.completed",
|
|
1056
|
+
"response.incomplete",
|
|
1057
|
+
"response.failed",
|
|
1058
|
+
"response.output_item.added",
|
|
1059
|
+
"response.output_item.done",
|
|
1060
|
+
"response.output_text.delta",
|
|
1061
|
+
"response.output_text.annotation.added",
|
|
1062
|
+
"response.reasoning_summary_part.added",
|
|
1063
|
+
"response.reasoning_summary_part.done",
|
|
1064
|
+
"response.reasoning_summary_text.delta",
|
|
1065
|
+
"response.function_call_arguments.delta",
|
|
1066
|
+
"response.function_call_arguments.done",
|
|
1067
|
+
"response.code_interpreter_call_code.delta",
|
|
1068
|
+
"response.code_interpreter_call_code.done",
|
|
1069
|
+
"response.apply_patch_call_operation_diff.delta",
|
|
1070
|
+
"response.apply_patch_call_operation_diff.done",
|
|
1071
|
+
"response.image_generation_call.partial_image",
|
|
1072
|
+
"error"
|
|
1073
|
+
])
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* Fallback event shape for future or provider-specific response stream events.
|
|
1077
|
+
*
|
|
1078
|
+
* @category models
|
|
1079
|
+
* @since 4.0.0
|
|
1080
|
+
*/
|
|
1081
|
+
export type UnknownResponseStreamEvent = {
|
|
1082
|
+
readonly type: string
|
|
1083
|
+
readonly [key: string]: unknown
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
const UnknownResponseStreamEvent = Schema.declare<UnknownResponseStreamEvent>(
|
|
1087
|
+
(value): value is UnknownResponseStreamEvent =>
|
|
1088
|
+
Predicate.hasProperty(value, "type") &&
|
|
1089
|
+
typeof value.type === "string" &&
|
|
1090
|
+
!knownResponseStreamEventTypes.has(value.type),
|
|
1091
|
+
{
|
|
1092
|
+
identifier: "UnknownResponseStreamEvent",
|
|
1093
|
+
description: "Fallback for unknown future stream events"
|
|
1094
|
+
}
|
|
1095
|
+
)
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* Schema for server-sent event shapes emitted by OpenAI Responses API streams.
|
|
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
|
+
*
|
|
1118
|
+
* @category schemas
|
|
1119
|
+
* @since 4.0.0
|
|
1120
|
+
*/
|
|
1121
|
+
export const ResponseStreamEvent = Schema.Union([
|
|
1122
|
+
ResponseCreatedEvent,
|
|
1123
|
+
ResponseCompletedEvent,
|
|
1124
|
+
ResponseIncompleteEvent,
|
|
1125
|
+
ResponseFailedEvent,
|
|
1126
|
+
ResponseOutputItemAddedEvent,
|
|
1127
|
+
ResponseOutputItemDoneEvent,
|
|
1128
|
+
ResponseOutputTextDeltaEvent,
|
|
1129
|
+
ResponseOutputTextAnnotationAddedEvent,
|
|
1130
|
+
ResponseReasoningSummaryPartAddedEvent,
|
|
1131
|
+
ResponseReasoningSummaryPartDoneEvent,
|
|
1132
|
+
ResponseReasoningSummaryTextDeltaEvent,
|
|
1133
|
+
ResponseFunctionCallArgumentsDeltaEvent,
|
|
1134
|
+
ResponseFunctionCallArgumentsDoneEvent,
|
|
1135
|
+
ResponseCodeInterpreterCallCodeDeltaEvent,
|
|
1136
|
+
ResponseCodeInterpreterCallCodeDoneEvent,
|
|
1137
|
+
ResponseApplyPatchCallOperationDiffDeltaEvent,
|
|
1138
|
+
ResponseApplyPatchCallOperationDiffDoneEvent,
|
|
1139
|
+
ResponseImageGenerationCallPartialImageEvent,
|
|
1140
|
+
ResponseErrorEvent,
|
|
1141
|
+
UnknownResponseStreamEvent
|
|
1142
|
+
])
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Server-sent event shape emitted by OpenAI Responses API streams.
|
|
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
|
+
*
|
|
1156
|
+
* @category models
|
|
1157
|
+
* @since 4.0.0
|
|
1158
|
+
*/
|
|
1159
|
+
export type ResponseStreamEvent = typeof ResponseStreamEvent.Type
|
|
1160
|
+
|
|
1161
|
+
/**
|
|
1162
|
+
* Schema for one embedding item returned by the OpenAI embeddings API.
|
|
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
|
+
*
|
|
1174
|
+
* @category schemas
|
|
1175
|
+
* @since 4.0.0
|
|
1176
|
+
*/
|
|
1177
|
+
export const Embedding = Schema.Struct({
|
|
1178
|
+
embedding: Schema.Union([
|
|
1179
|
+
Schema.Array(Schema.Number),
|
|
1180
|
+
Schema.String
|
|
1181
|
+
]),
|
|
1182
|
+
index: Schema.Number,
|
|
1183
|
+
object: Schema.optionalKey(Schema.String)
|
|
1184
|
+
})
|
|
1185
|
+
|
|
1186
|
+
/**
|
|
1187
|
+
* One embedding item returned by the OpenAI embeddings API.
|
|
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
|
+
*
|
|
1194
|
+
* @category models
|
|
1195
|
+
* @since 4.0.0
|
|
1196
|
+
*/
|
|
1197
|
+
export type Embedding = typeof Embedding.Type
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Schema for the request payload sent to the OpenAI embeddings endpoint.
|
|
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
|
+
*
|
|
1214
|
+
* @category schemas
|
|
1215
|
+
* @since 4.0.0
|
|
1216
|
+
*/
|
|
1217
|
+
export const CreateEmbeddingRequest = Schema.Struct({
|
|
1218
|
+
input: Schema.Union([
|
|
1219
|
+
Schema.String,
|
|
1220
|
+
Schema.Array(Schema.String),
|
|
1221
|
+
Schema.Array(Schema.Number),
|
|
1222
|
+
Schema.Array(Schema.Array(Schema.Number))
|
|
1223
|
+
]),
|
|
1224
|
+
model: Schema.String,
|
|
1225
|
+
encoding_format: Schema.optionalKey(Schema.Literals(["float", "base64"])),
|
|
1226
|
+
dimensions: Schema.optionalKey(Schema.Number),
|
|
1227
|
+
user: Schema.optionalKey(Schema.String)
|
|
1228
|
+
})
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* Request payload sent to the OpenAI embeddings endpoint.
|
|
1232
|
+
*
|
|
1233
|
+
* @category models
|
|
1234
|
+
* @since 4.0.0
|
|
1235
|
+
*/
|
|
1236
|
+
export type CreateEmbeddingRequest = typeof CreateEmbeddingRequest.Type
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
* Schema for a successful response payload returned by the OpenAI embeddings endpoint.
|
|
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
|
+
*
|
|
1259
|
+
* @category schemas
|
|
1260
|
+
* @since 4.0.0
|
|
1261
|
+
*/
|
|
1262
|
+
export const CreateEmbeddingResponse = Schema.Struct({
|
|
1263
|
+
data: Schema.Array(Embedding),
|
|
1264
|
+
model: Schema.String,
|
|
1265
|
+
object: Schema.optionalKey(Schema.Literal("list")),
|
|
1266
|
+
usage: Schema.optionalKey(
|
|
1267
|
+
Schema.Struct({
|
|
1268
|
+
prompt_tokens: Schema.Number,
|
|
1269
|
+
total_tokens: Schema.Number
|
|
1270
|
+
})
|
|
1271
|
+
)
|
|
1272
|
+
})
|
|
1273
|
+
|
|
1274
|
+
/**
|
|
1275
|
+
* Successful response payload returned by the OpenAI embeddings endpoint.
|
|
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
|
+
*
|
|
1286
|
+
* @category models
|
|
1287
|
+
* @since 4.0.0
|
|
1288
|
+
*/
|
|
1289
|
+
export type CreateEmbeddingResponse = typeof CreateEmbeddingResponse.Type
|