@@ -4,11 +4,11 @@ package openai
44
55import (
66 "context"
7+ "encoding/json"
78 "errors"
89 "fmt"
910 "net/http"
1011 "net/url"
11− "reflect"
1212
1313 "github.com/openai/openai-go/internal/apijson"
1414 "github.com/openai/openai-go/internal/apiquery"
@@ -16,11 +16,10 @@ import (
1616 "github.com/openai/openai-go/option"
1717 "github.com/openai/openai-go/packages/pagination"
1818 "github.com/openai/openai-go/packages/param"
19− "github.com/openai/openai-go/packages/resp"
19+ "github.com/openai/openai-go/packages/respjson"
2020 "github.com/openai/openai-go/packages/ssestream"
2121 "github.com/openai/openai-go/shared"
2222 "github.com/openai/openai-go/shared/constant"
23− "github.com/tidwall/gjson"
2423)
2524
2625// ChatCompletionService contains methods and other services that help with
@@ -176,9 +175,25 @@ type ChatCompletion struct {
176175 Model string `json:"model,required"`
177176 // The object type, which is always `chat.completion`.
178177 Object constant.ChatCompletion `json:"object,required"`
179− // The service tier used for processing the request.
178+ // Specifies the processing type used for serving the request.
180179 //
181− // Any of "scale", "default".
180+ // - If set to 'auto', then the request will be processed with the service tier
181+ // configured in the Project settings. Unless otherwise configured, the Project
182+ // will use 'default'.
183+ // - If set to 'default', then the requset will be processed with the standard
184+ // pricing and performance for the selected model.
185+ // - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
186+ // 'priority', then the request will be processed with the corresponding service
187+ // tier. [Contact sales](https://openai.com/contact-sales) to learn more about
188+ // Priority processing.
189+ // - When not set, the default behavior is 'auto'.
190+ //
191+ // When the `service_tier` parameter is set, the response body will include the
192+ // `service_tier` value based on the processing mode actually used to serve the
193+ // request. This response value may be different from the value set in the
194+ // parameter.
195+ //
196+ // Any of "auto", "default", "flex", "scale", "priority".
182197 ServiceTier ChatCompletionServiceTier `json:"service_tier,nullable"`
183198 // This fingerprint represents the backend configuration that the model runs with.
184199 //
@@ -187,18 +202,17 @@ type ChatCompletion struct {
187202 SystemFingerprint string `json:"system_fingerprint"`
188203 // Usage statistics for the completion request.
189204 Usage CompletionUsage `json:"usage"`
190− // Metadata for the response, check the presence of optional fields with the
191− // [resp.Field.IsPresent] method.
205+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
192206 JSON struct {
193− ID resp.Field
194− Choices resp.Field
195− Created resp.Field
196− Model resp.Field
197− Object resp.Field
198− ServiceTier resp.Field
199− SystemFingerprint resp.Field
200− Usage resp.Field
201− ExtraFields map[string]resp.Field
207+ ID respjson.Field
208+ Choices respjson.Field
209+ Created respjson.Field
210+ Model respjson.Field
211+ Object respjson.Field
212+ ServiceTier respjson.Field
213+ SystemFingerprint respjson.Field
214+ Usage respjson.Field
215+ ExtraFields map[string]respjson.Field
202216 raw string
203217 } `json:"-"`
204218}
@@ -225,14 +239,13 @@ type ChatCompletionChoice struct {
225239 Logprobs ChatCompletionChoiceLogprobs `json:"logprobs,required"`
226240 // A chat completion message generated by the model.
227241 Message ChatCompletionMessage `json:"message,required"`
228− // Metadata for the response, check the presence of optional fields with the
229− // [resp.Field.IsPresent] method.
242+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
230243 JSON struct {
231− FinishReason resp.Field
232− Index resp.Field
233− Logprobs resp.Field
234− Message resp.Field
235− ExtraFields map[string]resp.Field
244+ FinishReason respjson.Field
245+ Index respjson.Field
246+ Logprobs respjson.Field
247+ Message respjson.Field
248+ ExtraFields map[string]respjson.Field
236249 raw string
237250 } `json:"-"`
238251}
@@ -249,12 +262,11 @@ type ChatCompletionChoiceLogprobs struct {
249262 Content []ChatCompletionTokenLogprob `json:"content,required"`
250263 // A list of message refusal tokens with log probability information.
251264 Refusal []ChatCompletionTokenLogprob `json:"refusal,required"`
252− // Metadata for the response, check the presence of optional fields with the
253− // [resp.Field.IsPresent] method.
265+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
254266 JSON struct {
255− Content resp.Field
256− Refusal resp.Field
257− ExtraFields map[string]resp.Field
267+ Content respjson.Field
268+ Refusal respjson.Field
269+ ExtraFields map[string]respjson.Field
258270 raw string
259271 } `json:"-"`
260272}
@@ -265,12 +277,31 @@ func (r *ChatCompletionChoiceLogprobs) UnmarshalJSON(data []byte) error {
265277 return apijson.UnmarshalRoot(data, r)
266278}
267279
268−// The service tier used for processing the request.
280+// Specifies the processing type used for serving the request.
281+//
282+// - If set to 'auto', then the request will be processed with the service tier
283+// configured in the Project settings. Unless otherwise configured, the Project
284+// will use 'default'.
285+// - If set to 'default', then the requset will be processed with the standard
286+// pricing and performance for the selected model.
287+// - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
288+// 'priority', then the request will be processed with the corresponding service
289+// tier. [Contact sales](https://openai.com/contact-sales) to learn more about
290+// Priority processing.
291+// - When not set, the default behavior is 'auto'.
292+//
293+// When the `service_tier` parameter is set, the response body will include the
294+// `service_tier` value based on the processing mode actually used to serve the
295+// request. This response value may be different from the value set in the
296+// parameter.
269297type ChatCompletionServiceTier string
270298
271299const (
272− ChatCompletionServiceTierScale ChatCompletionServiceTier = "scale"
273− ChatCompletionServiceTierDefault ChatCompletionServiceTier = "default"
300+ ChatCompletionServiceTierAuto ChatCompletionServiceTier = "auto"
301+ ChatCompletionServiceTierDefault ChatCompletionServiceTier = "default"
302+ ChatCompletionServiceTierFlex ChatCompletionServiceTier = "flex"
303+ ChatCompletionServiceTierScale ChatCompletionServiceTier = "scale"
304+ ChatCompletionServiceTierPriority ChatCompletionServiceTier = "priority"
274305)
275306
276307// Messages sent by the model in response to user messages.
@@ -302,15 +333,13 @@ type ChatCompletionAssistantMessageParam struct {
302333 paramObj
303334}
304335
305−// IsPresent returns true if the field's value is not omitted and not the JSON
306−// "null". To check if this field is omitted, use [param.IsOmitted].
307−func (f ChatCompletionAssistantMessageParam) IsPresent() bool {
308− return !param.IsOmitted(f) && !f.IsNull()
309−}
310336func (r ChatCompletionAssistantMessageParam) MarshalJSON() (data []byte, err error) {
311337 type shadow ChatCompletionAssistantMessageParam
312338 return param.MarshalObject(r, (*shadow)(&r))
313339}
340+func (r *ChatCompletionAssistantMessageParam) UnmarshalJSON(data []byte) error {
341+ return apijson.UnmarshalRoot(data, r)
342+}
314343
315344// Data about a previous audio response from the model.
316345// [Learn more](https://platform.openai.com/docs/guides/audio).
@@ -322,15 +351,13 @@ type ChatCompletionAssistantMessageParamAudio struct {
322351 paramObj
323352}
324353
325−// IsPresent returns true if the field's value is not omitted and not the JSON
326−// "null". To check if this field is omitted, use [param.IsOmitted].
327−func (f ChatCompletionAssistantMessageParamAudio) IsPresent() bool {
328− return !param.IsOmitted(f) && !f.IsNull()
329−}
330354func (r ChatCompletionAssistantMessageParamAudio) MarshalJSON() (data []byte, err error) {
331355 type shadow ChatCompletionAssistantMessageParamAudio
332356 return param.MarshalObject(r, (*shadow)(&r))
333357}
358+func (r *ChatCompletionAssistantMessageParamAudio) UnmarshalJSON(data []byte) error {
359+ return apijson.UnmarshalRoot(data, r)
360+}
334361
335362// Only one field can be non-zero.
336363//
@@ -341,13 +368,11 @@ type ChatCompletionAssistantMessageParamContentUnion struct {
341368 paramUnion
342369}
343370
344−// IsPresent returns true if the field's value is not omitted and not the JSON
345−// "null". To check if this field is omitted, use [param.IsOmitted].
346−func (u ChatCompletionAssistantMessageParamContentUnion) IsPresent() bool {
347− return !param.IsOmitted(u) && !u.IsNull()
348−}
349371func (u ChatCompletionAssistantMessageParamContentUnion) MarshalJSON() ([]byte, error) {
350− return param.MarshalUnion[ChatCompletionAssistantMessageParamContentUnion](u.OfString, u.OfArrayOfContentParts)
372+ return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
373+}
374+func (u *ChatCompletionAssistantMessageParamContentUnion) UnmarshalJSON(data []byte) error {
375+ return apijson.UnmarshalRoot(data, u)
351376}
352377
353378func (u *ChatCompletionAssistantMessageParamContentUnion) asAny() any {
@@ -368,13 +393,11 @@ type ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion struct {
368393 paramUnion
369394}
370395
371−// IsPresent returns true if the field's value is not omitted and not the JSON
372−// "null". To check if this field is omitted, use [param.IsOmitted].
373−func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) IsPresent() bool {
374− return !param.IsOmitted(u) && !u.IsNull()
375−}
376396func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) MarshalJSON() ([]byte, error) {
377− return param.MarshalUnion[ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion](u.OfText, u.OfRefusal)
397+ return param.MarshalUnion(u, u.OfText, u.OfRefusal)
398+}
399+func (u *ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) UnmarshalJSON(data []byte) error {
400+ return apijson.UnmarshalRoot(data, u)
378401}
379402
380403func (u *ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) asAny() any {
@@ -415,16 +438,8 @@ func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetTy
415438func init() {
416439 apijson.RegisterUnion[ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion](
417440 "type",
418− apijson.UnionVariant{
419− TypeFilter: gjson.JSON,
420− Type: reflect.TypeOf(ChatCompletionContentPartTextParam{}),
421− DiscriminatorValue: "text",
422− },
423− apijson.UnionVariant{
424− TypeFilter: gjson.JSON,
425− Type: reflect.TypeOf(ChatCompletionContentPartRefusalParam{}),
426− DiscriminatorValue: "refusal",
427− },
441+ apijson.Discriminator[ChatCompletionContentPartTextParam]("text"),
442+ apijson.Discriminator[ChatCompletionContentPartRefusalParam]("refusal"),
428443 )
429444}
430445
@@ -445,15 +460,13 @@ type ChatCompletionAssistantMessageParamFunctionCall struct {
445460 paramObj
446461}
447462
448−// IsPresent returns true if the field's value is not omitted and not the JSON
449−// "null". To check if this field is omitted, use [param.IsOmitted].
450−func (f ChatCompletionAssistantMessageParamFunctionCall) IsPresent() bool {
451− return !param.IsOmitted(f) && !f.IsNull()
452−}
453463func (r ChatCompletionAssistantMessageParamFunctionCall) MarshalJSON() (data []byte, err error) {
454464 type shadow ChatCompletionAssistantMessageParamFunctionCall
455465 return param.MarshalObject(r, (*shadow)(&r))
456466}
467+func (r *ChatCompletionAssistantMessageParamFunctionCall) UnmarshalJSON(data []byte) error {
468+ return apijson.UnmarshalRoot(data, r)
469+}
457470
458471// If the audio output modality is requested, this object contains data about the
459472// audio response from the model.
@@ -469,14 +482,13 @@ type ChatCompletionAudio struct {
469482 ExpiresAt int64 `json:"expires_at,required"`
470483 // Transcript of the audio generated by the model.
471484 Transcript string `json:"transcript,required"`
472− // Metadata for the response, check the presence of optional fields with the
473− // [resp.Field.IsPresent] method.
485+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
474486 JSON struct {
475− ID resp.Field
476− Data resp.Field
477− ExpiresAt resp.Field
478− Transcript resp.Field
479− ExtraFields map[string]resp.Field
487+ ID respjson.Field
488+ Data respjson.Field
489+ ExpiresAt respjson.Field
490+ Transcript respjson.Field
491+ ExtraFields map[string]respjson.Field
480492 raw string
481493 } `json:"-"`
482494}
@@ -496,23 +508,21 @@ type ChatCompletionAudioParam struct {
496508 // Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
497509 // or `pcm16`.
498510 //
499− // Any of "wav", "mp3", "flac", "opus", "pcm16".
511+ // Any of "wav", "aac", "mp3", "flac", "opus", "pcm16".
500512 Format ChatCompletionAudioParamFormat `json:"format,omitzero,required"`
501513 // The voice the model uses to respond. Supported voices are `alloy`, `ash`,
502− // `ballad`, `coral`, `echo`, `sage`, and `shimmer`.
503− //
504− // Any of "alloy", "ash", "ballad", "coral", "echo", "sage", "shimmer", "verse".
514+ // `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, and `shimmer`.
505515 Voice ChatCompletionAudioParamVoice `json:"voice,omitzero,required"`
506516 paramObj
507517}
508518
509−// IsPresent returns true if the field's value is not omitted and not the JSON
510−// "null". To check if this field is omitted, use [param.IsOmitted].
511−func (f ChatCompletionAudioParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
512519func (r ChatCompletionAudioParam) MarshalJSON() (data []byte, err error) {
513520 type shadow ChatCompletionAudioParam
514521 return param.MarshalObject(r, (*shadow)(&r))
515522}
523+func (r *ChatCompletionAudioParam) UnmarshalJSON(data []byte) error {
524+ return apijson.UnmarshalRoot(data, r)
525+}
516526
517527// Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
518528// or `pcm16`.
@@ -520,6 +530,7 @@ type ChatCompletionAudioParamFormat string
520530
521531const (
522532 ChatCompletionAudioParamFormatWAV ChatCompletionAudioParamFormat = "wav"
533+ ChatCompletionAudioParamFormatAAC ChatCompletionAudioParamFormat = "aac"
523534 ChatCompletionAudioParamFormatMP3 ChatCompletionAudioParamFormat = "mp3"
524535 ChatCompletionAudioParamFormatFLAC ChatCompletionAudioParamFormat = "flac"
525536 ChatCompletionAudioParamFormatOpus ChatCompletionAudioParamFormat = "opus"
@@ -527,7 +538,7 @@ const (
527538)
528539
529540// The voice the model uses to respond. Supported voices are `alloy`, `ash`,
530−// `ballad`, `coral`, `echo`, `sage`, and `shimmer`.
541+// `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, and `shimmer`.
531542type ChatCompletionAudioParamVoice string
532543
533544const (
@@ -536,6 +547,9 @@ const (
536547 ChatCompletionAudioParamVoiceBallad ChatCompletionAudioParamVoice = "ballad"
537548 ChatCompletionAudioParamVoiceCoral ChatCompletionAudioParamVoice = "coral"
538549 ChatCompletionAudioParamVoiceEcho ChatCompletionAudioParamVoice = "echo"
550+ ChatCompletionAudioParamVoiceFable ChatCompletionAudioParamVoice = "fable"
551+ ChatCompletionAudioParamVoiceOnyx ChatCompletionAudioParamVoice = "onyx"
552+ ChatCompletionAudioParamVoiceNova ChatCompletionAudioParamVoice = "nova"
539553 ChatCompletionAudioParamVoiceSage ChatCompletionAudioParamVoice = "sage"
540554 ChatCompletionAudioParamVoiceShimmer ChatCompletionAudioParamVoice = "shimmer"
541555 ChatCompletionAudioParamVoiceVerse ChatCompletionAudioParamVoice = "verse"
@@ -558,9 +572,25 @@ type ChatCompletionChunk struct {
558572 Model string `json:"model,required"`
559573 // The object type, which is always `chat.completion.chunk`.
560574 Object constant.ChatCompletionChunk `json:"object,required"`
561− // The service tier used for processing the request.
575+ // Specifies the processing type used for serving the request.
576+ //
577+ // - If set to 'auto', then the request will be processed with the service tier
578+ // configured in the Project settings. Unless otherwise configured, the Project
579+ // will use 'default'.
580+ // - If set to 'default', then the requset will be processed with the standard
581+ // pricing and performance for the selected model.
582+ // - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
583+ // 'priority', then the request will be processed with the corresponding service
584+ // tier. [Contact sales](https://openai.com/contact-sales) to learn more about
585+ // Priority processing.
586+ // - When not set, the default behavior is 'auto'.
587+ //
588+ // When the `service_tier` parameter is set, the response body will include the
589+ // `service_tier` value based on the processing mode actually used to serve the
590+ // request. This response value may be different from the value set in the
591+ // parameter.
562592 //
563− // Any of "scale", "default".
593+ // Any of "auto", "default", "flex", "scale", "priority".
564594 ServiceTier ChatCompletionChunkServiceTier `json:"service_tier,nullable"`
565595 // This fingerprint represents the backend configuration that the model runs with.
566596 // Can be used in conjunction with the `seed` request parameter to understand when
@@ -574,18 +604,17 @@ type ChatCompletionChunk struct {
574604 // **NOTE:** If the stream is interrupted or cancelled, you may not receive the
575605 // final usage chunk which contains the total token usage for the request.
576606 Usage CompletionUsage `json:"usage,nullable"`
577− // Metadata for the response, check the presence of optional fields with the
578− // [resp.Field.IsPresent] method.
607+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
579608 JSON struct {
580− ID resp.Field
581− Choices resp.Field
582− Created resp.Field
583− Model resp.Field
584− Object resp.Field
585− ServiceTier resp.Field
586− SystemFingerprint resp.Field
587− Usage resp.Field
588− ExtraFields map[string]resp.Field
609+ ID respjson.Field
610+ Choices respjson.Field
611+ Created respjson.Field
612+ Model respjson.Field
613+ Object respjson.Field
614+ ServiceTier respjson.Field
615+ SystemFingerprint respjson.Field
616+ Usage respjson.Field
617+ ExtraFields map[string]respjson.Field
589618 raw string
590619 } `json:"-"`
591620}
@@ -612,14 +641,13 @@ type ChatCompletionChunkChoice struct {
612641 Index int64 `json:"index,required"`
613642 // Log probability information for the choice.
614643 Logprobs ChatCompletionChunkChoiceLogprobs `json:"logprobs,nullable"`
615− // Metadata for the response, check the presence of optional fields with the
616− // [resp.Field.IsPresent] method.
644+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
617645 JSON struct {
618− Delta resp.Field
619− FinishReason resp.Field
620− Index resp.Field
621− Logprobs resp.Field
622− ExtraFields map[string]resp.Field
646+ Delta respjson.Field
647+ FinishReason respjson.Field
648+ Index respjson.Field
649+ Logprobs respjson.Field
650+ ExtraFields map[string]respjson.Field
623651 raw string
624652 } `json:"-"`
625653}
@@ -646,15 +674,14 @@ type ChatCompletionChunkChoiceDelta struct {
646674 // Any of "developer", "system", "user", "assistant", "tool".
647675 Role string `json:"role"`
648676 ToolCalls []ChatCompletionChunkChoiceDeltaToolCall `json:"tool_calls"`
649− // Metadata for the response, check the presence of optional fields with the
650− // [resp.Field.IsPresent] method.
677+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
651678 JSON struct {
652− Content resp.Field
653− FunctionCall resp.Field
654− Refusal resp.Field
655− Role resp.Field
656− ToolCalls resp.Field
657− ExtraFields map[string]resp.Field
679+ Content respjson.Field
680+ FunctionCall respjson.Field
681+ Refusal respjson.Field
682+ Role respjson.Field
683+ ToolCalls respjson.Field
684+ ExtraFields map[string]respjson.Field
658685 raw string
659686 } `json:"-"`
660687}
@@ -677,12 +704,11 @@ type ChatCompletionChunkChoiceDeltaFunctionCall struct {
677704 Arguments string `json:"arguments"`
678705 // The name of the function to call.
679706 Name string `json:"name"`
680− // Metadata for the response, check the presence of optional fields with the
681− // [resp.Field.IsPresent] method.
707+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
682708 JSON struct {
683− Arguments resp.Field
684− Name resp.Field
685− ExtraFields map[string]resp.Field
709+ Arguments respjson.Field
710+ Name respjson.Field
711+ ExtraFields map[string]respjson.Field
686712 raw string
687713 } `json:"-"`
688714}
@@ -702,14 +728,13 @@ type ChatCompletionChunkChoiceDeltaToolCall struct {
702728 //
703729 // Any of "function".
704730 Type string `json:"type"`
705− // Metadata for the response, check the presence of optional fields with the
706− // [resp.Field.IsPresent] method.
731+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
707732 JSON struct {
708− Index resp.Field
709− ID resp.Field
710− Function resp.Field
711− Type resp.Field
712− ExtraFields map[string]resp.Field
733+ Index respjson.Field
734+ ID respjson.Field
735+ Function respjson.Field
736+ Type respjson.Field
737+ ExtraFields map[string]respjson.Field
713738 raw string
714739 } `json:"-"`
715740}
@@ -728,12 +753,11 @@ type ChatCompletionChunkChoiceDeltaToolCallFunction struct {
728753 Arguments string `json:"arguments"`
729754 // The name of the function to call.
730755 Name string `json:"name"`
731− // Metadata for the response, check the presence of optional fields with the
732− // [resp.Field.IsPresent] method.
756+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
733757 JSON struct {
734− Arguments resp.Field
735− Name resp.Field
736− ExtraFields map[string]resp.Field
758+ Arguments respjson.Field
759+ Name respjson.Field
760+ ExtraFields map[string]respjson.Field
737761 raw string
738762 } `json:"-"`
739763}
@@ -750,12 +774,11 @@ type ChatCompletionChunkChoiceLogprobs struct {
750774 Content []ChatCompletionTokenLogprob `json:"content,required"`
751775 // A list of message refusal tokens with log probability information.
752776 Refusal []ChatCompletionTokenLogprob `json:"refusal,required"`
753− // Metadata for the response, check the presence of optional fields with the
754− // [resp.Field.IsPresent] method.
777+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
755778 JSON struct {
756− Content resp.Field
757− Refusal resp.Field
758− ExtraFields map[string]resp.Field
779+ Content respjson.Field
780+ Refusal respjson.Field
781+ ExtraFields map[string]respjson.Field
759782 raw string
760783 } `json:"-"`
761784}
@@ -766,12 +789,31 @@ func (r *ChatCompletionChunkChoiceLogprobs) UnmarshalJSON(data []byte) error {
766789 return apijson.UnmarshalRoot(data, r)
767790}
768791
769−// The service tier used for processing the request.
792+// Specifies the processing type used for serving the request.
793+//
794+// - If set to 'auto', then the request will be processed with the service tier
795+// configured in the Project settings. Unless otherwise configured, the Project
796+// will use 'default'.
797+// - If set to 'default', then the requset will be processed with the standard
798+// pricing and performance for the selected model.
799+// - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
800+// 'priority', then the request will be processed with the corresponding service
801+// tier. [Contact sales](https://openai.com/contact-sales) to learn more about
802+// Priority processing.
803+// - When not set, the default behavior is 'auto'.
804+//
805+// When the `service_tier` parameter is set, the response body will include the
806+// `service_tier` value based on the processing mode actually used to serve the
807+// request. This response value may be different from the value set in the
808+// parameter.
770809type ChatCompletionChunkServiceTier string
771810
772811const (
773− ChatCompletionChunkServiceTierScale ChatCompletionChunkServiceTier = "scale"
774− ChatCompletionChunkServiceTierDefault ChatCompletionChunkServiceTier = "default"
812+ ChatCompletionChunkServiceTierAuto ChatCompletionChunkServiceTier = "auto"
813+ ChatCompletionChunkServiceTierDefault ChatCompletionChunkServiceTier = "default"
814+ ChatCompletionChunkServiceTierFlex ChatCompletionChunkServiceTier = "flex"
815+ ChatCompletionChunkServiceTierScale ChatCompletionChunkServiceTier = "scale"
816+ ChatCompletionChunkServiceTierPriority ChatCompletionChunkServiceTier = "priority"
775817)
776818
777819func TextContentPart(text string) ChatCompletionContentPartUnionParam {
@@ -809,13 +851,11 @@ type ChatCompletionContentPartUnionParam struct {
809851 paramUnion
810852}
811853
812−// IsPresent returns true if the field's value is not omitted and not the JSON
813−// "null". To check if this field is omitted, use [param.IsOmitted].
814−func (u ChatCompletionContentPartUnionParam) IsPresent() bool {
815− return !param.IsOmitted(u) && !u.IsNull()
816−}
817854func (u ChatCompletionContentPartUnionParam) MarshalJSON() ([]byte, error) {
818− return param.MarshalUnion[ChatCompletionContentPartUnionParam](u.OfText, u.OfImageURL, u.OfInputAudio, u.OfFile)
855+ return param.MarshalUnion(u, u.OfText, u.OfImageURL, u.OfInputAudio, u.OfFile)
856+}
857+func (u *ChatCompletionContentPartUnionParam) UnmarshalJSON(data []byte) error {
858+ return apijson.UnmarshalRoot(data, u)
819859}
820860
821861func (u *ChatCompletionContentPartUnionParam) asAny() any {
@@ -880,26 +920,10 @@ func (u ChatCompletionContentPartUnionParam) GetType() *string {
880920func init() {
881921 apijson.RegisterUnion[ChatCompletionContentPartUnionParam](
882922 "type",
883− apijson.UnionVariant{
884− TypeFilter: gjson.JSON,
885− Type: reflect.TypeOf(ChatCompletionContentPartTextParam{}),
886− DiscriminatorValue: "text",
887− },
888− apijson.UnionVariant{
889− TypeFilter: gjson.JSON,
890− Type: reflect.TypeOf(ChatCompletionContentPartImageParam{}),
891− DiscriminatorValue: "image_url",
892− },
893− apijson.UnionVariant{
894− TypeFilter: gjson.JSON,
895− Type: reflect.TypeOf(ChatCompletionContentPartInputAudioParam{}),
896− DiscriminatorValue: "input_audio",
897− },
898− apijson.UnionVariant{
899− TypeFilter: gjson.JSON,
900− Type: reflect.TypeOf(ChatCompletionContentPartFileParam{}),
901− DiscriminatorValue: "file",
902− },
923+ apijson.Discriminator[ChatCompletionContentPartTextParam]("text"),
924+ apijson.Discriminator[ChatCompletionContentPartImageParam]("image_url"),
925+ apijson.Discriminator[ChatCompletionContentPartInputAudioParam]("input_audio"),
926+ apijson.Discriminator[ChatCompletionContentPartFileParam]("file"),
903927 )
904928}
905929
@@ -916,15 +940,13 @@ type ChatCompletionContentPartFileParam struct {
916940 paramObj
917941}
918942
919−// IsPresent returns true if the field's value is not omitted and not the JSON
920−// "null". To check if this field is omitted, use [param.IsOmitted].
921−func (f ChatCompletionContentPartFileParam) IsPresent() bool {
922− return !param.IsOmitted(f) && !f.IsNull()
923−}
924943func (r ChatCompletionContentPartFileParam) MarshalJSON() (data []byte, err error) {
925944 type shadow ChatCompletionContentPartFileParam
926945 return param.MarshalObject(r, (*shadow)(&r))
927946}
947+func (r *ChatCompletionContentPartFileParam) UnmarshalJSON(data []byte) error {
948+ return apijson.UnmarshalRoot(data, r)
949+}
928950
929951type ChatCompletionContentPartFileFileParam struct {
930952 // The base64 encoded file data, used when passing the file to the model as a
@@ -937,15 +959,13 @@ type ChatCompletionContentPartFileFileParam struct {
937959 paramObj
938960}
939961
940−// IsPresent returns true if the field's value is not omitted and not the JSON
941−// "null". To check if this field is omitted, use [param.IsOmitted].
942−func (f ChatCompletionContentPartFileFileParam) IsPresent() bool {
943− return !param.IsOmitted(f) && !f.IsNull()
944−}
945962func (r ChatCompletionContentPartFileFileParam) MarshalJSON() (data []byte, err error) {
946963 type shadow ChatCompletionContentPartFileFileParam
947964 return param.MarshalObject(r, (*shadow)(&r))
948965}
966+func (r *ChatCompletionContentPartFileFileParam) UnmarshalJSON(data []byte) error {
967+ return apijson.UnmarshalRoot(data, r)
968+}
949969
950970// Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
951971//
@@ -959,15 +979,13 @@ type ChatCompletionContentPartImageParam struct {
959979 paramObj
960980}
961981
962−// IsPresent returns true if the field's value is not omitted and not the JSON
963−// "null". To check if this field is omitted, use [param.IsOmitted].
964−func (f ChatCompletionContentPartImageParam) IsPresent() bool {
965− return !param.IsOmitted(f) && !f.IsNull()
966−}
967982func (r ChatCompletionContentPartImageParam) MarshalJSON() (data []byte, err error) {
968983 type shadow ChatCompletionContentPartImageParam
969984 return param.MarshalObject(r, (*shadow)(&r))
970985}
986+func (r *ChatCompletionContentPartImageParam) UnmarshalJSON(data []byte) error {
987+ return apijson.UnmarshalRoot(data, r)
988+}
971989
972990// The property URL is required.
973991type ChatCompletionContentPartImageImageURLParam struct {
@@ -981,19 +999,17 @@ type ChatCompletionContentPartImageImageURLParam struct {
981999 paramObj
9821000}
9831001
984−// IsPresent returns true if the field's value is not omitted and not the JSON
985−// "null". To check if this field is omitted, use [param.IsOmitted].
986−func (f ChatCompletionContentPartImageImageURLParam) IsPresent() bool {
987− return !param.IsOmitted(f) && !f.IsNull()
988−}
9891002func (r ChatCompletionContentPartImageImageURLParam) MarshalJSON() (data []byte, err error) {
9901003 type shadow ChatCompletionContentPartImageImageURLParam
9911004 return param.MarshalObject(r, (*shadow)(&r))
9921005}
1006+func (r *ChatCompletionContentPartImageImageURLParam) UnmarshalJSON(data []byte) error {
1007+ return apijson.UnmarshalRoot(data, r)
1008+}
9931009
9941010func init() {
9951011 apijson.RegisterFieldValidator[ChatCompletionContentPartImageImageURLParam](
996− "Detail", false, "auto", "low", "high",
1012+ "detail", "auto", "low", "high",
9971013 )
9981014}
9991015
@@ -1009,15 +1025,13 @@ type ChatCompletionContentPartInputAudioParam struct {
10091025 paramObj
10101026}
10111027
1012−// IsPresent returns true if the field's value is not omitted and not the JSON
1013−// "null". To check if this field is omitted, use [param.IsOmitted].
1014−func (f ChatCompletionContentPartInputAudioParam) IsPresent() bool {
1015− return !param.IsOmitted(f) && !f.IsNull()
1016−}
10171028func (r ChatCompletionContentPartInputAudioParam) MarshalJSON() (data []byte, err error) {
10181029 type shadow ChatCompletionContentPartInputAudioParam
10191030 return param.MarshalObject(r, (*shadow)(&r))
10201031}
1032+func (r *ChatCompletionContentPartInputAudioParam) UnmarshalJSON(data []byte) error {
1033+ return apijson.UnmarshalRoot(data, r)
1034+}
10211035
10221036// The properties Data, Format are required.
10231037type ChatCompletionContentPartInputAudioInputAudioParam struct {
@@ -1030,19 +1044,17 @@ type ChatCompletionContentPartInputAudioInputAudioParam struct {
10301044 paramObj
10311045}
10321046
1033−// IsPresent returns true if the field's value is not omitted and not the JSON
1034−// "null". To check if this field is omitted, use [param.IsOmitted].
1035−func (f ChatCompletionContentPartInputAudioInputAudioParam) IsPresent() bool {
1036− return !param.IsOmitted(f) && !f.IsNull()
1037−}
10381047func (r ChatCompletionContentPartInputAudioInputAudioParam) MarshalJSON() (data []byte, err error) {
10391048 type shadow ChatCompletionContentPartInputAudioInputAudioParam
10401049 return param.MarshalObject(r, (*shadow)(&r))
10411050}
1051+func (r *ChatCompletionContentPartInputAudioInputAudioParam) UnmarshalJSON(data []byte) error {
1052+ return apijson.UnmarshalRoot(data, r)
1053+}
10421054
10431055func init() {
10441056 apijson.RegisterFieldValidator[ChatCompletionContentPartInputAudioInputAudioParam](
1045− "Format", false, "wav", "mp3",
1057+ "format", "wav", "mp3",
10461058 )
10471059}
10481060
@@ -1057,15 +1069,13 @@ type ChatCompletionContentPartRefusalParam struct {
10571069 paramObj
10581070}
10591071
1060−// IsPresent returns true if the field's value is not omitted and not the JSON
1061−// "null". To check if this field is omitted, use [param.IsOmitted].
1062−func (f ChatCompletionContentPartRefusalParam) IsPresent() bool {
1063− return !param.IsOmitted(f) && !f.IsNull()
1064−}
10651072func (r ChatCompletionContentPartRefusalParam) MarshalJSON() (data []byte, err error) {
10661073 type shadow ChatCompletionContentPartRefusalParam
10671074 return param.MarshalObject(r, (*shadow)(&r))
10681075}
1076+func (r *ChatCompletionContentPartRefusalParam) UnmarshalJSON(data []byte) error {
1077+ return apijson.UnmarshalRoot(data, r)
1078+}
10691079
10701080// Learn about
10711081// [text inputs](https://platform.openai.com/docs/guides/text-generation).
@@ -1081,15 +1091,13 @@ type ChatCompletionContentPartTextParam struct {
10811091 paramObj
10821092}
10831093
1084−// IsPresent returns true if the field's value is not omitted and not the JSON
1085−// "null". To check if this field is omitted, use [param.IsOmitted].
1086−func (f ChatCompletionContentPartTextParam) IsPresent() bool {
1087− return !param.IsOmitted(f) && !f.IsNull()
1088−}
10891094func (r ChatCompletionContentPartTextParam) MarshalJSON() (data []byte, err error) {
10901095 type shadow ChatCompletionContentPartTextParam
10911096 return param.MarshalObject(r, (*shadow)(&r))
10921097}
1098+func (r *ChatCompletionContentPartTextParam) UnmarshalJSON(data []byte) error {
1099+ return apijson.UnmarshalRoot(data, r)
1100+}
10931101
10941102type ChatCompletionDeleted struct {
10951103 // The ID of the chat completion that was deleted.
@@ -1098,13 +1106,12 @@ type ChatCompletionDeleted struct {
10981106 Deleted bool `json:"deleted,required"`
10991107 // The type of object being deleted.
11001108 Object constant.ChatCompletionDeleted `json:"object,required"`
1101− // Metadata for the response, check the presence of optional fields with the
1102− // [resp.Field.IsPresent] method.
1109+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
11031110 JSON struct {
1104− ID resp.Field
1105− Deleted resp.Field
1106− Object resp.Field
1107− ExtraFields map[string]resp.Field
1111+ ID respjson.Field
1112+ Deleted respjson.Field
1113+ Object respjson.Field
1114+ ExtraFields map[string]respjson.Field
11081115 raw string
11091116 } `json:"-"`
11101117}
@@ -1133,15 +1140,13 @@ type ChatCompletionDeveloperMessageParam struct {
11331140 paramObj
11341141}
11351142
1136−// IsPresent returns true if the field's value is not omitted and not the JSON
1137−// "null". To check if this field is omitted, use [param.IsOmitted].
1138−func (f ChatCompletionDeveloperMessageParam) IsPresent() bool {
1139− return !param.IsOmitted(f) && !f.IsNull()
1140−}
11411143func (r ChatCompletionDeveloperMessageParam) MarshalJSON() (data []byte, err error) {
11421144 type shadow ChatCompletionDeveloperMessageParam
11431145 return param.MarshalObject(r, (*shadow)(&r))
11441146}
1147+func (r *ChatCompletionDeveloperMessageParam) UnmarshalJSON(data []byte) error {
1148+ return apijson.UnmarshalRoot(data, r)
1149+}
11451150
11461151// Only one field can be non-zero.
11471152//
@@ -1152,13 +1157,11 @@ type ChatCompletionDeveloperMessageParamContentUnion struct {
11521157 paramUnion
11531158}
11541159
1155−// IsPresent returns true if the field's value is not omitted and not the JSON
1156−// "null". To check if this field is omitted, use [param.IsOmitted].
1157−func (u ChatCompletionDeveloperMessageParamContentUnion) IsPresent() bool {
1158− return !param.IsOmitted(u) && !u.IsNull()
1159−}
11601160func (u ChatCompletionDeveloperMessageParamContentUnion) MarshalJSON() ([]byte, error) {
1161− return param.MarshalUnion[ChatCompletionDeveloperMessageParamContentUnion](u.OfString, u.OfArrayOfContentParts)
1161+ return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
1162+}
1163+func (u *ChatCompletionDeveloperMessageParamContentUnion) UnmarshalJSON(data []byte) error {
1164+ return apijson.UnmarshalRoot(data, u)
11621165}
11631166
11641167func (u *ChatCompletionDeveloperMessageParamContentUnion) asAny() any {
@@ -1180,15 +1183,13 @@ type ChatCompletionFunctionCallOptionParam struct {
11801183 paramObj
11811184}
11821185
1183−// IsPresent returns true if the field's value is not omitted and not the JSON
1184−// "null". To check if this field is omitted, use [param.IsOmitted].
1185−func (f ChatCompletionFunctionCallOptionParam) IsPresent() bool {
1186− return !param.IsOmitted(f) && !f.IsNull()
1187−}
11881186func (r ChatCompletionFunctionCallOptionParam) MarshalJSON() (data []byte, err error) {
11891187 type shadow ChatCompletionFunctionCallOptionParam
11901188 return param.MarshalObject(r, (*shadow)(&r))
11911189}
1190+func (r *ChatCompletionFunctionCallOptionParam) UnmarshalJSON(data []byte) error {
1191+ return apijson.UnmarshalRoot(data, r)
1192+}
11921193
11931194// Deprecated: deprecated
11941195//
@@ -1205,15 +1206,13 @@ type ChatCompletionFunctionMessageParam struct {
12051206 paramObj
12061207}
12071208
1208−// IsPresent returns true if the field's value is not omitted and not the JSON
1209−// "null". To check if this field is omitted, use [param.IsOmitted].
1210−func (f ChatCompletionFunctionMessageParam) IsPresent() bool {
1211− return !param.IsOmitted(f) && !f.IsNull()
1212−}
12131209func (r ChatCompletionFunctionMessageParam) MarshalJSON() (data []byte, err error) {
12141210 type shadow ChatCompletionFunctionMessageParam
12151211 return param.MarshalObject(r, (*shadow)(&r))
12161212}
1213+func (r *ChatCompletionFunctionMessageParam) UnmarshalJSON(data []byte) error {
1214+ return apijson.UnmarshalRoot(data, r)
1215+}
12171216
12181217// A chat completion message generated by the model.
12191218type ChatCompletionMessage struct {
@@ -1237,17 +1236,16 @@ type ChatCompletionMessage struct {
12371236 FunctionCall ChatCompletionMessageFunctionCall `json:"function_call"`
12381237 // The tool calls generated by the model, such as function calls.
12391238 ToolCalls []ChatCompletionMessageToolCall `json:"tool_calls"`
1240− // Metadata for the response, check the presence of optional fields with the
1241− // [resp.Field.IsPresent] method.
1239+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
12421240 JSON struct {
1243− Content resp.Field
1244− Refusal resp.Field
1245− Role resp.Field
1246− Annotations resp.Field
1247− Audio resp.Field
1248− FunctionCall resp.Field
1249− ToolCalls resp.Field
1250− ExtraFields map[string]resp.Field
1241+ Content respjson.Field
1242+ Refusal respjson.Field
1243+ Role respjson.Field
1244+ Annotations respjson.Field
1245+ Audio respjson.Field
1246+ FunctionCall respjson.Field
1247+ ToolCalls respjson.Field
1248+ ExtraFields map[string]respjson.Field
12511249 raw string
12521250 } `json:"-"`
12531251}
@@ -1300,12 +1298,11 @@ type ChatCompletionMessageAnnotation struct {
13001298 Type constant.URLCitation `json:"type,required"`
13011299 // A URL citation when using web search.
13021300 URLCitation ChatCompletionMessageAnnotationURLCitation `json:"url_citation,required"`
1303− // Metadata for the response, check the presence of optional fields with the
1304− // [resp.Field.IsPresent] method.
1301+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
13051302 JSON struct {
1306− Type resp.Field
1307− URLCitation resp.Field
1308− ExtraFields map[string]resp.Field
1303+ Type respjson.Field
1304+ URLCitation respjson.Field
1305+ ExtraFields map[string]respjson.Field
13091306 raw string
13101307 } `json:"-"`
13111308}
@@ -1326,14 +1323,13 @@ type ChatCompletionMessageAnnotationURLCitation struct {
13261323 Title string `json:"title,required"`
13271324 // The URL of the web resource.
13281325 URL string `json:"url,required"`
1329− // Metadata for the response, check the presence of optional fields with the
1330− // [resp.Field.IsPresent] method.
1326+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
13311327 JSON struct {
1332− EndIndex resp.Field
1333− StartIndex resp.Field
1334− Title resp.Field
1335− URL resp.Field
1336− ExtraFields map[string]resp.Field
1328+ EndIndex respjson.Field
1329+ StartIndex respjson.Field
1330+ Title respjson.Field
1331+ URL respjson.Field
1332+ ExtraFields map[string]respjson.Field
13371333 raw string
13381334 } `json:"-"`
13391335}
@@ -1356,12 +1352,11 @@ type ChatCompletionMessageFunctionCall struct {
13561352 Arguments string `json:"arguments,required"`
13571353 // The name of the function to call.
13581354 Name string `json:"name,required"`
1359− // Metadata for the response, check the presence of optional fields with the
1360− // [resp.Field.IsPresent] method.
1355+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
13611356 JSON struct {
1362− Arguments resp.Field
1363− Name resp.Field
1364− ExtraFields map[string]resp.Field
1357+ Arguments respjson.Field
1358+ Name respjson.Field
1359+ ExtraFields map[string]respjson.Field
13651360 raw string
13661361 } `json:"-"`
13671362}
@@ -1448,17 +1443,17 @@ type ChatCompletionMessageParamUnion struct {
14481443 paramUnion
14491444}
14501445
1451−// IsPresent returns true if the field's value is not omitted and not the JSON
1452−// "null". To check if this field is omitted, use [param.IsOmitted].
1453−func (u ChatCompletionMessageParamUnion) IsPresent() bool { return !param.IsOmitted(u) && !u.IsNull() }
14541446func (u ChatCompletionMessageParamUnion) MarshalJSON() ([]byte, error) {
1455− return param.MarshalUnion[ChatCompletionMessageParamUnion](u.OfDeveloper,
1447+ return param.MarshalUnion(u, u.OfDeveloper,
14561448 u.OfSystem,
14571449 u.OfUser,
14581450 u.OfAssistant,
14591451 u.OfTool,
14601452 u.OfFunction)
14611453}
1454+func (u *ChatCompletionMessageParamUnion) UnmarshalJSON(data []byte) error {
1455+ return apijson.UnmarshalRoot(data, u)
1456+}
14621457
14631458func (u *ChatCompletionMessageParamUnion) asAny() any {
14641459 if !param.IsOmitted(u.OfDeveloper) {
@@ -1495,7 +1490,7 @@ func (u ChatCompletionMessageParamUnion) GetFunctionCall() *ChatCompletionAssist
14951490
14961491// Returns a pointer to the underlying variant's property, if present.
14971492func (u ChatCompletionMessageParamUnion) GetRefusal() *string {
1498− if vt := u.OfAssistant; vt != nil && vt.Refusal.IsPresent() {
1493+ if vt := u.OfAssistant; vt != nil && vt.Refusal.Valid() {
14991494 return &vt.Refusal.Value
15001495 }
15011496 return nil
@@ -1537,13 +1532,13 @@ func (u ChatCompletionMessageParamUnion) GetRole() *string {
15371532
15381533// Returns a pointer to the underlying variant's property, if present.
15391534func (u ChatCompletionMessageParamUnion) GetName() *string {
1540− if vt := u.OfDeveloper; vt != nil && vt.Name.IsPresent() {
1535+ if vt := u.OfDeveloper; vt != nil && vt.Name.Valid() {
15411536 return &vt.Name.Value
1542− } else if vt := u.OfSystem; vt != nil && vt.Name.IsPresent() {
1537+ } else if vt := u.OfSystem; vt != nil && vt.Name.Valid() {
15431538 return &vt.Name.Value
1544− } else if vt := u.OfUser; vt != nil && vt.Name.IsPresent() {
1539+ } else if vt := u.OfUser; vt != nil && vt.Name.Valid() {
15451540 return &vt.Name.Value
1546− } else if vt := u.OfAssistant; vt != nil && vt.Name.IsPresent() {
1541+ } else if vt := u.OfAssistant; vt != nil && vt.Name.Valid() {
15471542 return &vt.Name.Value
15481543 } else if vt := u.OfFunction; vt != nil {
15491544 return (*string)(&vt.Name)
@@ -1556,32 +1551,25 @@ func (u ChatCompletionMessageParamUnion) GetName() *string {
15561551// Or use AsAny() to get the underlying value
15571552func (u ChatCompletionMessageParamUnion) GetContent() (res chatCompletionMessageParamUnionContent) {
15581553 if vt := u.OfDeveloper; vt != nil {
1559− res.ofChatCompletionDeveloperMessageContent = &vt.Content
1554+ res.any = vt.Content.asAny()
15601555 } else if vt := u.OfSystem; vt != nil {
1561− res.ofChatCompletionSystemMessageContent = &vt.Content
1556+ res.any = vt.Content.asAny()
15621557 } else if vt := u.OfUser; vt != nil {
1563− res.ofChatCompletionUserMessageContent = &vt.Content
1558+ res.any = vt.Content.asAny()
15641559 } else if vt := u.OfAssistant; vt != nil {
1565− res.ofChatCompletionAssistantMessageContent = &vt.Content
1560+ res.any = vt.Content.asAny()
15661561 } else if vt := u.OfTool; vt != nil {
1567− res.ofChatCompletionToolMessageContent = &vt.Content
1568− } else if vt := u.OfFunction; vt != nil && vt.Content.IsPresent() {
1569− res.ofString = &vt.Content.Value
1562+ res.any = vt.Content.asAny()
1563+ } else if vt := u.OfFunction; vt != nil && vt.Content.Valid() {
1564+ res.any = &vt.Content.Value
15701565 }
15711566 return
15721567}
15731568
1574−// Only one field can be non-zero.
1575−//
1576−// Use [param.IsOmitted] to confirm if a field is set.
1577−type chatCompletionMessageParamUnionContent struct {
1578− ofChatCompletionDeveloperMessageContent *ChatCompletionDeveloperMessageParamContentUnion
1579− ofChatCompletionSystemMessageContent *ChatCompletionSystemMessageParamContentUnion
1580− ofChatCompletionUserMessageContent *ChatCompletionUserMessageParamContentUnion
1581− ofChatCompletionAssistantMessageContent *ChatCompletionAssistantMessageParamContentUnion
1582− ofChatCompletionToolMessageContent *ChatCompletionToolMessageParamContentUnion
1583− ofString *string
1584−}
1569+// Can have the runtime types [*string], [_[]ChatCompletionContentPartTextParam],
1570+// [_[]ChatCompletionContentPartUnionParam],
1571+// [\*[]ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion]
1572+type chatCompletionMessageParamUnionContent struct{ any }
15851573
15861574// Use the following switch statement to get the type of the union:
15871575//
@@ -1593,56 +1581,17 @@ type chatCompletionMessageParamUnionContent struct {
15931581// default:
15941582// fmt.Errorf("not present")
15951583// }
1596−func (u chatCompletionMessageParamUnionContent) AsAny() any {
1597− if !param.IsOmitted(u.ofChatCompletionDeveloperMessageContent) {
1598− return u.ofChatCompletionDeveloperMessageContent.asAny()
1599− } else if !param.IsOmitted(u.ofChatCompletionSystemMessageContent) {
1600− return u.ofChatCompletionSystemMessageContent.asAny()
1601− } else if !param.IsOmitted(u.ofChatCompletionUserMessageContent) {
1602− return u.ofChatCompletionUserMessageContent.asAny()
1603− } else if !param.IsOmitted(u.ofChatCompletionAssistantMessageContent) {
1604− return u.ofChatCompletionAssistantMessageContent.asAny()
1605− } else if !param.IsOmitted(u.ofChatCompletionToolMessageContent) {
1606− return u.ofChatCompletionToolMessageContent.asAny()
1607− } else if !param.IsOmitted(u.ofString) {
1608− return u.ofString
1609− }
1610− return nil
1611−}
1584+func (u chatCompletionMessageParamUnionContent) AsAny() any { return u.any }
16121585
16131586func init() {
16141587 apijson.RegisterUnion[ChatCompletionMessageParamUnion](
16151588 "role",
1616− apijson.UnionVariant{
1617− TypeFilter: gjson.JSON,
1618− Type: reflect.TypeOf(ChatCompletionDeveloperMessageParam{}),
1619− DiscriminatorValue: "developer",
1620− },
1621− apijson.UnionVariant{
1622− TypeFilter: gjson.JSON,
1623− Type: reflect.TypeOf(ChatCompletionSystemMessageParam{}),
1624− DiscriminatorValue: "system",
1625− },
1626− apijson.UnionVariant{
1627− TypeFilter: gjson.JSON,
1628− Type: reflect.TypeOf(ChatCompletionUserMessageParam{}),
1629− DiscriminatorValue: "user",
1630− },
1631− apijson.UnionVariant{
1632− TypeFilter: gjson.JSON,
1633− Type: reflect.TypeOf(ChatCompletionAssistantMessageParam{}),
1634− DiscriminatorValue: "assistant",
1635− },
1636− apijson.UnionVariant{
1637− TypeFilter: gjson.JSON,
1638− Type: reflect.TypeOf(ChatCompletionToolMessageParam{}),
1639− DiscriminatorValue: "tool",
1640− },
1641− apijson.UnionVariant{
1642− TypeFilter: gjson.JSON,
1643− Type: reflect.TypeOf(ChatCompletionFunctionMessageParam{}),
1644− DiscriminatorValue: "function",
1645− },
1589+ apijson.Discriminator[ChatCompletionDeveloperMessageParam]("developer"),
1590+ apijson.Discriminator[ChatCompletionSystemMessageParam]("system"),
1591+ apijson.Discriminator[ChatCompletionUserMessageParam]("user"),
1592+ apijson.Discriminator[ChatCompletionAssistantMessageParam]("assistant"),
1593+ apijson.Discriminator[ChatCompletionToolMessageParam]("tool"),
1594+ apijson.Discriminator[ChatCompletionFunctionMessageParam]("function"),
16461595 )
16471596}
16481597
@@ -1653,13 +1602,12 @@ type ChatCompletionMessageToolCall struct {
16531602 Function ChatCompletionMessageToolCallFunction `json:"function,required"`
16541603 // The type of the tool. Currently, only `function` is supported.
16551604 Type constant.Function `json:"type,required"`
1656− // Metadata for the response, check the presence of optional fields with the
1657− // [resp.Field.IsPresent] method.
1605+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
16581606 JSON struct {
1659− ID resp.Field
1660− Function resp.Field
1661− Type resp.Field
1662− ExtraFields map[string]resp.Field
1607+ ID respjson.Field
1608+ Function respjson.Field
1609+ Type respjson.Field
1610+ ExtraFields map[string]respjson.Field
16631611 raw string
16641612 } `json:"-"`
16651613}
@@ -1675,9 +1623,9 @@ func (r *ChatCompletionMessageToolCall) UnmarshalJSON(data []byte) error {
16751623//
16761624// Warning: the fields of the param type will not be present. ToParam should only
16771625// be used at the last possible moment before sending a request. Test for this with
1678−// ChatCompletionMessageToolCallParam.IsOverridden()
1626+// ChatCompletionMessageToolCallParam.Overrides()
16791627func (r ChatCompletionMessageToolCall) ToParam() ChatCompletionMessageToolCallParam {
1680− return param.OverrideObj[ChatCompletionMessageToolCallParam](r.RawJSON())
1628+ return param.Override[ChatCompletionMessageToolCallParam](json.RawMessage(r.RawJSON()))
16811629}
16821630
16831631// The function that the model called.
@@ -1689,12 +1637,11 @@ type ChatCompletionMessageToolCallFunction struct {
16891637 Arguments string `json:"arguments,required"`
16901638 // The name of the function to call.
16911639 Name string `json:"name,required"`
1692− // Metadata for the response, check the presence of optional fields with the
1693− // [resp.Field.IsPresent] method.
1640+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
16941641 JSON struct {
1695− Arguments resp.Field
1696− Name resp.Field
1697− ExtraFields map[string]resp.Field
1642+ Arguments respjson.Field
1643+ Name respjson.Field
1644+ ExtraFields map[string]respjson.Field
16981645 raw string
16991646 } `json:"-"`
17001647}
@@ -1718,15 +1665,13 @@ type ChatCompletionMessageToolCallParam struct {
17181665 paramObj
17191666}
17201667
1721−// IsPresent returns true if the field's value is not omitted and not the JSON
1722−// "null". To check if this field is omitted, use [param.IsOmitted].
1723−func (f ChatCompletionMessageToolCallParam) IsPresent() bool {
1724− return !param.IsOmitted(f) && !f.IsNull()
1725−}
17261668func (r ChatCompletionMessageToolCallParam) MarshalJSON() (data []byte, err error) {
17271669 type shadow ChatCompletionMessageToolCallParam
17281670 return param.MarshalObject(r, (*shadow)(&r))
17291671}
1672+func (r *ChatCompletionMessageToolCallParam) UnmarshalJSON(data []byte) error {
1673+ return apijson.UnmarshalRoot(data, r)
1674+}
17301675
17311676// The function that the model called.
17321677//
@@ -1742,15 +1687,13 @@ type ChatCompletionMessageToolCallFunctionParam struct {
17421687 paramObj
17431688}
17441689
1745−// IsPresent returns true if the field's value is not omitted and not the JSON
1746−// "null". To check if this field is omitted, use [param.IsOmitted].
1747−func (f ChatCompletionMessageToolCallFunctionParam) IsPresent() bool {
1748− return !param.IsOmitted(f) && !f.IsNull()
1749−}
17501690func (r ChatCompletionMessageToolCallFunctionParam) MarshalJSON() (data []byte, err error) {
17511691 type shadow ChatCompletionMessageToolCallFunctionParam
17521692 return param.MarshalObject(r, (*shadow)(&r))
17531693}
1694+func (r *ChatCompletionMessageToolCallFunctionParam) UnmarshalJSON(data []byte) error {
1695+ return apijson.UnmarshalRoot(data, r)
1696+}
17541697
17551698// Specifies a tool the model should use. Use to force the model to call a specific
17561699// function.
@@ -1765,15 +1708,13 @@ type ChatCompletionNamedToolChoiceParam struct {
17651708 paramObj
17661709}
17671710
1768−// IsPresent returns true if the field's value is not omitted and not the JSON
1769−// "null". To check if this field is omitted, use [param.IsOmitted].
1770−func (f ChatCompletionNamedToolChoiceParam) IsPresent() bool {
1771− return !param.IsOmitted(f) && !f.IsNull()
1772−}
17731711func (r ChatCompletionNamedToolChoiceParam) MarshalJSON() (data []byte, err error) {
17741712 type shadow ChatCompletionNamedToolChoiceParam
17751713 return param.MarshalObject(r, (*shadow)(&r))
17761714}
1715+func (r *ChatCompletionNamedToolChoiceParam) UnmarshalJSON(data []byte) error {
1716+ return apijson.UnmarshalRoot(data, r)
1717+}
17771718
17781719// The property Name is required.
17791720type ChatCompletionNamedToolChoiceFunctionParam struct {
@@ -1782,15 +1723,13 @@ type ChatCompletionNamedToolChoiceFunctionParam struct {
17821723 paramObj
17831724}
17841725
1785−// IsPresent returns true if the field's value is not omitted and not the JSON
1786−// "null". To check if this field is omitted, use [param.IsOmitted].
1787−func (f ChatCompletionNamedToolChoiceFunctionParam) IsPresent() bool {
1788− return !param.IsOmitted(f) && !f.IsNull()
1789−}
17901726func (r ChatCompletionNamedToolChoiceFunctionParam) MarshalJSON() (data []byte, err error) {
17911727 type shadow ChatCompletionNamedToolChoiceFunctionParam
17921728 return param.MarshalObject(r, (*shadow)(&r))
17931729}
1730+func (r *ChatCompletionNamedToolChoiceFunctionParam) UnmarshalJSON(data []byte) error {
1731+ return apijson.UnmarshalRoot(data, r)
1732+}
17941733
17951734// Static predicted output content, such as the content of a text file that is
17961735// being regenerated.
@@ -1809,15 +1748,13 @@ type ChatCompletionPredictionContentParam struct {
18091748 paramObj
18101749}
18111750
1812−// IsPresent returns true if the field's value is not omitted and not the JSON
1813−// "null". To check if this field is omitted, use [param.IsOmitted].
1814−func (f ChatCompletionPredictionContentParam) IsPresent() bool {
1815− return !param.IsOmitted(f) && !f.IsNull()
1816−}
18171751func (r ChatCompletionPredictionContentParam) MarshalJSON() (data []byte, err error) {
18181752 type shadow ChatCompletionPredictionContentParam
18191753 return param.MarshalObject(r, (*shadow)(&r))
18201754}
1755+func (r *ChatCompletionPredictionContentParam) UnmarshalJSON(data []byte) error {
1756+ return apijson.UnmarshalRoot(data, r)
1757+}
18211758
18221759// Only one field can be non-zero.
18231760//
@@ -1828,13 +1765,11 @@ type ChatCompletionPredictionContentContentUnionParam struct {
18281765 paramUnion
18291766}
18301767
1831−// IsPresent returns true if the field's value is not omitted and not the JSON
1832−// "null". To check if this field is omitted, use [param.IsOmitted].
1833−func (u ChatCompletionPredictionContentContentUnionParam) IsPresent() bool {
1834− return !param.IsOmitted(u) && !u.IsNull()
1835−}
18361768func (u ChatCompletionPredictionContentContentUnionParam) MarshalJSON() ([]byte, error) {
1837− return param.MarshalUnion[ChatCompletionPredictionContentContentUnionParam](u.OfString, u.OfArrayOfContentParts)
1769+ return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
1770+}
1771+func (u *ChatCompletionPredictionContentContentUnionParam) UnmarshalJSON(data []byte) error {
1772+ return apijson.UnmarshalRoot(data, u)
18381773}
18391774
18401775func (u *ChatCompletionPredictionContentContentUnionParam) asAny() any {
@@ -1850,11 +1785,10 @@ func (u *ChatCompletionPredictionContentContentUnionParam) asAny() any {
18501785type ChatCompletionStoreMessage struct {
18511786 // The identifier of the chat message.
18521787 ID string `json:"id,required"`
1853− // Metadata for the response, check the presence of optional fields with the
1854− // [resp.Field.IsPresent] method.
1788+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
18551789 JSON struct {
1856− ID resp.Field
1857− ExtraFields map[string]resp.Field
1790+ ID respjson.Field
1791+ ExtraFields map[string]respjson.Field
18581792 raw string
18591793 } `json:"-"`
18601794 ChatCompletionMessage
@@ -1879,13 +1813,13 @@ type ChatCompletionStreamOptionsParam struct {
18791813 paramObj
18801814}
18811815
1882−// IsPresent returns true if the field's value is not omitted and not the JSON
1883−// "null". To check if this field is omitted, use [param.IsOmitted].
1884−func (f ChatCompletionStreamOptionsParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
18851816func (r ChatCompletionStreamOptionsParam) MarshalJSON() (data []byte, err error) {
18861817 type shadow ChatCompletionStreamOptionsParam
18871818 return param.MarshalObject(r, (*shadow)(&r))
18881819}
1820+func (r *ChatCompletionStreamOptionsParam) UnmarshalJSON(data []byte) error {
1821+ return apijson.UnmarshalRoot(data, r)
1822+}
18891823
18901824// Developer-provided instructions that the model should follow, regardless of
18911825// messages sent by the user. With o1 models and newer, use `developer` messages
@@ -1905,13 +1839,13 @@ type ChatCompletionSystemMessageParam struct {
19051839 paramObj
19061840}
19071841
1908−// IsPresent returns true if the field's value is not omitted and not the JSON
1909−// "null". To check if this field is omitted, use [param.IsOmitted].
1910−func (f ChatCompletionSystemMessageParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
19111842func (r ChatCompletionSystemMessageParam) MarshalJSON() (data []byte, err error) {
19121843 type shadow ChatCompletionSystemMessageParam
19131844 return param.MarshalObject(r, (*shadow)(&r))
19141845}
1846+func (r *ChatCompletionSystemMessageParam) UnmarshalJSON(data []byte) error {
1847+ return apijson.UnmarshalRoot(data, r)
1848+}
19151849
19161850// Only one field can be non-zero.
19171851//
@@ -1922,13 +1856,11 @@ type ChatCompletionSystemMessageParamContentUnion struct {
19221856 paramUnion
19231857}
19241858
1925−// IsPresent returns true if the field's value is not omitted and not the JSON
1926−// "null". To check if this field is omitted, use [param.IsOmitted].
1927−func (u ChatCompletionSystemMessageParamContentUnion) IsPresent() bool {
1928− return !param.IsOmitted(u) && !u.IsNull()
1929−}
19301859func (u ChatCompletionSystemMessageParamContentUnion) MarshalJSON() ([]byte, error) {
1931− return param.MarshalUnion[ChatCompletionSystemMessageParamContentUnion](u.OfString, u.OfArrayOfContentParts)
1860+ return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
1861+}
1862+func (u *ChatCompletionSystemMessageParamContentUnion) UnmarshalJSON(data []byte) error {
1863+ return apijson.UnmarshalRoot(data, u)
19321864}
19331865
19341866func (u *ChatCompletionSystemMessageParamContentUnion) asAny() any {
@@ -1956,14 +1888,13 @@ type ChatCompletionTokenLogprob struct {
19561888 // position. In rare cases, there may be fewer than the number of requested
19571889 // `top_logprobs` returned.
19581890 TopLogprobs []ChatCompletionTokenLogprobTopLogprob `json:"top_logprobs,required"`
1959− // Metadata for the response, check the presence of optional fields with the
1960− // [resp.Field.IsPresent] method.
1891+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
19611892 JSON struct {
1962− Token resp.Field
1963− Bytes resp.Field
1964− Logprob resp.Field
1965− TopLogprobs resp.Field
1966− ExtraFields map[string]resp.Field
1893+ Token respjson.Field
1894+ Bytes respjson.Field
1895+ Logprob respjson.Field
1896+ TopLogprobs respjson.Field
1897+ ExtraFields map[string]respjson.Field
19671898 raw string
19681899 } `json:"-"`
19691900}
@@ -1986,13 +1917,12 @@ type ChatCompletionTokenLogprobTopLogprob struct {
19861917 // tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
19871918 // unlikely.
19881919 Logprob float64 `json:"logprob,required"`
1989− // Metadata for the response, check the presence of optional fields with the
1990− // [resp.Field.IsPresent] method.
1920+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
19911921 JSON struct {
1992− Token resp.Field
1993− Bytes resp.Field
1994− Logprob resp.Field
1995− ExtraFields map[string]resp.Field
1922+ Token respjson.Field
1923+ Bytes respjson.Field
1924+ Logprob respjson.Field
1925+ ExtraFields map[string]respjson.Field
19961926 raw string
19971927 } `json:"-"`
19981928}
@@ -2013,13 +1943,13 @@ type ChatCompletionToolParam struct {
20131943 paramObj
20141944}
20151945
2016−// IsPresent returns true if the field's value is not omitted and not the JSON
2017−// "null". To check if this field is omitted, use [param.IsOmitted].
2018−func (f ChatCompletionToolParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
20191946func (r ChatCompletionToolParam) MarshalJSON() (data []byte, err error) {
20201947 type shadow ChatCompletionToolParam
20211948 return param.MarshalObject(r, (*shadow)(&r))
20221949}
1950+func (r *ChatCompletionToolParam) UnmarshalJSON(data []byte) error {
1951+ return apijson.UnmarshalRoot(data, r)
1952+}
20231953
20241954func ChatCompletionToolChoiceOptionParamOfChatCompletionNamedToolChoice(function ChatCompletionNamedToolChoiceFunctionParam) ChatCompletionToolChoiceOptionUnionParam {
20251955 var variant ChatCompletionNamedToolChoiceParam
@@ -2037,13 +1967,11 @@ type ChatCompletionToolChoiceOptionUnionParam struct {
20371967 paramUnion
20381968}
20391969
2040−// IsPresent returns true if the field's value is not omitted and not the JSON
2041−// "null". To check if this field is omitted, use [param.IsOmitted].
2042−func (u ChatCompletionToolChoiceOptionUnionParam) IsPresent() bool {
2043− return !param.IsOmitted(u) && !u.IsNull()
2044−}
20451970func (u ChatCompletionToolChoiceOptionUnionParam) MarshalJSON() ([]byte, error) {
2046− return param.MarshalUnion[ChatCompletionToolChoiceOptionUnionParam](u.OfAuto, u.OfChatCompletionNamedToolChoice)
1971+ return param.MarshalUnion(u, u.OfAuto, u.OfChatCompletionNamedToolChoice)
1972+}
1973+func (u *ChatCompletionToolChoiceOptionUnionParam) UnmarshalJSON(data []byte) error {
1974+ return apijson.UnmarshalRoot(data, u)
20471975}
20481976
20491977func (u *ChatCompletionToolChoiceOptionUnionParam) asAny() any {
@@ -2055,21 +1983,16 @@ func (u *ChatCompletionToolChoiceOptionUnionParam) asAny() any {
20551983 return nil
20561984}
20571985
2058−// Returns a pointer to the underlying variant's property, if present.
2059−func (u ChatCompletionToolChoiceOptionUnionParam) GetFunction() *ChatCompletionNamedToolChoiceFunctionParam {
2060− if vt := u.OfChatCompletionNamedToolChoice; vt != nil {
2061− return &vt.Function
2062− }
2063− return nil
2064−}
1986+// `none` means the model will not call any tool and instead generates a message.
1987+// `auto` means the model can pick between generating a message or calling one or
1988+// more tools. `required` means the model must call one or more tools.
1989+type ChatCompletionToolChoiceOptionAuto string
20651990
2066−// Returns a pointer to the underlying variant's property, if present.
2067−func (u ChatCompletionToolChoiceOptionUnionParam) GetType() *string {
2068− if vt := u.OfChatCompletionNamedToolChoice; vt != nil {
2069− return (*string)(&vt.Type)
2070− }
2071− return nil
2072−}
1991+const (
1992+ ChatCompletionToolChoiceOptionAutoNone ChatCompletionToolChoiceOptionAuto = "none"
1993+ ChatCompletionToolChoiceOptionAutoAuto ChatCompletionToolChoiceOptionAuto = "auto"
1994+ ChatCompletionToolChoiceOptionAutoRequired ChatCompletionToolChoiceOptionAuto = "required"
1995+)
20731996
20741997// The properties Content, Role, ToolCallID are required.
20751998type ChatCompletionToolMessageParam struct {
@@ -2084,13 +2007,13 @@ type ChatCompletionToolMessageParam struct {
20842007 paramObj
20852008}
20862009
2087−// IsPresent returns true if the field's value is not omitted and not the JSON
2088−// "null". To check if this field is omitted, use [param.IsOmitted].
2089−func (f ChatCompletionToolMessageParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
20902010func (r ChatCompletionToolMessageParam) MarshalJSON() (data []byte, err error) {
20912011 type shadow ChatCompletionToolMessageParam
20922012 return param.MarshalObject(r, (*shadow)(&r))
20932013}
2014+func (r *ChatCompletionToolMessageParam) UnmarshalJSON(data []byte) error {
2015+ return apijson.UnmarshalRoot(data, r)
2016+}
20942017
20952018// Only one field can be non-zero.
20962019//
@@ -2101,13 +2024,11 @@ type ChatCompletionToolMessageParamContentUnion struct {
21012024 paramUnion
21022025}
21032026
2104−// IsPresent returns true if the field's value is not omitted and not the JSON
2105−// "null". To check if this field is omitted, use [param.IsOmitted].
2106−func (u ChatCompletionToolMessageParamContentUnion) IsPresent() bool {
2107− return !param.IsOmitted(u) && !u.IsNull()
2108−}
21092027func (u ChatCompletionToolMessageParamContentUnion) MarshalJSON() ([]byte, error) {
2110− return param.MarshalUnion[ChatCompletionToolMessageParamContentUnion](u.OfString, u.OfArrayOfContentParts)
2028+ return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
2029+}
2030+func (u *ChatCompletionToolMessageParamContentUnion) UnmarshalJSON(data []byte) error {
2031+ return apijson.UnmarshalRoot(data, u)
21112032}
21122033
21132034func (u *ChatCompletionToolMessageParamContentUnion) asAny() any {
@@ -2136,13 +2057,13 @@ type ChatCompletionUserMessageParam struct {
21362057 paramObj
21372058}
21382059
2139−// IsPresent returns true if the field's value is not omitted and not the JSON
2140−// "null". To check if this field is omitted, use [param.IsOmitted].
2141−func (f ChatCompletionUserMessageParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
21422060func (r ChatCompletionUserMessageParam) MarshalJSON() (data []byte, err error) {
21432061 type shadow ChatCompletionUserMessageParam
21442062 return param.MarshalObject(r, (*shadow)(&r))
21452063}
2064+func (r *ChatCompletionUserMessageParam) UnmarshalJSON(data []byte) error {
2065+ return apijson.UnmarshalRoot(data, r)
2066+}
21462067
21472068// Only one field can be non-zero.
21482069//
@@ -2153,13 +2074,11 @@ type ChatCompletionUserMessageParamContentUnion struct {
21532074 paramUnion
21542075}
21552076
2156−// IsPresent returns true if the field's value is not omitted and not the JSON
2157−// "null". To check if this field is omitted, use [param.IsOmitted].
2158−func (u ChatCompletionUserMessageParamContentUnion) IsPresent() bool {
2159− return !param.IsOmitted(u) && !u.IsNull()
2160−}
21612077func (u ChatCompletionUserMessageParamContentUnion) MarshalJSON() ([]byte, error) {
2162− return param.MarshalUnion[ChatCompletionUserMessageParamContentUnion](u.OfString, u.OfArrayOfContentParts)
2078+ return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
2079+}
2080+func (u *ChatCompletionUserMessageParamContentUnion) UnmarshalJSON(data []byte) error {
2081+ return apijson.UnmarshalRoot(data, u)
21632082}
21642083
21652084func (u *ChatCompletionUserMessageParamContentUnion) asAny() any {
@@ -2179,7 +2098,7 @@ type ChatCompletionNewParams struct {
21792098 // [images](https://platform.openai.com/docs/guides/vision), and
21802099 // [audio](https://platform.openai.com/docs/guides/audio).
21812100 Messages []ChatCompletionMessageParamUnion `json:"messages,omitzero,required"`
2182− // Model ID used to generate the response, like `gpt-4o` or `o1`. OpenAI offers a
2101+ // Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a
21832102 // wide range of models with different capabilities, performance characteristics,
21842103 // and price points. Refer to the
21852104 // [model guide](https://platform.openai.com/docs/models) to browse and compare
@@ -2203,7 +2122,7 @@ type ChatCompletionNewParams struct {
22032122 //
22042123 // This value is now deprecated in favor of `max_completion_tokens`, and is not
22052124 // compatible with
2206− // [o1 series models](https://platform.openai.com/docs/guides/reasoning).
2125+ // [o-series models](https://platform.openai.com/docs/guides/reasoning).
22072126 MaxTokens param.Opt[int64] `json:"max_tokens,omitzero"`
22082127 // How many chat completion choices to generate for each input message. Note that
22092128 // you will be charged based on the number of generated tokens across all of the
@@ -2222,6 +2141,8 @@ type ChatCompletionNewParams struct {
22222141 // Whether or not to store the output of this chat completion request for use in
22232142 // our [model distillation](https://platform.openai.com/docs/guides/distillation)
22242143 // or [evals](https://platform.openai.com/docs/guides/evals) products.
2144+ //
2145+ // Supports text and image inputs. Note: image inputs over 10MB will be dropped.
22252146 Store param.Opt[bool] `json:"store,omitzero"`
22262147 // What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
22272148 // make the output more random, while lower values like 0.2 will make it more
@@ -2242,8 +2163,8 @@ type ChatCompletionNewParams struct {
22422163 // [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
22432164 // during tool use.
22442165 ParallelToolCalls param.Opt[bool] `json:"parallel_tool_calls,omitzero"`
2245− // A unique identifier representing your end-user, which can help OpenAI to monitor
2246− // and detect abuse.
2166+ // A stable identifier for your end-users. Used to boost cache hit rates by better
2167+ // bucketing similar requests and to help OpenAI detect and prevent abuse.
22472168 // [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
22482169 User param.Opt[string] `json:"user,omitzero"`
22492170 // Parameters for audio output. Required when audio output is requested with
@@ -2265,7 +2186,7 @@ type ChatCompletionNewParams struct {
22652186 //
22662187 // Keys are strings with a maximum length of 64 characters. Values are strings with
22672188 // a maximum length of 512 characters.
2268− Metadata shared.MetadataParam `json:"metadata,omitzero"`
2189+ Metadata shared.Metadata `json:"metadata,omitzero"`
22692190 // Output types that you would like the model to generate. Most models are capable
22702191 // of generating text, which is the default:
22712192 //
@@ -2276,6 +2197,8 @@ type ChatCompletionNewParams struct {
22762197 // this model generate both text and audio responses, you can use:
22772198 //
22782199 // `["text", "audio"]`
2200+ //
2201+ // Any of "text", "audio".
22792202 Modalities []string `json:"modalities,omitzero"`
22802203 // **o-series models only**
22812204 //
@@ -2286,23 +2209,28 @@ type ChatCompletionNewParams struct {
22862209 //
22872210 // Any of "low", "medium", "high".
22882211 ReasoningEffort shared.ReasoningEffort `json:"reasoning_effort,omitzero"`
2289− // Specifies the latency tier to use for processing the request. This parameter is
2290− // relevant for customers subscribed to the scale tier service:
2291− //
2292− // - If set to 'auto', and the Project is Scale tier enabled, the system will
2293− // utilize scale tier credits until they are exhausted.
2294− // - If set to 'auto', and the Project is not Scale tier enabled, the request will
2295− // be processed using the default service tier with a lower uptime SLA and no
2296− // latency guarentee.
2297− // - If set to 'default', the request will be processed using the default service
2298− // tier with a lower uptime SLA and no latency guarentee.
2212+ // Specifies the processing type used for serving the request.
2213+ //
2214+ // - If set to 'auto', then the request will be processed with the service tier
2215+ // configured in the Project settings. Unless otherwise configured, the Project
2216+ // will use 'default'.
2217+ // - If set to 'default', then the requset will be processed with the standard
2218+ // pricing and performance for the selected model.
2219+ // - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
2220+ // 'priority', then the request will be processed with the corresponding service
2221+ // tier. [Contact sales](https://openai.com/contact-sales) to learn more about
2222+ // Priority processing.
22992223 // - When not set, the default behavior is 'auto'.
23002224 //
2301− // When this parameter is set, the response body will include the `service_tier`
2302− // utilized.
2225+ // When the `service_tier` parameter is set, the response body will include the
2226+ // `service_tier` value based on the processing mode actually used to serve the
2227+ // request. This response value may be different from the value set in the
2228+ // parameter.
23032229 //
2304− // Any of "auto", "default".
2230+ // Any of "auto", "default", "flex", "scale", "priority".
23052231 ServiceTier ChatCompletionNewParamsServiceTier `json:"service_tier,omitzero"`
2232+ // Not supported with latest reasoning models `o3` and `o4-mini`.
2233+ //
23062234 // Up to 4 sequences where the API will stop generating further tokens. The
23072235 // returned text will not contain the stop sequence.
23082236 Stop ChatCompletionNewParamsStopUnion `json:"stop,omitzero"`
@@ -2362,14 +2290,13 @@ type ChatCompletionNewParams struct {
23622290 paramObj
23632291}
23642292
2365−// IsPresent returns true if the field's value is not omitted and not the JSON
2366−// "null". To check if this field is omitted, use [param.IsOmitted].
2367−func (f ChatCompletionNewParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
2368−
23692293func (r ChatCompletionNewParams) MarshalJSON() (data []byte, err error) {
23702294 type shadow ChatCompletionNewParams
23712295 return param.MarshalObject(r, (*shadow)(&r))
23722296}
2297+func (r *ChatCompletionNewParams) UnmarshalJSON(data []byte) error {
2298+ return apijson.UnmarshalRoot(data, r)
2299+}
23732300
23742301// Only one field can be non-zero.
23752302//
@@ -2381,13 +2308,11 @@ type ChatCompletionNewParamsFunctionCallUnion struct {
23812308 paramUnion
23822309}
23832310
2384−// IsPresent returns true if the field's value is not omitted and not the JSON
2385−// "null". To check if this field is omitted, use [param.IsOmitted].
2386−func (u ChatCompletionNewParamsFunctionCallUnion) IsPresent() bool {
2387− return !param.IsOmitted(u) && !u.IsNull()
2388−}
23892311func (u ChatCompletionNewParamsFunctionCallUnion) MarshalJSON() ([]byte, error) {
2390− return param.MarshalUnion[ChatCompletionNewParamsFunctionCallUnion](u.OfFunctionCallMode, u.OfFunctionCallOption)
2312+ return param.MarshalUnion(u, u.OfFunctionCallMode, u.OfFunctionCallOption)
2313+}
2314+func (u *ChatCompletionNewParamsFunctionCallUnion) UnmarshalJSON(data []byte) error {
2315+ return apijson.UnmarshalRoot(data, u)
23912316}
23922317
23932318func (u *ChatCompletionNewParamsFunctionCallUnion) asAny() any {
@@ -2399,13 +2324,15 @@ func (u *ChatCompletionNewParamsFunctionCallUnion) asAny() any {
23992324 return nil
24002325}
24012326
2402−// Returns a pointer to the underlying variant's property, if present.
2403−func (u ChatCompletionNewParamsFunctionCallUnion) GetName() *string {
2404− if vt := u.OfFunctionCallOption; vt != nil {
2405− return &vt.Name
2406− }
2407− return nil
2408−}
2327+// `none` means the model will not call a function and instead generates a message.
2328+// `auto` means the model can pick between generating a message or calling a
2329+// function.
2330+type ChatCompletionNewParamsFunctionCallFunctionCallMode string
2331+
2332+const (
2333+ ChatCompletionNewParamsFunctionCallFunctionCallModeNone ChatCompletionNewParamsFunctionCallFunctionCallMode = "none"
2334+ ChatCompletionNewParamsFunctionCallFunctionCallModeAuto ChatCompletionNewParamsFunctionCallFunctionCallMode = "auto"
2335+)
24092336
24102337// Deprecated: deprecated
24112338//
@@ -2428,13 +2355,13 @@ type ChatCompletionNewParamsFunction struct {
24282355 paramObj
24292356}
24302357
2431−// IsPresent returns true if the field's value is not omitted and not the JSON
2432−// "null". To check if this field is omitted, use [param.IsOmitted].
2433−func (f ChatCompletionNewParamsFunction) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
24342358func (r ChatCompletionNewParamsFunction) MarshalJSON() (data []byte, err error) {
24352359 type shadow ChatCompletionNewParamsFunction
24362360 return param.MarshalObject(r, (*shadow)(&r))
24372361}
2362+func (r *ChatCompletionNewParamsFunction) UnmarshalJSON(data []byte) error {
2363+ return apijson.UnmarshalRoot(data, r)
2364+}
24382365
24392366// Only one field can be non-zero.
24402367//
@@ -2446,13 +2373,11 @@ type ChatCompletionNewParamsResponseFormatUnion struct {
24462373 paramUnion
24472374}
24482375
2449−// IsPresent returns true if the field's value is not omitted and not the JSON
2450−// "null". To check if this field is omitted, use [param.IsOmitted].
2451−func (u ChatCompletionNewParamsResponseFormatUnion) IsPresent() bool {
2452− return !param.IsOmitted(u) && !u.IsNull()
2453−}
24542376func (u ChatCompletionNewParamsResponseFormatUnion) MarshalJSON() ([]byte, error) {
2455− return param.MarshalUnion[ChatCompletionNewParamsResponseFormatUnion](u.OfText, u.OfJSONSchema, u.OfJSONObject)
2377+ return param.MarshalUnion(u, u.OfText, u.OfJSONSchema, u.OfJSONObject)
2378+}
2379+func (u *ChatCompletionNewParamsResponseFormatUnion) UnmarshalJSON(data []byte) error {
2380+ return apijson.UnmarshalRoot(data, u)
24562381}
24572382
24582383func (u *ChatCompletionNewParamsResponseFormatUnion) asAny() any {
@@ -2486,48 +2411,54 @@ func (u ChatCompletionNewParamsResponseFormatUnion) GetType() *string {
24862411 return nil
24872412}
24882413
2489−// Specifies the latency tier to use for processing the request. This parameter is
2490−// relevant for customers subscribed to the scale tier service:
2414+// Specifies the processing type used for serving the request.
24912415//
2492−// - If set to 'auto', and the Project is Scale tier enabled, the system will
2493−// utilize scale tier credits until they are exhausted.
2494−// - If set to 'auto', and the Project is not Scale tier enabled, the request will
2495−// be processed using the default service tier with a lower uptime SLA and no
2496−// latency guarentee.
2497−// - If set to 'default', the request will be processed using the default service
2498−// tier with a lower uptime SLA and no latency guarentee.
2416+// - If set to 'auto', then the request will be processed with the service tier
2417+// configured in the Project settings. Unless otherwise configured, the Project
2418+// will use 'default'.
2419+// - If set to 'default', then the requset will be processed with the standard
2420+// pricing and performance for the selected model.
2421+// - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
2422+// 'priority', then the request will be processed with the corresponding service
2423+// tier. [Contact sales](https://openai.com/contact-sales) to learn more about
2424+// Priority processing.
24992425// - When not set, the default behavior is 'auto'.
25002426//
2501−// When this parameter is set, the response body will include the `service_tier`
2502−// utilized.
2427+// When the `service_tier` parameter is set, the response body will include the
2428+// `service_tier` value based on the processing mode actually used to serve the
2429+// request. This response value may be different from the value set in the
2430+// parameter.
25032431type ChatCompletionNewParamsServiceTier string
25042432
25052433const (
2506− ChatCompletionNewParamsServiceTierAuto ChatCompletionNewParamsServiceTier = "auto"
2507− ChatCompletionNewParamsServiceTierDefault ChatCompletionNewParamsServiceTier = "default"
2434+ ChatCompletionNewParamsServiceTierAuto ChatCompletionNewParamsServiceTier = "auto"
2435+ ChatCompletionNewParamsServiceTierDefault ChatCompletionNewParamsServiceTier = "default"
2436+ ChatCompletionNewParamsServiceTierFlex ChatCompletionNewParamsServiceTier = "flex"
2437+ ChatCompletionNewParamsServiceTierScale ChatCompletionNewParamsServiceTier = "scale"
2438+ ChatCompletionNewParamsServiceTierPriority ChatCompletionNewParamsServiceTier = "priority"
25082439)
25092440
25102441// Only one field can be non-zero.
25112442//
25122443// Use [param.IsOmitted] to confirm if a field is set.
25132444type ChatCompletionNewParamsStopUnion struct {
2514− OfString param.Opt[string] `json:",omitzero,inline"`
2515− OfChatCompletionNewsStopArray []string `json:",omitzero,inline"`
2445+ OfString param.Opt[string] `json:",omitzero,inline"`
2446+ OfStringArray []string `json:",omitzero,inline"`
25162447 paramUnion
25172448}
25182449
2519−// IsPresent returns true if the field's value is not omitted and not the JSON
2520−// "null". To check if this field is omitted, use [param.IsOmitted].
2521−func (u ChatCompletionNewParamsStopUnion) IsPresent() bool { return !param.IsOmitted(u) && !u.IsNull() }
25222450func (u ChatCompletionNewParamsStopUnion) MarshalJSON() ([]byte, error) {
2523− return param.MarshalUnion[ChatCompletionNewParamsStopUnion](u.OfString, u.OfChatCompletionNewsStopArray)
2451+ return param.MarshalUnion(u, u.OfString, u.OfStringArray)
2452+}
2453+func (u *ChatCompletionNewParamsStopUnion) UnmarshalJSON(data []byte) error {
2454+ return apijson.UnmarshalRoot(data, u)
25242455}
25252456
25262457func (u *ChatCompletionNewParamsStopUnion) asAny() any {
25272458 if !param.IsOmitted(u.OfString) {
25282459 return &u.OfString.Value
2529− } else if !param.IsOmitted(u.OfChatCompletionNewsStopArray) {
2530− return &u.OfChatCompletionNewsStopArray
2460+ } else if !param.IsOmitted(u.OfStringArray) {
2461+ return &u.OfStringArray
25312462 }
25322463 return nil
25332464}
@@ -2546,19 +2477,17 @@ type ChatCompletionNewParamsWebSearchOptions struct {
25462477 paramObj
25472478}
25482479
2549−// IsPresent returns true if the field's value is not omitted and not the JSON
2550−// "null". To check if this field is omitted, use [param.IsOmitted].
2551−func (f ChatCompletionNewParamsWebSearchOptions) IsPresent() bool {
2552− return !param.IsOmitted(f) && !f.IsNull()
2553−}
25542480func (r ChatCompletionNewParamsWebSearchOptions) MarshalJSON() (data []byte, err error) {
25552481 type shadow ChatCompletionNewParamsWebSearchOptions
25562482 return param.MarshalObject(r, (*shadow)(&r))
25572483}
2484+func (r *ChatCompletionNewParamsWebSearchOptions) UnmarshalJSON(data []byte) error {
2485+ return apijson.UnmarshalRoot(data, r)
2486+}
25582487
25592488func init() {
25602489 apijson.RegisterFieldValidator[ChatCompletionNewParamsWebSearchOptions](
2561− "SearchContextSize", false, "low", "medium", "high",
2490+ "search_context_size", "low", "medium", "high",
25622491 )
25632492}
25642493
@@ -2575,15 +2504,13 @@ type ChatCompletionNewParamsWebSearchOptionsUserLocation struct {
25752504 paramObj
25762505}
25772506
2578−// IsPresent returns true if the field's value is not omitted and not the JSON
2579−// "null". To check if this field is omitted, use [param.IsOmitted].
2580−func (f ChatCompletionNewParamsWebSearchOptionsUserLocation) IsPresent() bool {
2581− return !param.IsOmitted(f) && !f.IsNull()
2582−}
25832507func (r ChatCompletionNewParamsWebSearchOptionsUserLocation) MarshalJSON() (data []byte, err error) {
25842508 type shadow ChatCompletionNewParamsWebSearchOptionsUserLocation
25852509 return param.MarshalObject(r, (*shadow)(&r))
25862510}
2511+func (r *ChatCompletionNewParamsWebSearchOptionsUserLocation) UnmarshalJSON(data []byte) error {
2512+ return apijson.UnmarshalRoot(data, r)
2513+}
25872514
25882515// Approximate location parameters for the search.
25892516type ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate struct {
@@ -2600,15 +2527,13 @@ type ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate struct {
26002527 paramObj
26012528}
26022529
2603−// IsPresent returns true if the field's value is not omitted and not the JSON
2604−// "null". To check if this field is omitted, use [param.IsOmitted].
2605−func (f ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate) IsPresent() bool {
2606− return !param.IsOmitted(f) && !f.IsNull()
2607−}
26082530func (r ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate) MarshalJSON() (data []byte, err error) {
26092531 type shadow ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate
26102532 return param.MarshalObject(r, (*shadow)(&r))
26112533}
2534+func (r *ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate) UnmarshalJSON(data []byte) error {
2535+ return apijson.UnmarshalRoot(data, r)
2536+}
26122537
26132538type ChatCompletionUpdateParams struct {
26142539 // Set of 16 key-value pairs that can be attached to an object. This can be useful
@@ -2617,18 +2542,17 @@ type ChatCompletionUpdateParams struct {
26172542 //
26182543 // Keys are strings with a maximum length of 64 characters. Values are strings with
26192544 // a maximum length of 512 characters.
2620− Metadata shared.MetadataParam `json:"metadata,omitzero,required"`
2545+ Metadata shared.Metadata `json:"metadata,omitzero,required"`
26212546 paramObj
26222547}
26232548
2624−// IsPresent returns true if the field's value is not omitted and not the JSON
2625−// "null". To check if this field is omitted, use [param.IsOmitted].
2626−func (f ChatCompletionUpdateParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
2627−
26282549func (r ChatCompletionUpdateParams) MarshalJSON() (data []byte, err error) {
26292550 type shadow ChatCompletionUpdateParams
26302551 return param.MarshalObject(r, (*shadow)(&r))
26312552}
2553+func (r *ChatCompletionUpdateParams) UnmarshalJSON(data []byte) error {
2554+ return apijson.UnmarshalRoot(data, r)
2555+}
26322556
26332557type ChatCompletionListParams struct {
26342558 // Identifier for the last chat completion from the previous pagination request.
@@ -2640,7 +2564,7 @@ type ChatCompletionListParams struct {
26402564 // A list of metadata keys to filter the Chat Completions by. Example:
26412565 //
26422566 // `metadata[key1]=value1&metadata[key2]=value2`
2643− Metadata shared.MetadataParam `query:"metadata,omitzero" json:"-"`
2567+ Metadata shared.Metadata `query:"metadata,omitzero" json:"-"`
26442568 // Sort order for Chat Completions by timestamp. Use `asc` for ascending order or
26452569 // `desc` for descending order. Defaults to `asc`.
26462570 //
@@ -2649,13 +2573,9 @@ type ChatCompletionListParams struct {
26492573 paramObj
26502574}
26512575
2652−// IsPresent returns true if the field's value is not omitted and not the JSON
2653−// "null". To check if this field is omitted, use [param.IsOmitted].
2654−func (f ChatCompletionListParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
2655−
26562576// URLQuery serializes [ChatCompletionListParams]'s query parameters as
26572577// `url.Values`.
2658−func (r ChatCompletionListParams) URLQuery() (v url.Values) {
2578+func (r ChatCompletionListParams) URLQuery() (v url.Values, err error) {
26592579 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
26602580 ArrayFormat: apiquery.ArrayQueryFormatBrackets,
26612581 NestedFormat: apiquery.NestedQueryFormatBrackets,