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