1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3package shared
4
5import (
6 "encoding/json"
7
8 "github.com/openai/openai-go/internal/apijson"
9 "github.com/openai/openai-go/packages/param"
10 "github.com/openai/openai-go/packages/respjson"
11 "github.com/openai/openai-go/shared/constant"
12)
13
14// aliased to make [param.APIUnion] private when embedding
15type paramUnion = param.APIUnion
16type paramObj = param.APIObject
17
18type ChatModel = string
19type ResponsesModel = string
20
21// aliased to make [param.APIObject] private when embedding
22
23const (
24 ChatModelGPT4_1 ChatModel = "gpt-4.1"
25 ChatModelGPT4_1Mini ChatModel = "gpt-4.1-mini"
26 ChatModelGPT4_1Nano ChatModel = "gpt-4.1-nano"
27 ChatModelGPT4_1_2025_04_14 ChatModel = "gpt-4.1-2025-04-14"
28 ChatModelGPT4_1Mini2025_04_14 ChatModel = "gpt-4.1-mini-2025-04-14"
29 ChatModelGPT4_1Nano2025_04_14 ChatModel = "gpt-4.1-nano-2025-04-14"
30 ChatModelO4Mini ChatModel = "o4-mini"
31 ChatModelO4Mini2025_04_16 ChatModel = "o4-mini-2025-04-16"
32 ChatModelO3 ChatModel = "o3"
33 ChatModelO3_2025_04_16 ChatModel = "o3-2025-04-16"
34 ChatModelO3Mini ChatModel = "o3-mini"
35 ChatModelO3Mini2025_01_31 ChatModel = "o3-mini-2025-01-31"
36 ChatModelO1 ChatModel = "o1"
37 ChatModelO1_2024_12_17 ChatModel = "o1-2024-12-17"
38 ChatModelO1Preview ChatModel = "o1-preview"
39 ChatModelO1Preview2024_09_12 ChatModel = "o1-preview-2024-09-12"
40 ChatModelO1Mini ChatModel = "o1-mini"
41 ChatModelO1Mini2024_09_12 ChatModel = "o1-mini-2024-09-12"
42 ChatModelGPT4o ChatModel = "gpt-4o"
43 ChatModelGPT4o2024_11_20 ChatModel = "gpt-4o-2024-11-20"
44 ChatModelGPT4o2024_08_06 ChatModel = "gpt-4o-2024-08-06"
45 ChatModelGPT4o2024_05_13 ChatModel = "gpt-4o-2024-05-13"
46 ChatModelGPT4oAudioPreview ChatModel = "gpt-4o-audio-preview"
47 ChatModelGPT4oAudioPreview2024_10_01 ChatModel = "gpt-4o-audio-preview-2024-10-01"
48 ChatModelGPT4oAudioPreview2024_12_17 ChatModel = "gpt-4o-audio-preview-2024-12-17"
49 ChatModelGPT4oAudioPreview2025_06_03 ChatModel = "gpt-4o-audio-preview-2025-06-03"
50 ChatModelGPT4oMiniAudioPreview ChatModel = "gpt-4o-mini-audio-preview"
51 ChatModelGPT4oMiniAudioPreview2024_12_17 ChatModel = "gpt-4o-mini-audio-preview-2024-12-17"
52 ChatModelGPT4oSearchPreview ChatModel = "gpt-4o-search-preview"
53 ChatModelGPT4oMiniSearchPreview ChatModel = "gpt-4o-mini-search-preview"
54 ChatModelGPT4oSearchPreview2025_03_11 ChatModel = "gpt-4o-search-preview-2025-03-11"
55 ChatModelGPT4oMiniSearchPreview2025_03_11 ChatModel = "gpt-4o-mini-search-preview-2025-03-11"
56 ChatModelChatgpt4oLatest ChatModel = "chatgpt-4o-latest"
57 ChatModelCodexMiniLatest ChatModel = "codex-mini-latest"
58 ChatModelGPT4oMini ChatModel = "gpt-4o-mini"
59 ChatModelGPT4oMini2024_07_18 ChatModel = "gpt-4o-mini-2024-07-18"
60 ChatModelGPT4Turbo ChatModel = "gpt-4-turbo"
61 ChatModelGPT4Turbo2024_04_09 ChatModel = "gpt-4-turbo-2024-04-09"
62 ChatModelGPT4_0125Preview ChatModel = "gpt-4-0125-preview"
63 ChatModelGPT4TurboPreview ChatModel = "gpt-4-turbo-preview"
64 ChatModelGPT4_1106Preview ChatModel = "gpt-4-1106-preview"
65 ChatModelGPT4VisionPreview ChatModel = "gpt-4-vision-preview"
66 ChatModelGPT4 ChatModel = "gpt-4"
67 ChatModelGPT4_0314 ChatModel = "gpt-4-0314"
68 ChatModelGPT4_0613 ChatModel = "gpt-4-0613"
69 ChatModelGPT4_32k ChatModel = "gpt-4-32k"
70 ChatModelGPT4_32k0314 ChatModel = "gpt-4-32k-0314"
71 ChatModelGPT4_32k0613 ChatModel = "gpt-4-32k-0613"
72 ChatModelGPT3_5Turbo ChatModel = "gpt-3.5-turbo"
73 ChatModelGPT3_5Turbo16k ChatModel = "gpt-3.5-turbo-16k"
74 ChatModelGPT3_5Turbo0301 ChatModel = "gpt-3.5-turbo-0301"
75 ChatModelGPT3_5Turbo0613 ChatModel = "gpt-3.5-turbo-0613"
76 ChatModelGPT3_5Turbo1106 ChatModel = "gpt-3.5-turbo-1106"
77 ChatModelGPT3_5Turbo0125 ChatModel = "gpt-3.5-turbo-0125"
78 ChatModelGPT3_5Turbo16k0613 ChatModel = "gpt-3.5-turbo-16k-0613"
79)
80
81// A filter used to compare a specified attribute key to a given value using a
82// defined comparison operation.
83type ComparisonFilter struct {
84 // The key to compare against the value.
85 Key string `json:"key,required"`
86 // Specifies the comparison operator: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`.
87 //
88 // - `eq`: equals
89 // - `ne`: not equal
90 // - `gt`: greater than
91 // - `gte`: greater than or equal
92 // - `lt`: less than
93 // - `lte`: less than or equal
94 //
95 // Any of "eq", "ne", "gt", "gte", "lt", "lte".
96 Type ComparisonFilterType `json:"type,required"`
97 // The value to compare against the attribute key; supports string, number, or
98 // boolean types.
99 Value ComparisonFilterValueUnion `json:"value,required"`
100 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
101 JSON struct {
102 Key respjson.Field
103 Type respjson.Field
104 Value respjson.Field
105 ExtraFields map[string]respjson.Field
106 raw string
107 } `json:"-"`
108}
109
110// Returns the unmodified JSON received from the API
111func (r ComparisonFilter) RawJSON() string { return r.JSON.raw }
112func (r *ComparisonFilter) UnmarshalJSON(data []byte) error {
113 return apijson.UnmarshalRoot(data, r)
114}
115
116// ToParam converts this ComparisonFilter to a ComparisonFilterParam.
117//
118// Warning: the fields of the param type will not be present. ToParam should only
119// be used at the last possible moment before sending a request. Test for this with
120// ComparisonFilterParam.Overrides()
121func (r ComparisonFilter) ToParam() ComparisonFilterParam {
122 return param.Override[ComparisonFilterParam](json.RawMessage(r.RawJSON()))
123}
124
125// Specifies the comparison operator: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`.
126//
127// - `eq`: equals
128// - `ne`: not equal
129// - `gt`: greater than
130// - `gte`: greater than or equal
131// - `lt`: less than
132// - `lte`: less than or equal
133type ComparisonFilterType string
134
135const (
136 ComparisonFilterTypeEq ComparisonFilterType = "eq"
137 ComparisonFilterTypeNe ComparisonFilterType = "ne"
138 ComparisonFilterTypeGt ComparisonFilterType = "gt"
139 ComparisonFilterTypeGte ComparisonFilterType = "gte"
140 ComparisonFilterTypeLt ComparisonFilterType = "lt"
141 ComparisonFilterTypeLte ComparisonFilterType = "lte"
142)
143
144// ComparisonFilterValueUnion contains all possible properties and values from
145// [string], [float64], [bool].
146//
147// Use the methods beginning with 'As' to cast the union to one of its variants.
148//
149// If the underlying value is not a json object, one of the following properties
150// will be valid: OfString OfFloat OfBool]
151type ComparisonFilterValueUnion struct {
152 // This field will be present if the value is a [string] instead of an object.
153 OfString string `json:",inline"`
154 // This field will be present if the value is a [float64] instead of an object.
155 OfFloat float64 `json:",inline"`
156 // This field will be present if the value is a [bool] instead of an object.
157 OfBool bool `json:",inline"`
158 JSON struct {
159 OfString respjson.Field
160 OfFloat respjson.Field
161 OfBool respjson.Field
162 raw string
163 } `json:"-"`
164}
165
166func (u ComparisonFilterValueUnion) AsString() (v string) {
167 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
168 return
169}
170
171func (u ComparisonFilterValueUnion) AsFloat() (v float64) {
172 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
173 return
174}
175
176func (u ComparisonFilterValueUnion) AsBool() (v bool) {
177 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
178 return
179}
180
181// Returns the unmodified JSON received from the API
182func (u ComparisonFilterValueUnion) RawJSON() string { return u.JSON.raw }
183
184func (r *ComparisonFilterValueUnion) UnmarshalJSON(data []byte) error {
185 return apijson.UnmarshalRoot(data, r)
186}
187
188// A filter used to compare a specified attribute key to a given value using a
189// defined comparison operation.
190//
191// The properties Key, Type, Value are required.
192type ComparisonFilterParam struct {
193 // The key to compare against the value.
194 Key string `json:"key,required"`
195 // Specifies the comparison operator: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`.
196 //
197 // - `eq`: equals
198 // - `ne`: not equal
199 // - `gt`: greater than
200 // - `gte`: greater than or equal
201 // - `lt`: less than
202 // - `lte`: less than or equal
203 //
204 // Any of "eq", "ne", "gt", "gte", "lt", "lte".
205 Type ComparisonFilterType `json:"type,omitzero,required"`
206 // The value to compare against the attribute key; supports string, number, or
207 // boolean types.
208 Value ComparisonFilterValueUnionParam `json:"value,omitzero,required"`
209 paramObj
210}
211
212func (r ComparisonFilterParam) MarshalJSON() (data []byte, err error) {
213 type shadow ComparisonFilterParam
214 return param.MarshalObject(r, (*shadow)(&r))
215}
216func (r *ComparisonFilterParam) UnmarshalJSON(data []byte) error {
217 return apijson.UnmarshalRoot(data, r)
218}
219
220// Only one field can be non-zero.
221//
222// Use [param.IsOmitted] to confirm if a field is set.
223type ComparisonFilterValueUnionParam struct {
224 OfString param.Opt[string] `json:",omitzero,inline"`
225 OfFloat param.Opt[float64] `json:",omitzero,inline"`
226 OfBool param.Opt[bool] `json:",omitzero,inline"`
227 paramUnion
228}
229
230func (u ComparisonFilterValueUnionParam) MarshalJSON() ([]byte, error) {
231 return param.MarshalUnion(u, u.OfString, u.OfFloat, u.OfBool)
232}
233func (u *ComparisonFilterValueUnionParam) UnmarshalJSON(data []byte) error {
234 return apijson.UnmarshalRoot(data, u)
235}
236
237func (u *ComparisonFilterValueUnionParam) asAny() any {
238 if !param.IsOmitted(u.OfString) {
239 return &u.OfString.Value
240 } else if !param.IsOmitted(u.OfFloat) {
241 return &u.OfFloat.Value
242 } else if !param.IsOmitted(u.OfBool) {
243 return &u.OfBool.Value
244 }
245 return nil
246}
247
248// Combine multiple filters using `and` or `or`.
249type CompoundFilter struct {
250 // Array of filters to combine. Items can be `ComparisonFilter` or
251 // `CompoundFilter`.
252 Filters []ComparisonFilter `json:"filters,required"`
253 // Type of operation: `and` or `or`.
254 //
255 // Any of "and", "or".
256 Type CompoundFilterType `json:"type,required"`
257 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
258 JSON struct {
259 Filters respjson.Field
260 Type respjson.Field
261 ExtraFields map[string]respjson.Field
262 raw string
263 } `json:"-"`
264}
265
266// Returns the unmodified JSON received from the API
267func (r CompoundFilter) RawJSON() string { return r.JSON.raw }
268func (r *CompoundFilter) UnmarshalJSON(data []byte) error {
269 return apijson.UnmarshalRoot(data, r)
270}
271
272// ToParam converts this CompoundFilter to a CompoundFilterParam.
273//
274// Warning: the fields of the param type will not be present. ToParam should only
275// be used at the last possible moment before sending a request. Test for this with
276// CompoundFilterParam.Overrides()
277func (r CompoundFilter) ToParam() CompoundFilterParam {
278 return param.Override[CompoundFilterParam](json.RawMessage(r.RawJSON()))
279}
280
281// Type of operation: `and` or `or`.
282type CompoundFilterType string
283
284const (
285 CompoundFilterTypeAnd CompoundFilterType = "and"
286 CompoundFilterTypeOr CompoundFilterType = "or"
287)
288
289// Combine multiple filters using `and` or `or`.
290//
291// The properties Filters, Type are required.
292type CompoundFilterParam struct {
293 // Array of filters to combine. Items can be `ComparisonFilter` or
294 // `CompoundFilter`.
295 Filters []ComparisonFilterParam `json:"filters,omitzero,required"`
296 // Type of operation: `and` or `or`.
297 //
298 // Any of "and", "or".
299 Type CompoundFilterType `json:"type,omitzero,required"`
300 paramObj
301}
302
303func (r CompoundFilterParam) MarshalJSON() (data []byte, err error) {
304 type shadow CompoundFilterParam
305 return param.MarshalObject(r, (*shadow)(&r))
306}
307func (r *CompoundFilterParam) UnmarshalJSON(data []byte) error {
308 return apijson.UnmarshalRoot(data, r)
309}
310
311type ErrorObject struct {
312 Code string `json:"code,required"`
313 Message string `json:"message,required"`
314 Param string `json:"param,required"`
315 Type string `json:"type,required"`
316 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
317 JSON struct {
318 Code respjson.Field
319 Message respjson.Field
320 Param respjson.Field
321 Type respjson.Field
322 ExtraFields map[string]respjson.Field
323 raw string
324 } `json:"-"`
325}
326
327// Returns the unmodified JSON received from the API
328func (r ErrorObject) RawJSON() string { return r.JSON.raw }
329func (r *ErrorObject) UnmarshalJSON(data []byte) error {
330 return apijson.UnmarshalRoot(data, r)
331}
332
333type FunctionDefinition struct {
334 // The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
335 // underscores and dashes, with a maximum length of 64.
336 Name string `json:"name,required"`
337 // A description of what the function does, used by the model to choose when and
338 // how to call the function.
339 Description string `json:"description"`
340 // The parameters the functions accepts, described as a JSON Schema object. See the
341 // [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
342 // and the
343 // [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
344 // documentation about the format.
345 //
346 // Omitting `parameters` defines a function with an empty parameter list.
347 Parameters FunctionParameters `json:"parameters"`
348 // Whether to enable strict schema adherence when generating the function call. If
349 // set to true, the model will follow the exact schema defined in the `parameters`
350 // field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn
351 // more about Structured Outputs in the
352 // [function calling guide](docs/guides/function-calling).
353 Strict bool `json:"strict,nullable"`
354 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
355 JSON struct {
356 Name respjson.Field
357 Description respjson.Field
358 Parameters respjson.Field
359 Strict respjson.Field
360 ExtraFields map[string]respjson.Field
361 raw string
362 } `json:"-"`
363}
364
365// Returns the unmodified JSON received from the API
366func (r FunctionDefinition) RawJSON() string { return r.JSON.raw }
367func (r *FunctionDefinition) UnmarshalJSON(data []byte) error {
368 return apijson.UnmarshalRoot(data, r)
369}
370
371// ToParam converts this FunctionDefinition to a FunctionDefinitionParam.
372//
373// Warning: the fields of the param type will not be present. ToParam should only
374// be used at the last possible moment before sending a request. Test for this with
375// FunctionDefinitionParam.Overrides()
376func (r FunctionDefinition) ToParam() FunctionDefinitionParam {
377 return param.Override[FunctionDefinitionParam](json.RawMessage(r.RawJSON()))
378}
379
380// The property Name is required.
381type FunctionDefinitionParam struct {
382 // The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
383 // underscores and dashes, with a maximum length of 64.
384 Name string `json:"name,required"`
385 // Whether to enable strict schema adherence when generating the function call. If
386 // set to true, the model will follow the exact schema defined in the `parameters`
387 // field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn
388 // more about Structured Outputs in the
389 // [function calling guide](docs/guides/function-calling).
390 Strict param.Opt[bool] `json:"strict,omitzero"`
391 // A description of what the function does, used by the model to choose when and
392 // how to call the function.
393 Description param.Opt[string] `json:"description,omitzero"`
394 // The parameters the functions accepts, described as a JSON Schema object. See the
395 // [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
396 // and the
397 // [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
398 // documentation about the format.
399 //
400 // Omitting `parameters` defines a function with an empty parameter list.
401 Parameters FunctionParameters `json:"parameters,omitzero"`
402 paramObj
403}
404
405func (r FunctionDefinitionParam) MarshalJSON() (data []byte, err error) {
406 type shadow FunctionDefinitionParam
407 return param.MarshalObject(r, (*shadow)(&r))
408}
409func (r *FunctionDefinitionParam) UnmarshalJSON(data []byte) error {
410 return apijson.UnmarshalRoot(data, r)
411}
412
413type FunctionParameters map[string]any
414
415type Metadata map[string]string
416
417// **o-series models only**
418//
419// Configuration options for
420// [reasoning models](https://platform.openai.com/docs/guides/reasoning).
421type Reasoning struct {
422 // **o-series models only**
423 //
424 // Constrains effort on reasoning for
425 // [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
426 // supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
427 // result in faster responses and fewer tokens used on reasoning in a response.
428 //
429 // Any of "low", "medium", "high".
430 Effort ReasoningEffort `json:"effort,nullable"`
431 // **Deprecated:** use `summary` instead.
432 //
433 // A summary of the reasoning performed by the model. This can be useful for
434 // debugging and understanding the model's reasoning process. One of `auto`,
435 // `concise`, or `detailed`.
436 //
437 // Any of "auto", "concise", "detailed".
438 //
439 // Deprecated: deprecated
440 GenerateSummary ReasoningGenerateSummary `json:"generate_summary,nullable"`
441 // A summary of the reasoning performed by the model. This can be useful for
442 // debugging and understanding the model's reasoning process. One of `auto`,
443 // `concise`, or `detailed`.
444 //
445 // Any of "auto", "concise", "detailed".
446 Summary ReasoningSummary `json:"summary,nullable"`
447 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
448 JSON struct {
449 Effort respjson.Field
450 GenerateSummary respjson.Field
451 Summary respjson.Field
452 ExtraFields map[string]respjson.Field
453 raw string
454 } `json:"-"`
455}
456
457// Returns the unmodified JSON received from the API
458func (r Reasoning) RawJSON() string { return r.JSON.raw }
459func (r *Reasoning) UnmarshalJSON(data []byte) error {
460 return apijson.UnmarshalRoot(data, r)
461}
462
463// ToParam converts this Reasoning to a ReasoningParam.
464//
465// Warning: the fields of the param type will not be present. ToParam should only
466// be used at the last possible moment before sending a request. Test for this with
467// ReasoningParam.Overrides()
468func (r Reasoning) ToParam() ReasoningParam {
469 return param.Override[ReasoningParam](json.RawMessage(r.RawJSON()))
470}
471
472// **Deprecated:** use `summary` instead.
473//
474// A summary of the reasoning performed by the model. This can be useful for
475// debugging and understanding the model's reasoning process. One of `auto`,
476// `concise`, or `detailed`.
477type ReasoningGenerateSummary string
478
479const (
480 ReasoningGenerateSummaryAuto ReasoningGenerateSummary = "auto"
481 ReasoningGenerateSummaryConcise ReasoningGenerateSummary = "concise"
482 ReasoningGenerateSummaryDetailed ReasoningGenerateSummary = "detailed"
483)
484
485// A summary of the reasoning performed by the model. This can be useful for
486// debugging and understanding the model's reasoning process. One of `auto`,
487// `concise`, or `detailed`.
488type ReasoningSummary string
489
490const (
491 ReasoningSummaryAuto ReasoningSummary = "auto"
492 ReasoningSummaryConcise ReasoningSummary = "concise"
493 ReasoningSummaryDetailed ReasoningSummary = "detailed"
494)
495
496// **o-series models only**
497//
498// Configuration options for
499// [reasoning models](https://platform.openai.com/docs/guides/reasoning).
500type ReasoningParam struct {
501 // **o-series models only**
502 //
503 // Constrains effort on reasoning for
504 // [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
505 // supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
506 // result in faster responses and fewer tokens used on reasoning in a response.
507 //
508 // Any of "low", "medium", "high".
509 Effort ReasoningEffort `json:"effort,omitzero"`
510 // **Deprecated:** use `summary` instead.
511 //
512 // A summary of the reasoning performed by the model. This can be useful for
513 // debugging and understanding the model's reasoning process. One of `auto`,
514 // `concise`, or `detailed`.
515 //
516 // Any of "auto", "concise", "detailed".
517 //
518 // Deprecated: deprecated
519 GenerateSummary ReasoningGenerateSummary `json:"generate_summary,omitzero"`
520 // A summary of the reasoning performed by the model. This can be useful for
521 // debugging and understanding the model's reasoning process. One of `auto`,
522 // `concise`, or `detailed`.
523 //
524 // Any of "auto", "concise", "detailed".
525 Summary ReasoningSummary `json:"summary,omitzero"`
526 paramObj
527}
528
529func (r ReasoningParam) MarshalJSON() (data []byte, err error) {
530 type shadow ReasoningParam
531 return param.MarshalObject(r, (*shadow)(&r))
532}
533func (r *ReasoningParam) UnmarshalJSON(data []byte) error {
534 return apijson.UnmarshalRoot(data, r)
535}
536
537// **o-series models only**
538//
539// Constrains effort on reasoning for
540// [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
541// supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
542// result in faster responses and fewer tokens used on reasoning in a response.
543type ReasoningEffort string
544
545const (
546 ReasoningEffortLow ReasoningEffort = "low"
547 ReasoningEffortMedium ReasoningEffort = "medium"
548 ReasoningEffortHigh ReasoningEffort = "high"
549)
550
551// JSON object response format. An older method of generating JSON responses. Using
552// `json_schema` is recommended for models that support it. Note that the model
553// will not generate JSON without a system or user message instructing it to do so.
554type ResponseFormatJSONObject struct {
555 // The type of response format being defined. Always `json_object`.
556 Type constant.JSONObject `json:"type,required"`
557 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
558 JSON struct {
559 Type respjson.Field
560 ExtraFields map[string]respjson.Field
561 raw string
562 } `json:"-"`
563}
564
565// Returns the unmodified JSON received from the API
566func (r ResponseFormatJSONObject) RawJSON() string { return r.JSON.raw }
567func (r *ResponseFormatJSONObject) UnmarshalJSON(data []byte) error {
568 return apijson.UnmarshalRoot(data, r)
569}
570
571func (ResponseFormatJSONObject) ImplResponseFormatTextConfigUnion() {}
572
573// ToParam converts this ResponseFormatJSONObject to a
574// ResponseFormatJSONObjectParam.
575//
576// Warning: the fields of the param type will not be present. ToParam should only
577// be used at the last possible moment before sending a request. Test for this with
578// ResponseFormatJSONObjectParam.Overrides()
579func (r ResponseFormatJSONObject) ToParam() ResponseFormatJSONObjectParam {
580 return param.Override[ResponseFormatJSONObjectParam](json.RawMessage(r.RawJSON()))
581}
582
583func NewResponseFormatJSONObjectParam() ResponseFormatJSONObjectParam {
584 return ResponseFormatJSONObjectParam{
585 Type: "json_object",
586 }
587}
588
589// JSON object response format. An older method of generating JSON responses. Using
590// `json_schema` is recommended for models that support it. Note that the model
591// will not generate JSON without a system or user message instructing it to do so.
592//
593// This struct has a constant value, construct it with
594// [NewResponseFormatJSONObjectParam].
595type ResponseFormatJSONObjectParam struct {
596 // The type of response format being defined. Always `json_object`.
597 Type constant.JSONObject `json:"type,required"`
598 paramObj
599}
600
601func (r ResponseFormatJSONObjectParam) MarshalJSON() (data []byte, err error) {
602 type shadow ResponseFormatJSONObjectParam
603 return param.MarshalObject(r, (*shadow)(&r))
604}
605func (r *ResponseFormatJSONObjectParam) UnmarshalJSON(data []byte) error {
606 return apijson.UnmarshalRoot(data, r)
607}
608
609// JSON Schema response format. Used to generate structured JSON responses. Learn
610// more about
611// [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
612type ResponseFormatJSONSchema struct {
613 // Structured Outputs configuration options, including a JSON Schema.
614 JSONSchema ResponseFormatJSONSchemaJSONSchema `json:"json_schema,required"`
615 // The type of response format being defined. Always `json_schema`.
616 Type constant.JSONSchema `json:"type,required"`
617 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
618 JSON struct {
619 JSONSchema respjson.Field
620 Type respjson.Field
621 ExtraFields map[string]respjson.Field
622 raw string
623 } `json:"-"`
624}
625
626// Returns the unmodified JSON received from the API
627func (r ResponseFormatJSONSchema) RawJSON() string { return r.JSON.raw }
628func (r *ResponseFormatJSONSchema) UnmarshalJSON(data []byte) error {
629 return apijson.UnmarshalRoot(data, r)
630}
631
632// ToParam converts this ResponseFormatJSONSchema to a
633// ResponseFormatJSONSchemaParam.
634//
635// Warning: the fields of the param type will not be present. ToParam should only
636// be used at the last possible moment before sending a request. Test for this with
637// ResponseFormatJSONSchemaParam.Overrides()
638func (r ResponseFormatJSONSchema) ToParam() ResponseFormatJSONSchemaParam {
639 return param.Override[ResponseFormatJSONSchemaParam](json.RawMessage(r.RawJSON()))
640}
641
642// Structured Outputs configuration options, including a JSON Schema.
643type ResponseFormatJSONSchemaJSONSchema struct {
644 // The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores
645 // and dashes, with a maximum length of 64.
646 Name string `json:"name,required"`
647 // A description of what the response format is for, used by the model to determine
648 // how to respond in the format.
649 Description string `json:"description"`
650 // The schema for the response format, described as a JSON Schema object. Learn how
651 // to build JSON schemas [here](https://json-schema.org/).
652 Schema map[string]any `json:"schema"`
653 // Whether to enable strict schema adherence when generating the output. If set to
654 // true, the model will always follow the exact schema defined in the `schema`
655 // field. Only a subset of JSON Schema is supported when `strict` is `true`. To
656 // learn more, read the
657 // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
658 Strict bool `json:"strict,nullable"`
659 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
660 JSON struct {
661 Name respjson.Field
662 Description respjson.Field
663 Schema respjson.Field
664 Strict respjson.Field
665 ExtraFields map[string]respjson.Field
666 raw string
667 } `json:"-"`
668}
669
670// Returns the unmodified JSON received from the API
671func (r ResponseFormatJSONSchemaJSONSchema) RawJSON() string { return r.JSON.raw }
672func (r *ResponseFormatJSONSchemaJSONSchema) UnmarshalJSON(data []byte) error {
673 return apijson.UnmarshalRoot(data, r)
674}
675
676// JSON Schema response format. Used to generate structured JSON responses. Learn
677// more about
678// [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
679//
680// The properties JSONSchema, Type are required.
681type ResponseFormatJSONSchemaParam struct {
682 // Structured Outputs configuration options, including a JSON Schema.
683 JSONSchema ResponseFormatJSONSchemaJSONSchemaParam `json:"json_schema,omitzero,required"`
684 // The type of response format being defined. Always `json_schema`.
685 //
686 // This field can be elided, and will marshal its zero value as "json_schema".
687 Type constant.JSONSchema `json:"type,required"`
688 paramObj
689}
690
691func (r ResponseFormatJSONSchemaParam) MarshalJSON() (data []byte, err error) {
692 type shadow ResponseFormatJSONSchemaParam
693 return param.MarshalObject(r, (*shadow)(&r))
694}
695func (r *ResponseFormatJSONSchemaParam) UnmarshalJSON(data []byte) error {
696 return apijson.UnmarshalRoot(data, r)
697}
698
699// Structured Outputs configuration options, including a JSON Schema.
700//
701// The property Name is required.
702type ResponseFormatJSONSchemaJSONSchemaParam struct {
703 // The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores
704 // and dashes, with a maximum length of 64.
705 Name string `json:"name,required"`
706 // Whether to enable strict schema adherence when generating the output. If set to
707 // true, the model will always follow the exact schema defined in the `schema`
708 // field. Only a subset of JSON Schema is supported when `strict` is `true`. To
709 // learn more, read the
710 // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
711 Strict param.Opt[bool] `json:"strict,omitzero"`
712 // A description of what the response format is for, used by the model to determine
713 // how to respond in the format.
714 Description param.Opt[string] `json:"description,omitzero"`
715 // The schema for the response format, described as a JSON Schema object. Learn how
716 // to build JSON schemas [here](https://json-schema.org/).
717 Schema any `json:"schema,omitzero"`
718 paramObj
719}
720
721func (r ResponseFormatJSONSchemaJSONSchemaParam) MarshalJSON() (data []byte, err error) {
722 type shadow ResponseFormatJSONSchemaJSONSchemaParam
723 return param.MarshalObject(r, (*shadow)(&r))
724}
725func (r *ResponseFormatJSONSchemaJSONSchemaParam) UnmarshalJSON(data []byte) error {
726 return apijson.UnmarshalRoot(data, r)
727}
728
729// Default response format. Used to generate text responses.
730type ResponseFormatText struct {
731 // The type of response format being defined. Always `text`.
732 Type constant.Text `json:"type,required"`
733 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
734 JSON struct {
735 Type respjson.Field
736 ExtraFields map[string]respjson.Field
737 raw string
738 } `json:"-"`
739}
740
741// Returns the unmodified JSON received from the API
742func (r ResponseFormatText) RawJSON() string { return r.JSON.raw }
743func (r *ResponseFormatText) UnmarshalJSON(data []byte) error {
744 return apijson.UnmarshalRoot(data, r)
745}
746
747func (ResponseFormatText) ImplResponseFormatTextConfigUnion() {}
748
749// ToParam converts this ResponseFormatText to a ResponseFormatTextParam.
750//
751// Warning: the fields of the param type will not be present. ToParam should only
752// be used at the last possible moment before sending a request. Test for this with
753// ResponseFormatTextParam.Overrides()
754func (r ResponseFormatText) ToParam() ResponseFormatTextParam {
755 return param.Override[ResponseFormatTextParam](json.RawMessage(r.RawJSON()))
756}
757
758func NewResponseFormatTextParam() ResponseFormatTextParam {
759 return ResponseFormatTextParam{
760 Type: "text",
761 }
762}
763
764// Default response format. Used to generate text responses.
765//
766// This struct has a constant value, construct it with
767// [NewResponseFormatTextParam].
768type ResponseFormatTextParam struct {
769 // The type of response format being defined. Always `text`.
770 Type constant.Text `json:"type,required"`
771 paramObj
772}
773
774func (r ResponseFormatTextParam) MarshalJSON() (data []byte, err error) {
775 type shadow ResponseFormatTextParam
776 return param.MarshalObject(r, (*shadow)(&r))
777}
778func (r *ResponseFormatTextParam) UnmarshalJSON(data []byte) error {
779 return apijson.UnmarshalRoot(data, r)
780}
781
782// ResponsesModel also accepts any [string] or [ChatModel]
783
784const (
785 ResponsesModelO1Pro ResponsesModel = "o1-pro"
786 ResponsesModelO1Pro2025_03_19 ResponsesModel = "o1-pro-2025-03-19"
787 ResponsesModelO3Pro ResponsesModel = "o3-pro"
788 ResponsesModelO3Pro2025_06_10 ResponsesModel = "o3-pro-2025-06-10"
789 ResponsesModelO3DeepResearch ResponsesModel = "o3-deep-research"
790 ResponsesModelO3DeepResearch2025_06_26 ResponsesModel = "o3-deep-research-2025-06-26"
791 ResponsesModelO4MiniDeepResearch ResponsesModel = "o4-mini-deep-research"
792 ResponsesModelO4MiniDeepResearch2025_06_26 ResponsesModel = "o4-mini-deep-research-2025-06-26"
793 ResponsesModelComputerUsePreview ResponsesModel = "computer-use-preview"
794 ResponsesModelComputerUsePreview2025_03_11 ResponsesModel = "computer-use-preview-2025-03-11"
795 // Or some ...[ChatModel]
796)