chatcompletion.go

   1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
   2
   3package openai
   4
   5import (
   6	"context"
   7	"encoding/json"
   8	"errors"
   9	"fmt"
  10	"net/http"
  11	"net/url"
  12
  13	"github.com/openai/openai-go/internal/apijson"
  14	"github.com/openai/openai-go/internal/apiquery"
  15	"github.com/openai/openai-go/internal/requestconfig"
  16	"github.com/openai/openai-go/option"
  17	"github.com/openai/openai-go/packages/pagination"
  18	"github.com/openai/openai-go/packages/param"
  19	"github.com/openai/openai-go/packages/respjson"
  20	"github.com/openai/openai-go/packages/ssestream"
  21	"github.com/openai/openai-go/shared"
  22	"github.com/openai/openai-go/shared/constant"
  23)
  24
  25// ChatCompletionService contains methods and other services that help with
  26// interacting with the openai API.
  27//
  28// Note, unlike clients, this service does not read variables from the environment
  29// automatically. You should not instantiate this service directly, and instead use
  30// the [NewChatCompletionService] method instead.
  31type ChatCompletionService struct {
  32	Options  []option.RequestOption
  33	Messages ChatCompletionMessageService
  34}
  35
  36// NewChatCompletionService generates a new service that applies the given options
  37// to each request. These options are applied after the parent client's options (if
  38// there is one), and before any request-specific options.
  39func NewChatCompletionService(opts ...option.RequestOption) (r ChatCompletionService) {
  40	r = ChatCompletionService{}
  41	r.Options = opts
  42	r.Messages = NewChatCompletionMessageService(opts...)
  43	return
  44}
  45
  46// **Starting a new project?** We recommend trying
  47// [Responses](https://platform.openai.com/docs/api-reference/responses) to take
  48// advantage of the latest OpenAI platform features. Compare
  49// [Chat Completions with Responses](https://platform.openai.com/docs/guides/responses-vs-chat-completions?api-mode=responses).
  50//
  51// ---
  52//
  53// Creates a model response for the given chat conversation. Learn more in the
  54// [text generation](https://platform.openai.com/docs/guides/text-generation),
  55// [vision](https://platform.openai.com/docs/guides/vision), and
  56// [audio](https://platform.openai.com/docs/guides/audio) guides.
  57//
  58// Parameter support can differ depending on the model used to generate the
  59// response, particularly for newer reasoning models. Parameters that are only
  60// supported for reasoning models are noted below. For the current state of
  61// unsupported parameters in reasoning models,
  62// [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).
  63func (r *ChatCompletionService) New(ctx context.Context, body ChatCompletionNewParams, opts ...option.RequestOption) (res *ChatCompletion, err error) {
  64	opts = append(r.Options[:], opts...)
  65	path := "chat/completions"
  66	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  67	return
  68}
  69
  70// **Starting a new project?** We recommend trying
  71// [Responses](https://platform.openai.com/docs/api-reference/responses) to take
  72// advantage of the latest OpenAI platform features. Compare
  73// [Chat Completions with Responses](https://platform.openai.com/docs/guides/responses-vs-chat-completions?api-mode=responses).
  74//
  75// ---
  76//
  77// Creates a model response for the given chat conversation. Learn more in the
  78// [text generation](https://platform.openai.com/docs/guides/text-generation),
  79// [vision](https://platform.openai.com/docs/guides/vision), and
  80// [audio](https://platform.openai.com/docs/guides/audio) guides.
  81//
  82// Parameter support can differ depending on the model used to generate the
  83// response, particularly for newer reasoning models. Parameters that are only
  84// supported for reasoning models are noted below. For the current state of
  85// unsupported parameters in reasoning models,
  86// [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).
  87func (r *ChatCompletionService) NewStreaming(ctx context.Context, body ChatCompletionNewParams, opts ...option.RequestOption) (stream *ssestream.Stream[ChatCompletionChunk]) {
  88	var (
  89		raw *http.Response
  90		err error
  91	)
  92	opts = append(r.Options[:], opts...)
  93	opts = append([]option.RequestOption{option.WithJSONSet("stream", true)}, opts...)
  94	path := "chat/completions"
  95	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &raw, opts...)
  96	return ssestream.NewStream[ChatCompletionChunk](ssestream.NewDecoder(raw), err)
  97}
  98
  99// Get a stored chat completion. Only Chat Completions that have been created with
 100// the `store` parameter set to `true` will be returned.
 101func (r *ChatCompletionService) Get(ctx context.Context, completionID string, opts ...option.RequestOption) (res *ChatCompletion, err error) {
 102	opts = append(r.Options[:], opts...)
 103	if completionID == "" {
 104		err = errors.New("missing required completion_id parameter")
 105		return
 106	}
 107	path := fmt.Sprintf("chat/completions/%s", completionID)
 108	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
 109	return
 110}
 111
 112// Modify a stored chat completion. Only Chat Completions that have been created
 113// with the `store` parameter set to `true` can be modified. Currently, the only
 114// supported modification is to update the `metadata` field.
 115func (r *ChatCompletionService) Update(ctx context.Context, completionID string, body ChatCompletionUpdateParams, opts ...option.RequestOption) (res *ChatCompletion, err error) {
 116	opts = append(r.Options[:], opts...)
 117	if completionID == "" {
 118		err = errors.New("missing required completion_id parameter")
 119		return
 120	}
 121	path := fmt.Sprintf("chat/completions/%s", completionID)
 122	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
 123	return
 124}
 125
 126// List stored Chat Completions. Only Chat Completions that have been stored with
 127// the `store` parameter set to `true` will be returned.
 128func (r *ChatCompletionService) List(ctx context.Context, query ChatCompletionListParams, opts ...option.RequestOption) (res *pagination.CursorPage[ChatCompletion], err error) {
 129	var raw *http.Response
 130	opts = append(r.Options[:], opts...)
 131	opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
 132	path := "chat/completions"
 133	cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
 134	if err != nil {
 135		return nil, err
 136	}
 137	err = cfg.Execute()
 138	if err != nil {
 139		return nil, err
 140	}
 141	res.SetPageConfig(cfg, raw)
 142	return res, nil
 143}
 144
 145// List stored Chat Completions. Only Chat Completions that have been stored with
 146// the `store` parameter set to `true` will be returned.
 147func (r *ChatCompletionService) ListAutoPaging(ctx context.Context, query ChatCompletionListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[ChatCompletion] {
 148	return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
 149}
 150
 151// Delete a stored chat completion. Only Chat Completions that have been created
 152// with the `store` parameter set to `true` can be deleted.
 153func (r *ChatCompletionService) Delete(ctx context.Context, completionID string, opts ...option.RequestOption) (res *ChatCompletionDeleted, err error) {
 154	opts = append(r.Options[:], opts...)
 155	if completionID == "" {
 156		err = errors.New("missing required completion_id parameter")
 157		return
 158	}
 159	path := fmt.Sprintf("chat/completions/%s", completionID)
 160	err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
 161	return
 162}
 163
 164// Represents a chat completion response returned by model, based on the provided
 165// input.
 166type ChatCompletion struct {
 167	// A unique identifier for the chat completion.
 168	ID string `json:"id,required"`
 169	// A list of chat completion choices. Can be more than one if `n` is greater
 170	// than 1.
 171	Choices []ChatCompletionChoice `json:"choices,required"`
 172	// The Unix timestamp (in seconds) of when the chat completion was created.
 173	Created int64 `json:"created,required"`
 174	// The model used for the chat completion.
 175	Model string `json:"model,required"`
 176	// The object type, which is always `chat.completion`.
 177	Object constant.ChatCompletion `json:"object,required"`
 178	// Specifies the processing type used for serving the request.
 179	//
 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".
 197	ServiceTier ChatCompletionServiceTier `json:"service_tier,nullable"`
 198	// This fingerprint represents the backend configuration that the model runs with.
 199	//
 200	// Can be used in conjunction with the `seed` request parameter to understand when
 201	// backend changes have been made that might impact determinism.
 202	SystemFingerprint string `json:"system_fingerprint"`
 203	// Usage statistics for the completion request.
 204	Usage CompletionUsage `json:"usage"`
 205	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 206	JSON struct {
 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
 216		raw               string
 217	} `json:"-"`
 218}
 219
 220// Returns the unmodified JSON received from the API
 221func (r ChatCompletion) RawJSON() string { return r.JSON.raw }
 222func (r *ChatCompletion) UnmarshalJSON(data []byte) error {
 223	return apijson.UnmarshalRoot(data, r)
 224}
 225
 226type ChatCompletionChoice struct {
 227	// The reason the model stopped generating tokens. This will be `stop` if the model
 228	// hit a natural stop point or a provided stop sequence, `length` if the maximum
 229	// number of tokens specified in the request was reached, `content_filter` if
 230	// content was omitted due to a flag from our content filters, `tool_calls` if the
 231	// model called a tool, or `function_call` (deprecated) if the model called a
 232	// function.
 233	//
 234	// Any of "stop", "length", "tool_calls", "content_filter", "function_call".
 235	FinishReason string `json:"finish_reason,required"`
 236	// The index of the choice in the list of choices.
 237	Index int64 `json:"index,required"`
 238	// Log probability information for the choice.
 239	Logprobs ChatCompletionChoiceLogprobs `json:"logprobs,required"`
 240	// A chat completion message generated by the model.
 241	Message ChatCompletionMessage `json:"message,required"`
 242	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 243	JSON struct {
 244		FinishReason respjson.Field
 245		Index        respjson.Field
 246		Logprobs     respjson.Field
 247		Message      respjson.Field
 248		ExtraFields  map[string]respjson.Field
 249		raw          string
 250	} `json:"-"`
 251}
 252
 253// Returns the unmodified JSON received from the API
 254func (r ChatCompletionChoice) RawJSON() string { return r.JSON.raw }
 255func (r *ChatCompletionChoice) UnmarshalJSON(data []byte) error {
 256	return apijson.UnmarshalRoot(data, r)
 257}
 258
 259// Log probability information for the choice.
 260type ChatCompletionChoiceLogprobs struct {
 261	// A list of message content tokens with log probability information.
 262	Content []ChatCompletionTokenLogprob `json:"content,required"`
 263	// A list of message refusal tokens with log probability information.
 264	Refusal []ChatCompletionTokenLogprob `json:"refusal,required"`
 265	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 266	JSON struct {
 267		Content     respjson.Field
 268		Refusal     respjson.Field
 269		ExtraFields map[string]respjson.Field
 270		raw         string
 271	} `json:"-"`
 272}
 273
 274// Returns the unmodified JSON received from the API
 275func (r ChatCompletionChoiceLogprobs) RawJSON() string { return r.JSON.raw }
 276func (r *ChatCompletionChoiceLogprobs) UnmarshalJSON(data []byte) error {
 277	return apijson.UnmarshalRoot(data, r)
 278}
 279
 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.
 297type ChatCompletionServiceTier string
 298
 299const (
 300	ChatCompletionServiceTierAuto     ChatCompletionServiceTier = "auto"
 301	ChatCompletionServiceTierDefault  ChatCompletionServiceTier = "default"
 302	ChatCompletionServiceTierFlex     ChatCompletionServiceTier = "flex"
 303	ChatCompletionServiceTierScale    ChatCompletionServiceTier = "scale"
 304	ChatCompletionServiceTierPriority ChatCompletionServiceTier = "priority"
 305)
 306
 307// Messages sent by the model in response to user messages.
 308//
 309// The property Role is required.
 310type ChatCompletionAssistantMessageParam struct {
 311	// The refusal message by the assistant.
 312	Refusal param.Opt[string] `json:"refusal,omitzero"`
 313	// An optional name for the participant. Provides the model information to
 314	// differentiate between participants of the same role.
 315	Name param.Opt[string] `json:"name,omitzero"`
 316	// Data about a previous audio response from the model.
 317	// [Learn more](https://platform.openai.com/docs/guides/audio).
 318	Audio ChatCompletionAssistantMessageParamAudio `json:"audio,omitzero"`
 319	// The contents of the assistant message. Required unless `tool_calls` or
 320	// `function_call` is specified.
 321	Content ChatCompletionAssistantMessageParamContentUnion `json:"content,omitzero"`
 322	// Deprecated and replaced by `tool_calls`. The name and arguments of a function
 323	// that should be called, as generated by the model.
 324	//
 325	// Deprecated: deprecated
 326	FunctionCall ChatCompletionAssistantMessageParamFunctionCall `json:"function_call,omitzero"`
 327	// The tool calls generated by the model, such as function calls.
 328	ToolCalls []ChatCompletionMessageToolCallParam `json:"tool_calls,omitzero"`
 329	// The role of the messages author, in this case `assistant`.
 330	//
 331	// This field can be elided, and will marshal its zero value as "assistant".
 332	Role constant.Assistant `json:"role,required"`
 333	paramObj
 334}
 335
 336func (r ChatCompletionAssistantMessageParam) MarshalJSON() (data []byte, err error) {
 337	type shadow ChatCompletionAssistantMessageParam
 338	return param.MarshalObject(r, (*shadow)(&r))
 339}
 340func (r *ChatCompletionAssistantMessageParam) UnmarshalJSON(data []byte) error {
 341	return apijson.UnmarshalRoot(data, r)
 342}
 343
 344// Data about a previous audio response from the model.
 345// [Learn more](https://platform.openai.com/docs/guides/audio).
 346//
 347// The property ID is required.
 348type ChatCompletionAssistantMessageParamAudio struct {
 349	// Unique identifier for a previous audio response from the model.
 350	ID string `json:"id,required"`
 351	paramObj
 352}
 353
 354func (r ChatCompletionAssistantMessageParamAudio) MarshalJSON() (data []byte, err error) {
 355	type shadow ChatCompletionAssistantMessageParamAudio
 356	return param.MarshalObject(r, (*shadow)(&r))
 357}
 358func (r *ChatCompletionAssistantMessageParamAudio) UnmarshalJSON(data []byte) error {
 359	return apijson.UnmarshalRoot(data, r)
 360}
 361
 362// Only one field can be non-zero.
 363//
 364// Use [param.IsOmitted] to confirm if a field is set.
 365type ChatCompletionAssistantMessageParamContentUnion struct {
 366	OfString              param.Opt[string]                                                   `json:",omitzero,inline"`
 367	OfArrayOfContentParts []ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion `json:",omitzero,inline"`
 368	paramUnion
 369}
 370
 371func (u ChatCompletionAssistantMessageParamContentUnion) MarshalJSON() ([]byte, error) {
 372	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
 373}
 374func (u *ChatCompletionAssistantMessageParamContentUnion) UnmarshalJSON(data []byte) error {
 375	return apijson.UnmarshalRoot(data, u)
 376}
 377
 378func (u *ChatCompletionAssistantMessageParamContentUnion) asAny() any {
 379	if !param.IsOmitted(u.OfString) {
 380		return &u.OfString.Value
 381	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
 382		return &u.OfArrayOfContentParts
 383	}
 384	return nil
 385}
 386
 387// Only one field can be non-zero.
 388//
 389// Use [param.IsOmitted] to confirm if a field is set.
 390type ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion struct {
 391	OfText    *ChatCompletionContentPartTextParam    `json:",omitzero,inline"`
 392	OfRefusal *ChatCompletionContentPartRefusalParam `json:",omitzero,inline"`
 393	paramUnion
 394}
 395
 396func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) MarshalJSON() ([]byte, error) {
 397	return param.MarshalUnion(u, u.OfText, u.OfRefusal)
 398}
 399func (u *ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) UnmarshalJSON(data []byte) error {
 400	return apijson.UnmarshalRoot(data, u)
 401}
 402
 403func (u *ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) asAny() any {
 404	if !param.IsOmitted(u.OfText) {
 405		return u.OfText
 406	} else if !param.IsOmitted(u.OfRefusal) {
 407		return u.OfRefusal
 408	}
 409	return nil
 410}
 411
 412// Returns a pointer to the underlying variant's property, if present.
 413func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetText() *string {
 414	if vt := u.OfText; vt != nil {
 415		return &vt.Text
 416	}
 417	return nil
 418}
 419
 420// Returns a pointer to the underlying variant's property, if present.
 421func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetRefusal() *string {
 422	if vt := u.OfRefusal; vt != nil {
 423		return &vt.Refusal
 424	}
 425	return nil
 426}
 427
 428// Returns a pointer to the underlying variant's property, if present.
 429func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetType() *string {
 430	if vt := u.OfText; vt != nil {
 431		return (*string)(&vt.Type)
 432	} else if vt := u.OfRefusal; vt != nil {
 433		return (*string)(&vt.Type)
 434	}
 435	return nil
 436}
 437
 438func init() {
 439	apijson.RegisterUnion[ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion](
 440		"type",
 441		apijson.Discriminator[ChatCompletionContentPartTextParam]("text"),
 442		apijson.Discriminator[ChatCompletionContentPartRefusalParam]("refusal"),
 443	)
 444}
 445
 446// Deprecated and replaced by `tool_calls`. The name and arguments of a function
 447// that should be called, as generated by the model.
 448//
 449// Deprecated: deprecated
 450//
 451// The properties Arguments, Name are required.
 452type ChatCompletionAssistantMessageParamFunctionCall struct {
 453	// The arguments to call the function with, as generated by the model in JSON
 454	// format. Note that the model does not always generate valid JSON, and may
 455	// hallucinate parameters not defined by your function schema. Validate the
 456	// arguments in your code before calling your function.
 457	Arguments string `json:"arguments,required"`
 458	// The name of the function to call.
 459	Name string `json:"name,required"`
 460	paramObj
 461}
 462
 463func (r ChatCompletionAssistantMessageParamFunctionCall) MarshalJSON() (data []byte, err error) {
 464	type shadow ChatCompletionAssistantMessageParamFunctionCall
 465	return param.MarshalObject(r, (*shadow)(&r))
 466}
 467func (r *ChatCompletionAssistantMessageParamFunctionCall) UnmarshalJSON(data []byte) error {
 468	return apijson.UnmarshalRoot(data, r)
 469}
 470
 471// If the audio output modality is requested, this object contains data about the
 472// audio response from the model.
 473// [Learn more](https://platform.openai.com/docs/guides/audio).
 474type ChatCompletionAudio struct {
 475	// Unique identifier for this audio response.
 476	ID string `json:"id,required"`
 477	// Base64 encoded audio bytes generated by the model, in the format specified in
 478	// the request.
 479	Data string `json:"data,required"`
 480	// The Unix timestamp (in seconds) for when this audio response will no longer be
 481	// accessible on the server for use in multi-turn conversations.
 482	ExpiresAt int64 `json:"expires_at,required"`
 483	// Transcript of the audio generated by the model.
 484	Transcript string `json:"transcript,required"`
 485	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 486	JSON struct {
 487		ID          respjson.Field
 488		Data        respjson.Field
 489		ExpiresAt   respjson.Field
 490		Transcript  respjson.Field
 491		ExtraFields map[string]respjson.Field
 492		raw         string
 493	} `json:"-"`
 494}
 495
 496// Returns the unmodified JSON received from the API
 497func (r ChatCompletionAudio) RawJSON() string { return r.JSON.raw }
 498func (r *ChatCompletionAudio) UnmarshalJSON(data []byte) error {
 499	return apijson.UnmarshalRoot(data, r)
 500}
 501
 502// Parameters for audio output. Required when audio output is requested with
 503// `modalities: ["audio"]`.
 504// [Learn more](https://platform.openai.com/docs/guides/audio).
 505//
 506// The properties Format, Voice are required.
 507type ChatCompletionAudioParam struct {
 508	// Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
 509	// or `pcm16`.
 510	//
 511	// Any of "wav", "aac", "mp3", "flac", "opus", "pcm16".
 512	Format ChatCompletionAudioParamFormat `json:"format,omitzero,required"`
 513	// The voice the model uses to respond. Supported voices are `alloy`, `ash`,
 514	// `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, and `shimmer`.
 515	Voice ChatCompletionAudioParamVoice `json:"voice,omitzero,required"`
 516	paramObj
 517}
 518
 519func (r ChatCompletionAudioParam) MarshalJSON() (data []byte, err error) {
 520	type shadow ChatCompletionAudioParam
 521	return param.MarshalObject(r, (*shadow)(&r))
 522}
 523func (r *ChatCompletionAudioParam) UnmarshalJSON(data []byte) error {
 524	return apijson.UnmarshalRoot(data, r)
 525}
 526
 527// Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
 528// or `pcm16`.
 529type ChatCompletionAudioParamFormat string
 530
 531const (
 532	ChatCompletionAudioParamFormatWAV   ChatCompletionAudioParamFormat = "wav"
 533	ChatCompletionAudioParamFormatAAC   ChatCompletionAudioParamFormat = "aac"
 534	ChatCompletionAudioParamFormatMP3   ChatCompletionAudioParamFormat = "mp3"
 535	ChatCompletionAudioParamFormatFLAC  ChatCompletionAudioParamFormat = "flac"
 536	ChatCompletionAudioParamFormatOpus  ChatCompletionAudioParamFormat = "opus"
 537	ChatCompletionAudioParamFormatPcm16 ChatCompletionAudioParamFormat = "pcm16"
 538)
 539
 540// The voice the model uses to respond. Supported voices are `alloy`, `ash`,
 541// `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, and `shimmer`.
 542type ChatCompletionAudioParamVoice string
 543
 544const (
 545	ChatCompletionAudioParamVoiceAlloy   ChatCompletionAudioParamVoice = "alloy"
 546	ChatCompletionAudioParamVoiceAsh     ChatCompletionAudioParamVoice = "ash"
 547	ChatCompletionAudioParamVoiceBallad  ChatCompletionAudioParamVoice = "ballad"
 548	ChatCompletionAudioParamVoiceCoral   ChatCompletionAudioParamVoice = "coral"
 549	ChatCompletionAudioParamVoiceEcho    ChatCompletionAudioParamVoice = "echo"
 550	ChatCompletionAudioParamVoiceFable   ChatCompletionAudioParamVoice = "fable"
 551	ChatCompletionAudioParamVoiceOnyx    ChatCompletionAudioParamVoice = "onyx"
 552	ChatCompletionAudioParamVoiceNova    ChatCompletionAudioParamVoice = "nova"
 553	ChatCompletionAudioParamVoiceSage    ChatCompletionAudioParamVoice = "sage"
 554	ChatCompletionAudioParamVoiceShimmer ChatCompletionAudioParamVoice = "shimmer"
 555	ChatCompletionAudioParamVoiceVerse   ChatCompletionAudioParamVoice = "verse"
 556)
 557
 558// Represents a streamed chunk of a chat completion response returned by the model,
 559// based on the provided input.
 560// [Learn more](https://platform.openai.com/docs/guides/streaming-responses).
 561type ChatCompletionChunk struct {
 562	// A unique identifier for the chat completion. Each chunk has the same ID.
 563	ID string `json:"id,required"`
 564	// A list of chat completion choices. Can contain more than one elements if `n` is
 565	// greater than 1. Can also be empty for the last chunk if you set
 566	// `stream_options: {"include_usage": true}`.
 567	Choices []ChatCompletionChunkChoice `json:"choices,required"`
 568	// The Unix timestamp (in seconds) of when the chat completion was created. Each
 569	// chunk has the same timestamp.
 570	Created int64 `json:"created,required"`
 571	// The model to generate the completion.
 572	Model string `json:"model,required"`
 573	// The object type, which is always `chat.completion.chunk`.
 574	Object constant.ChatCompletionChunk `json:"object,required"`
 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.
 592	//
 593	// Any of "auto", "default", "flex", "scale", "priority".
 594	ServiceTier ChatCompletionChunkServiceTier `json:"service_tier,nullable"`
 595	// This fingerprint represents the backend configuration that the model runs with.
 596	// Can be used in conjunction with the `seed` request parameter to understand when
 597	// backend changes have been made that might impact determinism.
 598	SystemFingerprint string `json:"system_fingerprint"`
 599	// An optional field that will only be present when you set
 600	// `stream_options: {"include_usage": true}` in your request. When present, it
 601	// contains a null value **except for the last chunk** which contains the token
 602	// usage statistics for the entire request.
 603	//
 604	// **NOTE:** If the stream is interrupted or cancelled, you may not receive the
 605	// final usage chunk which contains the total token usage for the request.
 606	Usage CompletionUsage `json:"usage,nullable"`
 607	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 608	JSON struct {
 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
 618		raw               string
 619	} `json:"-"`
 620}
 621
 622// Returns the unmodified JSON received from the API
 623func (r ChatCompletionChunk) RawJSON() string { return r.JSON.raw }
 624func (r *ChatCompletionChunk) UnmarshalJSON(data []byte) error {
 625	return apijson.UnmarshalRoot(data, r)
 626}
 627
 628type ChatCompletionChunkChoice struct {
 629	// A chat completion delta generated by streamed model responses.
 630	Delta ChatCompletionChunkChoiceDelta `json:"delta,required"`
 631	// The reason the model stopped generating tokens. This will be `stop` if the model
 632	// hit a natural stop point or a provided stop sequence, `length` if the maximum
 633	// number of tokens specified in the request was reached, `content_filter` if
 634	// content was omitted due to a flag from our content filters, `tool_calls` if the
 635	// model called a tool, or `function_call` (deprecated) if the model called a
 636	// function.
 637	//
 638	// Any of "stop", "length", "tool_calls", "content_filter", "function_call".
 639	FinishReason string `json:"finish_reason,required"`
 640	// The index of the choice in the list of choices.
 641	Index int64 `json:"index,required"`
 642	// Log probability information for the choice.
 643	Logprobs ChatCompletionChunkChoiceLogprobs `json:"logprobs,nullable"`
 644	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 645	JSON struct {
 646		Delta        respjson.Field
 647		FinishReason respjson.Field
 648		Index        respjson.Field
 649		Logprobs     respjson.Field
 650		ExtraFields  map[string]respjson.Field
 651		raw          string
 652	} `json:"-"`
 653}
 654
 655// Returns the unmodified JSON received from the API
 656func (r ChatCompletionChunkChoice) RawJSON() string { return r.JSON.raw }
 657func (r *ChatCompletionChunkChoice) UnmarshalJSON(data []byte) error {
 658	return apijson.UnmarshalRoot(data, r)
 659}
 660
 661// A chat completion delta generated by streamed model responses.
 662type ChatCompletionChunkChoiceDelta struct {
 663	// The contents of the chunk message.
 664	Content string `json:"content,nullable"`
 665	// Deprecated and replaced by `tool_calls`. The name and arguments of a function
 666	// that should be called, as generated by the model.
 667	//
 668	// Deprecated: deprecated
 669	FunctionCall ChatCompletionChunkChoiceDeltaFunctionCall `json:"function_call"`
 670	// The refusal message generated by the model.
 671	Refusal string `json:"refusal,nullable"`
 672	// The role of the author of this message.
 673	//
 674	// Any of "developer", "system", "user", "assistant", "tool".
 675	Role      string                                   `json:"role"`
 676	ToolCalls []ChatCompletionChunkChoiceDeltaToolCall `json:"tool_calls"`
 677	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 678	JSON struct {
 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
 685		raw          string
 686	} `json:"-"`
 687}
 688
 689// Returns the unmodified JSON received from the API
 690func (r ChatCompletionChunkChoiceDelta) RawJSON() string { return r.JSON.raw }
 691func (r *ChatCompletionChunkChoiceDelta) UnmarshalJSON(data []byte) error {
 692	return apijson.UnmarshalRoot(data, r)
 693}
 694
 695// Deprecated and replaced by `tool_calls`. The name and arguments of a function
 696// that should be called, as generated by the model.
 697//
 698// Deprecated: deprecated
 699type ChatCompletionChunkChoiceDeltaFunctionCall struct {
 700	// The arguments to call the function with, as generated by the model in JSON
 701	// format. Note that the model does not always generate valid JSON, and may
 702	// hallucinate parameters not defined by your function schema. Validate the
 703	// arguments in your code before calling your function.
 704	Arguments string `json:"arguments"`
 705	// The name of the function to call.
 706	Name string `json:"name"`
 707	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 708	JSON struct {
 709		Arguments   respjson.Field
 710		Name        respjson.Field
 711		ExtraFields map[string]respjson.Field
 712		raw         string
 713	} `json:"-"`
 714}
 715
 716// Returns the unmodified JSON received from the API
 717func (r ChatCompletionChunkChoiceDeltaFunctionCall) RawJSON() string { return r.JSON.raw }
 718func (r *ChatCompletionChunkChoiceDeltaFunctionCall) UnmarshalJSON(data []byte) error {
 719	return apijson.UnmarshalRoot(data, r)
 720}
 721
 722type ChatCompletionChunkChoiceDeltaToolCall struct {
 723	Index int64 `json:"index,required"`
 724	// The ID of the tool call.
 725	ID       string                                         `json:"id"`
 726	Function ChatCompletionChunkChoiceDeltaToolCallFunction `json:"function"`
 727	// The type of the tool. Currently, only `function` is supported.
 728	//
 729	// Any of "function".
 730	Type string `json:"type"`
 731	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 732	JSON struct {
 733		Index       respjson.Field
 734		ID          respjson.Field
 735		Function    respjson.Field
 736		Type        respjson.Field
 737		ExtraFields map[string]respjson.Field
 738		raw         string
 739	} `json:"-"`
 740}
 741
 742// Returns the unmodified JSON received from the API
 743func (r ChatCompletionChunkChoiceDeltaToolCall) RawJSON() string { return r.JSON.raw }
 744func (r *ChatCompletionChunkChoiceDeltaToolCall) UnmarshalJSON(data []byte) error {
 745	return apijson.UnmarshalRoot(data, r)
 746}
 747
 748type ChatCompletionChunkChoiceDeltaToolCallFunction struct {
 749	// The arguments to call the function with, as generated by the model in JSON
 750	// format. Note that the model does not always generate valid JSON, and may
 751	// hallucinate parameters not defined by your function schema. Validate the
 752	// arguments in your code before calling your function.
 753	Arguments string `json:"arguments"`
 754	// The name of the function to call.
 755	Name string `json:"name"`
 756	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 757	JSON struct {
 758		Arguments   respjson.Field
 759		Name        respjson.Field
 760		ExtraFields map[string]respjson.Field
 761		raw         string
 762	} `json:"-"`
 763}
 764
 765// Returns the unmodified JSON received from the API
 766func (r ChatCompletionChunkChoiceDeltaToolCallFunction) RawJSON() string { return r.JSON.raw }
 767func (r *ChatCompletionChunkChoiceDeltaToolCallFunction) UnmarshalJSON(data []byte) error {
 768	return apijson.UnmarshalRoot(data, r)
 769}
 770
 771// Log probability information for the choice.
 772type ChatCompletionChunkChoiceLogprobs struct {
 773	// A list of message content tokens with log probability information.
 774	Content []ChatCompletionTokenLogprob `json:"content,required"`
 775	// A list of message refusal tokens with log probability information.
 776	Refusal []ChatCompletionTokenLogprob `json:"refusal,required"`
 777	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 778	JSON struct {
 779		Content     respjson.Field
 780		Refusal     respjson.Field
 781		ExtraFields map[string]respjson.Field
 782		raw         string
 783	} `json:"-"`
 784}
 785
 786// Returns the unmodified JSON received from the API
 787func (r ChatCompletionChunkChoiceLogprobs) RawJSON() string { return r.JSON.raw }
 788func (r *ChatCompletionChunkChoiceLogprobs) UnmarshalJSON(data []byte) error {
 789	return apijson.UnmarshalRoot(data, r)
 790}
 791
 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.
 809type ChatCompletionChunkServiceTier string
 810
 811const (
 812	ChatCompletionChunkServiceTierAuto     ChatCompletionChunkServiceTier = "auto"
 813	ChatCompletionChunkServiceTierDefault  ChatCompletionChunkServiceTier = "default"
 814	ChatCompletionChunkServiceTierFlex     ChatCompletionChunkServiceTier = "flex"
 815	ChatCompletionChunkServiceTierScale    ChatCompletionChunkServiceTier = "scale"
 816	ChatCompletionChunkServiceTierPriority ChatCompletionChunkServiceTier = "priority"
 817)
 818
 819func TextContentPart(text string) ChatCompletionContentPartUnionParam {
 820	var variant ChatCompletionContentPartTextParam
 821	variant.Text = text
 822	return ChatCompletionContentPartUnionParam{OfText: &variant}
 823}
 824
 825func ImageContentPart(imageURL ChatCompletionContentPartImageImageURLParam) ChatCompletionContentPartUnionParam {
 826	var variant ChatCompletionContentPartImageParam
 827	variant.ImageURL = imageURL
 828	return ChatCompletionContentPartUnionParam{OfImageURL: &variant}
 829}
 830
 831func InputAudioContentPart(inputAudio ChatCompletionContentPartInputAudioInputAudioParam) ChatCompletionContentPartUnionParam {
 832	var variant ChatCompletionContentPartInputAudioParam
 833	variant.InputAudio = inputAudio
 834	return ChatCompletionContentPartUnionParam{OfInputAudio: &variant}
 835}
 836
 837func FileContentPart(file ChatCompletionContentPartFileFileParam) ChatCompletionContentPartUnionParam {
 838	var variant ChatCompletionContentPartFileParam
 839	variant.File = file
 840	return ChatCompletionContentPartUnionParam{OfFile: &variant}
 841}
 842
 843// Only one field can be non-zero.
 844//
 845// Use [param.IsOmitted] to confirm if a field is set.
 846type ChatCompletionContentPartUnionParam struct {
 847	OfText       *ChatCompletionContentPartTextParam       `json:",omitzero,inline"`
 848	OfImageURL   *ChatCompletionContentPartImageParam      `json:",omitzero,inline"`
 849	OfInputAudio *ChatCompletionContentPartInputAudioParam `json:",omitzero,inline"`
 850	OfFile       *ChatCompletionContentPartFileParam       `json:",omitzero,inline"`
 851	paramUnion
 852}
 853
 854func (u ChatCompletionContentPartUnionParam) MarshalJSON() ([]byte, error) {
 855	return param.MarshalUnion(u, u.OfText, u.OfImageURL, u.OfInputAudio, u.OfFile)
 856}
 857func (u *ChatCompletionContentPartUnionParam) UnmarshalJSON(data []byte) error {
 858	return apijson.UnmarshalRoot(data, u)
 859}
 860
 861func (u *ChatCompletionContentPartUnionParam) asAny() any {
 862	if !param.IsOmitted(u.OfText) {
 863		return u.OfText
 864	} else if !param.IsOmitted(u.OfImageURL) {
 865		return u.OfImageURL
 866	} else if !param.IsOmitted(u.OfInputAudio) {
 867		return u.OfInputAudio
 868	} else if !param.IsOmitted(u.OfFile) {
 869		return u.OfFile
 870	}
 871	return nil
 872}
 873
 874// Returns a pointer to the underlying variant's property, if present.
 875func (u ChatCompletionContentPartUnionParam) GetText() *string {
 876	if vt := u.OfText; vt != nil {
 877		return &vt.Text
 878	}
 879	return nil
 880}
 881
 882// Returns a pointer to the underlying variant's property, if present.
 883func (u ChatCompletionContentPartUnionParam) GetImageURL() *ChatCompletionContentPartImageImageURLParam {
 884	if vt := u.OfImageURL; vt != nil {
 885		return &vt.ImageURL
 886	}
 887	return nil
 888}
 889
 890// Returns a pointer to the underlying variant's property, if present.
 891func (u ChatCompletionContentPartUnionParam) GetInputAudio() *ChatCompletionContentPartInputAudioInputAudioParam {
 892	if vt := u.OfInputAudio; vt != nil {
 893		return &vt.InputAudio
 894	}
 895	return nil
 896}
 897
 898// Returns a pointer to the underlying variant's property, if present.
 899func (u ChatCompletionContentPartUnionParam) GetFile() *ChatCompletionContentPartFileFileParam {
 900	if vt := u.OfFile; vt != nil {
 901		return &vt.File
 902	}
 903	return nil
 904}
 905
 906// Returns a pointer to the underlying variant's property, if present.
 907func (u ChatCompletionContentPartUnionParam) GetType() *string {
 908	if vt := u.OfText; vt != nil {
 909		return (*string)(&vt.Type)
 910	} else if vt := u.OfImageURL; vt != nil {
 911		return (*string)(&vt.Type)
 912	} else if vt := u.OfInputAudio; vt != nil {
 913		return (*string)(&vt.Type)
 914	} else if vt := u.OfFile; vt != nil {
 915		return (*string)(&vt.Type)
 916	}
 917	return nil
 918}
 919
 920func init() {
 921	apijson.RegisterUnion[ChatCompletionContentPartUnionParam](
 922		"type",
 923		apijson.Discriminator[ChatCompletionContentPartTextParam]("text"),
 924		apijson.Discriminator[ChatCompletionContentPartImageParam]("image_url"),
 925		apijson.Discriminator[ChatCompletionContentPartInputAudioParam]("input_audio"),
 926		apijson.Discriminator[ChatCompletionContentPartFileParam]("file"),
 927	)
 928}
 929
 930// Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text
 931// generation.
 932//
 933// The properties File, Type are required.
 934type ChatCompletionContentPartFileParam struct {
 935	File ChatCompletionContentPartFileFileParam `json:"file,omitzero,required"`
 936	// The type of the content part. Always `file`.
 937	//
 938	// This field can be elided, and will marshal its zero value as "file".
 939	Type constant.File `json:"type,required"`
 940	paramObj
 941}
 942
 943func (r ChatCompletionContentPartFileParam) MarshalJSON() (data []byte, err error) {
 944	type shadow ChatCompletionContentPartFileParam
 945	return param.MarshalObject(r, (*shadow)(&r))
 946}
 947func (r *ChatCompletionContentPartFileParam) UnmarshalJSON(data []byte) error {
 948	return apijson.UnmarshalRoot(data, r)
 949}
 950
 951type ChatCompletionContentPartFileFileParam struct {
 952	// The base64 encoded file data, used when passing the file to the model as a
 953	// string.
 954	FileData param.Opt[string] `json:"file_data,omitzero"`
 955	// The ID of an uploaded file to use as input.
 956	FileID param.Opt[string] `json:"file_id,omitzero"`
 957	// The name of the file, used when passing the file to the model as a string.
 958	Filename param.Opt[string] `json:"filename,omitzero"`
 959	paramObj
 960}
 961
 962func (r ChatCompletionContentPartFileFileParam) MarshalJSON() (data []byte, err error) {
 963	type shadow ChatCompletionContentPartFileFileParam
 964	return param.MarshalObject(r, (*shadow)(&r))
 965}
 966func (r *ChatCompletionContentPartFileFileParam) UnmarshalJSON(data []byte) error {
 967	return apijson.UnmarshalRoot(data, r)
 968}
 969
 970// Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
 971//
 972// The properties ImageURL, Type are required.
 973type ChatCompletionContentPartImageParam struct {
 974	ImageURL ChatCompletionContentPartImageImageURLParam `json:"image_url,omitzero,required"`
 975	// The type of the content part.
 976	//
 977	// This field can be elided, and will marshal its zero value as "image_url".
 978	Type constant.ImageURL `json:"type,required"`
 979	paramObj
 980}
 981
 982func (r ChatCompletionContentPartImageParam) MarshalJSON() (data []byte, err error) {
 983	type shadow ChatCompletionContentPartImageParam
 984	return param.MarshalObject(r, (*shadow)(&r))
 985}
 986func (r *ChatCompletionContentPartImageParam) UnmarshalJSON(data []byte) error {
 987	return apijson.UnmarshalRoot(data, r)
 988}
 989
 990// The property URL is required.
 991type ChatCompletionContentPartImageImageURLParam struct {
 992	// Either a URL of the image or the base64 encoded image data.
 993	URL string `json:"url,required" format:"uri"`
 994	// Specifies the detail level of the image. Learn more in the
 995	// [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
 996	//
 997	// Any of "auto", "low", "high".
 998	Detail string `json:"detail,omitzero"`
 999	paramObj
1000}
1001
1002func (r ChatCompletionContentPartImageImageURLParam) MarshalJSON() (data []byte, err error) {
1003	type shadow ChatCompletionContentPartImageImageURLParam
1004	return param.MarshalObject(r, (*shadow)(&r))
1005}
1006func (r *ChatCompletionContentPartImageImageURLParam) UnmarshalJSON(data []byte) error {
1007	return apijson.UnmarshalRoot(data, r)
1008}
1009
1010func init() {
1011	apijson.RegisterFieldValidator[ChatCompletionContentPartImageImageURLParam](
1012		"detail", "auto", "low", "high",
1013	)
1014}
1015
1016// Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
1017//
1018// The properties InputAudio, Type are required.
1019type ChatCompletionContentPartInputAudioParam struct {
1020	InputAudio ChatCompletionContentPartInputAudioInputAudioParam `json:"input_audio,omitzero,required"`
1021	// The type of the content part. Always `input_audio`.
1022	//
1023	// This field can be elided, and will marshal its zero value as "input_audio".
1024	Type constant.InputAudio `json:"type,required"`
1025	paramObj
1026}
1027
1028func (r ChatCompletionContentPartInputAudioParam) MarshalJSON() (data []byte, err error) {
1029	type shadow ChatCompletionContentPartInputAudioParam
1030	return param.MarshalObject(r, (*shadow)(&r))
1031}
1032func (r *ChatCompletionContentPartInputAudioParam) UnmarshalJSON(data []byte) error {
1033	return apijson.UnmarshalRoot(data, r)
1034}
1035
1036// The properties Data, Format are required.
1037type ChatCompletionContentPartInputAudioInputAudioParam struct {
1038	// Base64 encoded audio data.
1039	Data string `json:"data,required"`
1040	// The format of the encoded audio data. Currently supports "wav" and "mp3".
1041	//
1042	// Any of "wav", "mp3".
1043	Format string `json:"format,omitzero,required"`
1044	paramObj
1045}
1046
1047func (r ChatCompletionContentPartInputAudioInputAudioParam) MarshalJSON() (data []byte, err error) {
1048	type shadow ChatCompletionContentPartInputAudioInputAudioParam
1049	return param.MarshalObject(r, (*shadow)(&r))
1050}
1051func (r *ChatCompletionContentPartInputAudioInputAudioParam) UnmarshalJSON(data []byte) error {
1052	return apijson.UnmarshalRoot(data, r)
1053}
1054
1055func init() {
1056	apijson.RegisterFieldValidator[ChatCompletionContentPartInputAudioInputAudioParam](
1057		"format", "wav", "mp3",
1058	)
1059}
1060
1061// The properties Refusal, Type are required.
1062type ChatCompletionContentPartRefusalParam struct {
1063	// The refusal message generated by the model.
1064	Refusal string `json:"refusal,required"`
1065	// The type of the content part.
1066	//
1067	// This field can be elided, and will marshal its zero value as "refusal".
1068	Type constant.Refusal `json:"type,required"`
1069	paramObj
1070}
1071
1072func (r ChatCompletionContentPartRefusalParam) MarshalJSON() (data []byte, err error) {
1073	type shadow ChatCompletionContentPartRefusalParam
1074	return param.MarshalObject(r, (*shadow)(&r))
1075}
1076func (r *ChatCompletionContentPartRefusalParam) UnmarshalJSON(data []byte) error {
1077	return apijson.UnmarshalRoot(data, r)
1078}
1079
1080// Learn about
1081// [text inputs](https://platform.openai.com/docs/guides/text-generation).
1082//
1083// The properties Text, Type are required.
1084type ChatCompletionContentPartTextParam struct {
1085	// The text content.
1086	Text string `json:"text,required"`
1087	// The type of the content part.
1088	//
1089	// This field can be elided, and will marshal its zero value as "text".
1090	Type constant.Text `json:"type,required"`
1091	paramObj
1092}
1093
1094func (r ChatCompletionContentPartTextParam) MarshalJSON() (data []byte, err error) {
1095	type shadow ChatCompletionContentPartTextParam
1096	return param.MarshalObject(r, (*shadow)(&r))
1097}
1098func (r *ChatCompletionContentPartTextParam) UnmarshalJSON(data []byte) error {
1099	return apijson.UnmarshalRoot(data, r)
1100}
1101
1102type ChatCompletionDeleted struct {
1103	// The ID of the chat completion that was deleted.
1104	ID string `json:"id,required"`
1105	// Whether the chat completion was deleted.
1106	Deleted bool `json:"deleted,required"`
1107	// The type of object being deleted.
1108	Object constant.ChatCompletionDeleted `json:"object,required"`
1109	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1110	JSON struct {
1111		ID          respjson.Field
1112		Deleted     respjson.Field
1113		Object      respjson.Field
1114		ExtraFields map[string]respjson.Field
1115		raw         string
1116	} `json:"-"`
1117}
1118
1119// Returns the unmodified JSON received from the API
1120func (r ChatCompletionDeleted) RawJSON() string { return r.JSON.raw }
1121func (r *ChatCompletionDeleted) UnmarshalJSON(data []byte) error {
1122	return apijson.UnmarshalRoot(data, r)
1123}
1124
1125// Developer-provided instructions that the model should follow, regardless of
1126// messages sent by the user. With o1 models and newer, `developer` messages
1127// replace the previous `system` messages.
1128//
1129// The properties Content, Role are required.
1130type ChatCompletionDeveloperMessageParam struct {
1131	// The contents of the developer message.
1132	Content ChatCompletionDeveloperMessageParamContentUnion `json:"content,omitzero,required"`
1133	// An optional name for the participant. Provides the model information to
1134	// differentiate between participants of the same role.
1135	Name param.Opt[string] `json:"name,omitzero"`
1136	// The role of the messages author, in this case `developer`.
1137	//
1138	// This field can be elided, and will marshal its zero value as "developer".
1139	Role constant.Developer `json:"role,required"`
1140	paramObj
1141}
1142
1143func (r ChatCompletionDeveloperMessageParam) MarshalJSON() (data []byte, err error) {
1144	type shadow ChatCompletionDeveloperMessageParam
1145	return param.MarshalObject(r, (*shadow)(&r))
1146}
1147func (r *ChatCompletionDeveloperMessageParam) UnmarshalJSON(data []byte) error {
1148	return apijson.UnmarshalRoot(data, r)
1149}
1150
1151// Only one field can be non-zero.
1152//
1153// Use [param.IsOmitted] to confirm if a field is set.
1154type ChatCompletionDeveloperMessageParamContentUnion struct {
1155	OfString              param.Opt[string]                    `json:",omitzero,inline"`
1156	OfArrayOfContentParts []ChatCompletionContentPartTextParam `json:",omitzero,inline"`
1157	paramUnion
1158}
1159
1160func (u ChatCompletionDeveloperMessageParamContentUnion) MarshalJSON() ([]byte, error) {
1161	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
1162}
1163func (u *ChatCompletionDeveloperMessageParamContentUnion) UnmarshalJSON(data []byte) error {
1164	return apijson.UnmarshalRoot(data, u)
1165}
1166
1167func (u *ChatCompletionDeveloperMessageParamContentUnion) asAny() any {
1168	if !param.IsOmitted(u.OfString) {
1169		return &u.OfString.Value
1170	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
1171		return &u.OfArrayOfContentParts
1172	}
1173	return nil
1174}
1175
1176// Specifying a particular function via `{"name": "my_function"}` forces the model
1177// to call that function.
1178//
1179// The property Name is required.
1180type ChatCompletionFunctionCallOptionParam struct {
1181	// The name of the function to call.
1182	Name string `json:"name,required"`
1183	paramObj
1184}
1185
1186func (r ChatCompletionFunctionCallOptionParam) MarshalJSON() (data []byte, err error) {
1187	type shadow ChatCompletionFunctionCallOptionParam
1188	return param.MarshalObject(r, (*shadow)(&r))
1189}
1190func (r *ChatCompletionFunctionCallOptionParam) UnmarshalJSON(data []byte) error {
1191	return apijson.UnmarshalRoot(data, r)
1192}
1193
1194// Deprecated: deprecated
1195//
1196// The properties Content, Name, Role are required.
1197type ChatCompletionFunctionMessageParam struct {
1198	// The contents of the function message.
1199	Content param.Opt[string] `json:"content,omitzero,required"`
1200	// The name of the function to call.
1201	Name string `json:"name,required"`
1202	// The role of the messages author, in this case `function`.
1203	//
1204	// This field can be elided, and will marshal its zero value as "function".
1205	Role constant.Function `json:"role,required"`
1206	paramObj
1207}
1208
1209func (r ChatCompletionFunctionMessageParam) MarshalJSON() (data []byte, err error) {
1210	type shadow ChatCompletionFunctionMessageParam
1211	return param.MarshalObject(r, (*shadow)(&r))
1212}
1213func (r *ChatCompletionFunctionMessageParam) UnmarshalJSON(data []byte) error {
1214	return apijson.UnmarshalRoot(data, r)
1215}
1216
1217// A chat completion message generated by the model.
1218type ChatCompletionMessage struct {
1219	// The contents of the message.
1220	Content string `json:"content,required"`
1221	// The refusal message generated by the model.
1222	Refusal string `json:"refusal,required"`
1223	// The role of the author of this message.
1224	Role constant.Assistant `json:"role,required"`
1225	// Annotations for the message, when applicable, as when using the
1226	// [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
1227	Annotations []ChatCompletionMessageAnnotation `json:"annotations"`
1228	// If the audio output modality is requested, this object contains data about the
1229	// audio response from the model.
1230	// [Learn more](https://platform.openai.com/docs/guides/audio).
1231	Audio ChatCompletionAudio `json:"audio,nullable"`
1232	// Deprecated and replaced by `tool_calls`. The name and arguments of a function
1233	// that should be called, as generated by the model.
1234	//
1235	// Deprecated: deprecated
1236	FunctionCall ChatCompletionMessageFunctionCall `json:"function_call"`
1237	// The tool calls generated by the model, such as function calls.
1238	ToolCalls []ChatCompletionMessageToolCall `json:"tool_calls"`
1239	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1240	JSON struct {
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
1249		raw          string
1250	} `json:"-"`
1251}
1252
1253// Returns the unmodified JSON received from the API
1254func (r ChatCompletionMessage) RawJSON() string { return r.JSON.raw }
1255func (r *ChatCompletionMessage) UnmarshalJSON(data []byte) error {
1256	return apijson.UnmarshalRoot(data, r)
1257}
1258
1259func (r ChatCompletionMessage) ToParam() ChatCompletionMessageParamUnion {
1260	asst := r.ToAssistantMessageParam()
1261	return ChatCompletionMessageParamUnion{OfAssistant: &asst}
1262}
1263
1264func (r ChatCompletionMessage) ToAssistantMessageParam() ChatCompletionAssistantMessageParam {
1265	var p ChatCompletionAssistantMessageParam
1266
1267	// It is important to not rely on the JSON metadata property
1268	// here, it may be unset if the receiver was generated via a
1269	// [ChatCompletionAccumulator].
1270	//
1271	// Explicit null is intentionally elided from the response.
1272	if r.Content != "" {
1273		p.Content.OfString = String(r.Content)
1274	}
1275	if r.Refusal != "" {
1276		p.Refusal = String(r.Refusal)
1277	}
1278
1279	p.Audio.ID = r.Audio.ID
1280	p.Role = r.Role
1281	p.FunctionCall.Arguments = r.FunctionCall.Arguments
1282	p.FunctionCall.Name = r.FunctionCall.Name
1283
1284	if len(r.ToolCalls) > 0 {
1285		p.ToolCalls = make([]ChatCompletionMessageToolCallParam, len(r.ToolCalls))
1286		for i, v := range r.ToolCalls {
1287			p.ToolCalls[i].ID = v.ID
1288			p.ToolCalls[i].Function.Arguments = v.Function.Arguments
1289			p.ToolCalls[i].Function.Name = v.Function.Name
1290		}
1291	}
1292	return p
1293}
1294
1295// A URL citation when using web search.
1296type ChatCompletionMessageAnnotation struct {
1297	// The type of the URL citation. Always `url_citation`.
1298	Type constant.URLCitation `json:"type,required"`
1299	// A URL citation when using web search.
1300	URLCitation ChatCompletionMessageAnnotationURLCitation `json:"url_citation,required"`
1301	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1302	JSON struct {
1303		Type        respjson.Field
1304		URLCitation respjson.Field
1305		ExtraFields map[string]respjson.Field
1306		raw         string
1307	} `json:"-"`
1308}
1309
1310// Returns the unmodified JSON received from the API
1311func (r ChatCompletionMessageAnnotation) RawJSON() string { return r.JSON.raw }
1312func (r *ChatCompletionMessageAnnotation) UnmarshalJSON(data []byte) error {
1313	return apijson.UnmarshalRoot(data, r)
1314}
1315
1316// A URL citation when using web search.
1317type ChatCompletionMessageAnnotationURLCitation struct {
1318	// The index of the last character of the URL citation in the message.
1319	EndIndex int64 `json:"end_index,required"`
1320	// The index of the first character of the URL citation in the message.
1321	StartIndex int64 `json:"start_index,required"`
1322	// The title of the web resource.
1323	Title string `json:"title,required"`
1324	// The URL of the web resource.
1325	URL string `json:"url,required"`
1326	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1327	JSON struct {
1328		EndIndex    respjson.Field
1329		StartIndex  respjson.Field
1330		Title       respjson.Field
1331		URL         respjson.Field
1332		ExtraFields map[string]respjson.Field
1333		raw         string
1334	} `json:"-"`
1335}
1336
1337// Returns the unmodified JSON received from the API
1338func (r ChatCompletionMessageAnnotationURLCitation) RawJSON() string { return r.JSON.raw }
1339func (r *ChatCompletionMessageAnnotationURLCitation) UnmarshalJSON(data []byte) error {
1340	return apijson.UnmarshalRoot(data, r)
1341}
1342
1343// Deprecated and replaced by `tool_calls`. The name and arguments of a function
1344// that should be called, as generated by the model.
1345//
1346// Deprecated: deprecated
1347type ChatCompletionMessageFunctionCall struct {
1348	// The arguments to call the function with, as generated by the model in JSON
1349	// format. Note that the model does not always generate valid JSON, and may
1350	// hallucinate parameters not defined by your function schema. Validate the
1351	// arguments in your code before calling your function.
1352	Arguments string `json:"arguments,required"`
1353	// The name of the function to call.
1354	Name string `json:"name,required"`
1355	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1356	JSON struct {
1357		Arguments   respjson.Field
1358		Name        respjson.Field
1359		ExtraFields map[string]respjson.Field
1360		raw         string
1361	} `json:"-"`
1362}
1363
1364// Returns the unmodified JSON received from the API
1365func (r ChatCompletionMessageFunctionCall) RawJSON() string { return r.JSON.raw }
1366func (r *ChatCompletionMessageFunctionCall) UnmarshalJSON(data []byte) error {
1367	return apijson.UnmarshalRoot(data, r)
1368}
1369
1370func AssistantMessage[T string | []ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion](content T) ChatCompletionMessageParamUnion {
1371	var assistant ChatCompletionAssistantMessageParam
1372	switch v := any(content).(type) {
1373	case string:
1374		assistant.Content.OfString = param.NewOpt(v)
1375	case []ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion:
1376		assistant.Content.OfArrayOfContentParts = v
1377	}
1378	return ChatCompletionMessageParamUnion{OfAssistant: &assistant}
1379}
1380
1381func DeveloperMessage[T string | []ChatCompletionContentPartTextParam](content T) ChatCompletionMessageParamUnion {
1382	var developer ChatCompletionDeveloperMessageParam
1383	switch v := any(content).(type) {
1384	case string:
1385		developer.Content.OfString = param.NewOpt(v)
1386	case []ChatCompletionContentPartTextParam:
1387		developer.Content.OfArrayOfContentParts = v
1388	}
1389	return ChatCompletionMessageParamUnion{OfDeveloper: &developer}
1390}
1391
1392func SystemMessage[T string | []ChatCompletionContentPartTextParam](content T) ChatCompletionMessageParamUnion {
1393	var system ChatCompletionSystemMessageParam
1394	switch v := any(content).(type) {
1395	case string:
1396		system.Content.OfString = param.NewOpt(v)
1397	case []ChatCompletionContentPartTextParam:
1398		system.Content.OfArrayOfContentParts = v
1399	}
1400	return ChatCompletionMessageParamUnion{OfSystem: &system}
1401}
1402
1403func UserMessage[T string | []ChatCompletionContentPartUnionParam](content T) ChatCompletionMessageParamUnion {
1404	var user ChatCompletionUserMessageParam
1405	switch v := any(content).(type) {
1406	case string:
1407		user.Content.OfString = param.NewOpt(v)
1408	case []ChatCompletionContentPartUnionParam:
1409		user.Content.OfArrayOfContentParts = v
1410	}
1411	return ChatCompletionMessageParamUnion{OfUser: &user}
1412}
1413
1414func ToolMessage[T string | []ChatCompletionContentPartTextParam](content T, toolCallID string) ChatCompletionMessageParamUnion {
1415	var tool ChatCompletionToolMessageParam
1416	switch v := any(content).(type) {
1417	case string:
1418		tool.Content.OfString = param.NewOpt(v)
1419	case []ChatCompletionContentPartTextParam:
1420		tool.Content.OfArrayOfContentParts = v
1421	}
1422	tool.ToolCallID = toolCallID
1423	return ChatCompletionMessageParamUnion{OfTool: &tool}
1424}
1425
1426func ChatCompletionMessageParamOfFunction(content string, name string) ChatCompletionMessageParamUnion {
1427	var function ChatCompletionFunctionMessageParam
1428	function.Content = param.NewOpt(content)
1429	function.Name = name
1430	return ChatCompletionMessageParamUnion{OfFunction: &function}
1431}
1432
1433// Only one field can be non-zero.
1434//
1435// Use [param.IsOmitted] to confirm if a field is set.
1436type ChatCompletionMessageParamUnion struct {
1437	OfDeveloper *ChatCompletionDeveloperMessageParam `json:",omitzero,inline"`
1438	OfSystem    *ChatCompletionSystemMessageParam    `json:",omitzero,inline"`
1439	OfUser      *ChatCompletionUserMessageParam      `json:",omitzero,inline"`
1440	OfAssistant *ChatCompletionAssistantMessageParam `json:",omitzero,inline"`
1441	OfTool      *ChatCompletionToolMessageParam      `json:",omitzero,inline"`
1442	OfFunction  *ChatCompletionFunctionMessageParam  `json:",omitzero,inline"`
1443	paramUnion
1444}
1445
1446func (u ChatCompletionMessageParamUnion) MarshalJSON() ([]byte, error) {
1447	return param.MarshalUnion(u, u.OfDeveloper,
1448		u.OfSystem,
1449		u.OfUser,
1450		u.OfAssistant,
1451		u.OfTool,
1452		u.OfFunction)
1453}
1454func (u *ChatCompletionMessageParamUnion) UnmarshalJSON(data []byte) error {
1455	return apijson.UnmarshalRoot(data, u)
1456}
1457
1458func (u *ChatCompletionMessageParamUnion) asAny() any {
1459	if !param.IsOmitted(u.OfDeveloper) {
1460		return u.OfDeveloper
1461	} else if !param.IsOmitted(u.OfSystem) {
1462		return u.OfSystem
1463	} else if !param.IsOmitted(u.OfUser) {
1464		return u.OfUser
1465	} else if !param.IsOmitted(u.OfAssistant) {
1466		return u.OfAssistant
1467	} else if !param.IsOmitted(u.OfTool) {
1468		return u.OfTool
1469	} else if !param.IsOmitted(u.OfFunction) {
1470		return u.OfFunction
1471	}
1472	return nil
1473}
1474
1475// Returns a pointer to the underlying variant's property, if present.
1476func (u ChatCompletionMessageParamUnion) GetAudio() *ChatCompletionAssistantMessageParamAudio {
1477	if vt := u.OfAssistant; vt != nil {
1478		return &vt.Audio
1479	}
1480	return nil
1481}
1482
1483// Returns a pointer to the underlying variant's property, if present.
1484func (u ChatCompletionMessageParamUnion) GetFunctionCall() *ChatCompletionAssistantMessageParamFunctionCall {
1485	if vt := u.OfAssistant; vt != nil {
1486		return &vt.FunctionCall
1487	}
1488	return nil
1489}
1490
1491// Returns a pointer to the underlying variant's property, if present.
1492func (u ChatCompletionMessageParamUnion) GetRefusal() *string {
1493	if vt := u.OfAssistant; vt != nil && vt.Refusal.Valid() {
1494		return &vt.Refusal.Value
1495	}
1496	return nil
1497}
1498
1499// Returns a pointer to the underlying variant's property, if present.
1500func (u ChatCompletionMessageParamUnion) GetToolCalls() []ChatCompletionMessageToolCallParam {
1501	if vt := u.OfAssistant; vt != nil {
1502		return vt.ToolCalls
1503	}
1504	return nil
1505}
1506
1507// Returns a pointer to the underlying variant's property, if present.
1508func (u ChatCompletionMessageParamUnion) GetToolCallID() *string {
1509	if vt := u.OfTool; vt != nil {
1510		return &vt.ToolCallID
1511	}
1512	return nil
1513}
1514
1515// Returns a pointer to the underlying variant's property, if present.
1516func (u ChatCompletionMessageParamUnion) GetRole() *string {
1517	if vt := u.OfDeveloper; vt != nil {
1518		return (*string)(&vt.Role)
1519	} else if vt := u.OfSystem; vt != nil {
1520		return (*string)(&vt.Role)
1521	} else if vt := u.OfUser; vt != nil {
1522		return (*string)(&vt.Role)
1523	} else if vt := u.OfAssistant; vt != nil {
1524		return (*string)(&vt.Role)
1525	} else if vt := u.OfTool; vt != nil {
1526		return (*string)(&vt.Role)
1527	} else if vt := u.OfFunction; vt != nil {
1528		return (*string)(&vt.Role)
1529	}
1530	return nil
1531}
1532
1533// Returns a pointer to the underlying variant's property, if present.
1534func (u ChatCompletionMessageParamUnion) GetName() *string {
1535	if vt := u.OfDeveloper; vt != nil && vt.Name.Valid() {
1536		return &vt.Name.Value
1537	} else if vt := u.OfSystem; vt != nil && vt.Name.Valid() {
1538		return &vt.Name.Value
1539	} else if vt := u.OfUser; vt != nil && vt.Name.Valid() {
1540		return &vt.Name.Value
1541	} else if vt := u.OfAssistant; vt != nil && vt.Name.Valid() {
1542		return &vt.Name.Value
1543	} else if vt := u.OfFunction; vt != nil {
1544		return (*string)(&vt.Name)
1545	}
1546	return nil
1547}
1548
1549// Returns a subunion which exports methods to access subproperties
1550//
1551// Or use AsAny() to get the underlying value
1552func (u ChatCompletionMessageParamUnion) GetContent() (res chatCompletionMessageParamUnionContent) {
1553	if vt := u.OfDeveloper; vt != nil {
1554		res.any = vt.Content.asAny()
1555	} else if vt := u.OfSystem; vt != nil {
1556		res.any = vt.Content.asAny()
1557	} else if vt := u.OfUser; vt != nil {
1558		res.any = vt.Content.asAny()
1559	} else if vt := u.OfAssistant; vt != nil {
1560		res.any = vt.Content.asAny()
1561	} else if vt := u.OfTool; vt != nil {
1562		res.any = vt.Content.asAny()
1563	} else if vt := u.OfFunction; vt != nil && vt.Content.Valid() {
1564		res.any = &vt.Content.Value
1565	}
1566	return
1567}
1568
1569// Can have the runtime types [*string], [_[]ChatCompletionContentPartTextParam],
1570// [_[]ChatCompletionContentPartUnionParam],
1571// [\*[]ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion]
1572type chatCompletionMessageParamUnionContent struct{ any }
1573
1574// Use the following switch statement to get the type of the union:
1575//
1576//	switch u.AsAny().(type) {
1577//	case *string:
1578//	case *[]openai.ChatCompletionContentPartTextParam:
1579//	case *[]openai.ChatCompletionContentPartUnionParam:
1580//	case *[]openai.ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion:
1581//	default:
1582//	    fmt.Errorf("not present")
1583//	}
1584func (u chatCompletionMessageParamUnionContent) AsAny() any { return u.any }
1585
1586func init() {
1587	apijson.RegisterUnion[ChatCompletionMessageParamUnion](
1588		"role",
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"),
1595	)
1596}
1597
1598type ChatCompletionMessageToolCall struct {
1599	// The ID of the tool call.
1600	ID string `json:"id,required"`
1601	// The function that the model called.
1602	Function ChatCompletionMessageToolCallFunction `json:"function,required"`
1603	// The type of the tool. Currently, only `function` is supported.
1604	Type constant.Function `json:"type,required"`
1605	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1606	JSON struct {
1607		ID          respjson.Field
1608		Function    respjson.Field
1609		Type        respjson.Field
1610		ExtraFields map[string]respjson.Field
1611		raw         string
1612	} `json:"-"`
1613}
1614
1615// Returns the unmodified JSON received from the API
1616func (r ChatCompletionMessageToolCall) RawJSON() string { return r.JSON.raw }
1617func (r *ChatCompletionMessageToolCall) UnmarshalJSON(data []byte) error {
1618	return apijson.UnmarshalRoot(data, r)
1619}
1620
1621// ToParam converts this ChatCompletionMessageToolCall to a
1622// ChatCompletionMessageToolCallParam.
1623//
1624// Warning: the fields of the param type will not be present. ToParam should only
1625// be used at the last possible moment before sending a request. Test for this with
1626// ChatCompletionMessageToolCallParam.Overrides()
1627func (r ChatCompletionMessageToolCall) ToParam() ChatCompletionMessageToolCallParam {
1628	return param.Override[ChatCompletionMessageToolCallParam](json.RawMessage(r.RawJSON()))
1629}
1630
1631// The function that the model called.
1632type ChatCompletionMessageToolCallFunction struct {
1633	// The arguments to call the function with, as generated by the model in JSON
1634	// format. Note that the model does not always generate valid JSON, and may
1635	// hallucinate parameters not defined by your function schema. Validate the
1636	// arguments in your code before calling your function.
1637	Arguments string `json:"arguments,required"`
1638	// The name of the function to call.
1639	Name string `json:"name,required"`
1640	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1641	JSON struct {
1642		Arguments   respjson.Field
1643		Name        respjson.Field
1644		ExtraFields map[string]respjson.Field
1645		raw         string
1646	} `json:"-"`
1647}
1648
1649// Returns the unmodified JSON received from the API
1650func (r ChatCompletionMessageToolCallFunction) RawJSON() string { return r.JSON.raw }
1651func (r *ChatCompletionMessageToolCallFunction) UnmarshalJSON(data []byte) error {
1652	return apijson.UnmarshalRoot(data, r)
1653}
1654
1655// The properties ID, Function, Type are required.
1656type ChatCompletionMessageToolCallParam struct {
1657	// The ID of the tool call.
1658	ID string `json:"id,required"`
1659	// The function that the model called.
1660	Function ChatCompletionMessageToolCallFunctionParam `json:"function,omitzero,required"`
1661	// The type of the tool. Currently, only `function` is supported.
1662	//
1663	// This field can be elided, and will marshal its zero value as "function".
1664	Type constant.Function `json:"type,required"`
1665	paramObj
1666}
1667
1668func (r ChatCompletionMessageToolCallParam) MarshalJSON() (data []byte, err error) {
1669	type shadow ChatCompletionMessageToolCallParam
1670	return param.MarshalObject(r, (*shadow)(&r))
1671}
1672func (r *ChatCompletionMessageToolCallParam) UnmarshalJSON(data []byte) error {
1673	return apijson.UnmarshalRoot(data, r)
1674}
1675
1676// The function that the model called.
1677//
1678// The properties Arguments, Name are required.
1679type ChatCompletionMessageToolCallFunctionParam struct {
1680	// The arguments to call the function with, as generated by the model in JSON
1681	// format. Note that the model does not always generate valid JSON, and may
1682	// hallucinate parameters not defined by your function schema. Validate the
1683	// arguments in your code before calling your function.
1684	Arguments string `json:"arguments,required"`
1685	// The name of the function to call.
1686	Name string `json:"name,required"`
1687	paramObj
1688}
1689
1690func (r ChatCompletionMessageToolCallFunctionParam) MarshalJSON() (data []byte, err error) {
1691	type shadow ChatCompletionMessageToolCallFunctionParam
1692	return param.MarshalObject(r, (*shadow)(&r))
1693}
1694func (r *ChatCompletionMessageToolCallFunctionParam) UnmarshalJSON(data []byte) error {
1695	return apijson.UnmarshalRoot(data, r)
1696}
1697
1698// Specifies a tool the model should use. Use to force the model to call a specific
1699// function.
1700//
1701// The properties Function, Type are required.
1702type ChatCompletionNamedToolChoiceParam struct {
1703	Function ChatCompletionNamedToolChoiceFunctionParam `json:"function,omitzero,required"`
1704	// The type of the tool. Currently, only `function` is supported.
1705	//
1706	// This field can be elided, and will marshal its zero value as "function".
1707	Type constant.Function `json:"type,required"`
1708	paramObj
1709}
1710
1711func (r ChatCompletionNamedToolChoiceParam) MarshalJSON() (data []byte, err error) {
1712	type shadow ChatCompletionNamedToolChoiceParam
1713	return param.MarshalObject(r, (*shadow)(&r))
1714}
1715func (r *ChatCompletionNamedToolChoiceParam) UnmarshalJSON(data []byte) error {
1716	return apijson.UnmarshalRoot(data, r)
1717}
1718
1719// The property Name is required.
1720type ChatCompletionNamedToolChoiceFunctionParam struct {
1721	// The name of the function to call.
1722	Name string `json:"name,required"`
1723	paramObj
1724}
1725
1726func (r ChatCompletionNamedToolChoiceFunctionParam) MarshalJSON() (data []byte, err error) {
1727	type shadow ChatCompletionNamedToolChoiceFunctionParam
1728	return param.MarshalObject(r, (*shadow)(&r))
1729}
1730func (r *ChatCompletionNamedToolChoiceFunctionParam) UnmarshalJSON(data []byte) error {
1731	return apijson.UnmarshalRoot(data, r)
1732}
1733
1734// Static predicted output content, such as the content of a text file that is
1735// being regenerated.
1736//
1737// The properties Content, Type are required.
1738type ChatCompletionPredictionContentParam struct {
1739	// The content that should be matched when generating a model response. If
1740	// generated tokens would match this content, the entire model response can be
1741	// returned much more quickly.
1742	Content ChatCompletionPredictionContentContentUnionParam `json:"content,omitzero,required"`
1743	// The type of the predicted content you want to provide. This type is currently
1744	// always `content`.
1745	//
1746	// This field can be elided, and will marshal its zero value as "content".
1747	Type constant.Content `json:"type,required"`
1748	paramObj
1749}
1750
1751func (r ChatCompletionPredictionContentParam) MarshalJSON() (data []byte, err error) {
1752	type shadow ChatCompletionPredictionContentParam
1753	return param.MarshalObject(r, (*shadow)(&r))
1754}
1755func (r *ChatCompletionPredictionContentParam) UnmarshalJSON(data []byte) error {
1756	return apijson.UnmarshalRoot(data, r)
1757}
1758
1759// Only one field can be non-zero.
1760//
1761// Use [param.IsOmitted] to confirm if a field is set.
1762type ChatCompletionPredictionContentContentUnionParam struct {
1763	OfString              param.Opt[string]                    `json:",omitzero,inline"`
1764	OfArrayOfContentParts []ChatCompletionContentPartTextParam `json:",omitzero,inline"`
1765	paramUnion
1766}
1767
1768func (u ChatCompletionPredictionContentContentUnionParam) MarshalJSON() ([]byte, error) {
1769	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
1770}
1771func (u *ChatCompletionPredictionContentContentUnionParam) UnmarshalJSON(data []byte) error {
1772	return apijson.UnmarshalRoot(data, u)
1773}
1774
1775func (u *ChatCompletionPredictionContentContentUnionParam) asAny() any {
1776	if !param.IsOmitted(u.OfString) {
1777		return &u.OfString.Value
1778	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
1779		return &u.OfArrayOfContentParts
1780	}
1781	return nil
1782}
1783
1784// A chat completion message generated by the model.
1785type ChatCompletionStoreMessage struct {
1786	// The identifier of the chat message.
1787	ID string `json:"id,required"`
1788	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1789	JSON struct {
1790		ID          respjson.Field
1791		ExtraFields map[string]respjson.Field
1792		raw         string
1793	} `json:"-"`
1794	ChatCompletionMessage
1795}
1796
1797// Returns the unmodified JSON received from the API
1798func (r ChatCompletionStoreMessage) RawJSON() string { return r.JSON.raw }
1799func (r *ChatCompletionStoreMessage) UnmarshalJSON(data []byte) error {
1800	return apijson.UnmarshalRoot(data, r)
1801}
1802
1803// Options for streaming response. Only set this when you set `stream: true`.
1804type ChatCompletionStreamOptionsParam struct {
1805	// If set, an additional chunk will be streamed before the `data: [DONE]` message.
1806	// The `usage` field on this chunk shows the token usage statistics for the entire
1807	// request, and the `choices` field will always be an empty array.
1808	//
1809	// All other chunks will also include a `usage` field, but with a null value.
1810	// **NOTE:** If the stream is interrupted, you may not receive the final usage
1811	// chunk which contains the total token usage for the request.
1812	IncludeUsage param.Opt[bool] `json:"include_usage,omitzero"`
1813	paramObj
1814}
1815
1816func (r ChatCompletionStreamOptionsParam) MarshalJSON() (data []byte, err error) {
1817	type shadow ChatCompletionStreamOptionsParam
1818	return param.MarshalObject(r, (*shadow)(&r))
1819}
1820func (r *ChatCompletionStreamOptionsParam) UnmarshalJSON(data []byte) error {
1821	return apijson.UnmarshalRoot(data, r)
1822}
1823
1824// Developer-provided instructions that the model should follow, regardless of
1825// messages sent by the user. With o1 models and newer, use `developer` messages
1826// for this purpose instead.
1827//
1828// The properties Content, Role are required.
1829type ChatCompletionSystemMessageParam struct {
1830	// The contents of the system message.
1831	Content ChatCompletionSystemMessageParamContentUnion `json:"content,omitzero,required"`
1832	// An optional name for the participant. Provides the model information to
1833	// differentiate between participants of the same role.
1834	Name param.Opt[string] `json:"name,omitzero"`
1835	// The role of the messages author, in this case `system`.
1836	//
1837	// This field can be elided, and will marshal its zero value as "system".
1838	Role constant.System `json:"role,required"`
1839	paramObj
1840}
1841
1842func (r ChatCompletionSystemMessageParam) MarshalJSON() (data []byte, err error) {
1843	type shadow ChatCompletionSystemMessageParam
1844	return param.MarshalObject(r, (*shadow)(&r))
1845}
1846func (r *ChatCompletionSystemMessageParam) UnmarshalJSON(data []byte) error {
1847	return apijson.UnmarshalRoot(data, r)
1848}
1849
1850// Only one field can be non-zero.
1851//
1852// Use [param.IsOmitted] to confirm if a field is set.
1853type ChatCompletionSystemMessageParamContentUnion struct {
1854	OfString              param.Opt[string]                    `json:",omitzero,inline"`
1855	OfArrayOfContentParts []ChatCompletionContentPartTextParam `json:",omitzero,inline"`
1856	paramUnion
1857}
1858
1859func (u ChatCompletionSystemMessageParamContentUnion) MarshalJSON() ([]byte, error) {
1860	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
1861}
1862func (u *ChatCompletionSystemMessageParamContentUnion) UnmarshalJSON(data []byte) error {
1863	return apijson.UnmarshalRoot(data, u)
1864}
1865
1866func (u *ChatCompletionSystemMessageParamContentUnion) asAny() any {
1867	if !param.IsOmitted(u.OfString) {
1868		return &u.OfString.Value
1869	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
1870		return &u.OfArrayOfContentParts
1871	}
1872	return nil
1873}
1874
1875type ChatCompletionTokenLogprob struct {
1876	// The token.
1877	Token string `json:"token,required"`
1878	// A list of integers representing the UTF-8 bytes representation of the token.
1879	// Useful in instances where characters are represented by multiple tokens and
1880	// their byte representations must be combined to generate the correct text
1881	// representation. Can be `null` if there is no bytes representation for the token.
1882	Bytes []int64 `json:"bytes,required"`
1883	// The log probability of this token, if it is within the top 20 most likely
1884	// tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
1885	// unlikely.
1886	Logprob float64 `json:"logprob,required"`
1887	// List of the most likely tokens and their log probability, at this token
1888	// position. In rare cases, there may be fewer than the number of requested
1889	// `top_logprobs` returned.
1890	TopLogprobs []ChatCompletionTokenLogprobTopLogprob `json:"top_logprobs,required"`
1891	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1892	JSON struct {
1893		Token       respjson.Field
1894		Bytes       respjson.Field
1895		Logprob     respjson.Field
1896		TopLogprobs respjson.Field
1897		ExtraFields map[string]respjson.Field
1898		raw         string
1899	} `json:"-"`
1900}
1901
1902// Returns the unmodified JSON received from the API
1903func (r ChatCompletionTokenLogprob) RawJSON() string { return r.JSON.raw }
1904func (r *ChatCompletionTokenLogprob) UnmarshalJSON(data []byte) error {
1905	return apijson.UnmarshalRoot(data, r)
1906}
1907
1908type ChatCompletionTokenLogprobTopLogprob struct {
1909	// The token.
1910	Token string `json:"token,required"`
1911	// A list of integers representing the UTF-8 bytes representation of the token.
1912	// Useful in instances where characters are represented by multiple tokens and
1913	// their byte representations must be combined to generate the correct text
1914	// representation. Can be `null` if there is no bytes representation for the token.
1915	Bytes []int64 `json:"bytes,required"`
1916	// The log probability of this token, if it is within the top 20 most likely
1917	// tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
1918	// unlikely.
1919	Logprob float64 `json:"logprob,required"`
1920	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1921	JSON struct {
1922		Token       respjson.Field
1923		Bytes       respjson.Field
1924		Logprob     respjson.Field
1925		ExtraFields map[string]respjson.Field
1926		raw         string
1927	} `json:"-"`
1928}
1929
1930// Returns the unmodified JSON received from the API
1931func (r ChatCompletionTokenLogprobTopLogprob) RawJSON() string { return r.JSON.raw }
1932func (r *ChatCompletionTokenLogprobTopLogprob) UnmarshalJSON(data []byte) error {
1933	return apijson.UnmarshalRoot(data, r)
1934}
1935
1936// The properties Function, Type are required.
1937type ChatCompletionToolParam struct {
1938	Function shared.FunctionDefinitionParam `json:"function,omitzero,required"`
1939	// The type of the tool. Currently, only `function` is supported.
1940	//
1941	// This field can be elided, and will marshal its zero value as "function".
1942	Type constant.Function `json:"type,required"`
1943	paramObj
1944}
1945
1946func (r ChatCompletionToolParam) MarshalJSON() (data []byte, err error) {
1947	type shadow ChatCompletionToolParam
1948	return param.MarshalObject(r, (*shadow)(&r))
1949}
1950func (r *ChatCompletionToolParam) UnmarshalJSON(data []byte) error {
1951	return apijson.UnmarshalRoot(data, r)
1952}
1953
1954func ChatCompletionToolChoiceOptionParamOfChatCompletionNamedToolChoice(function ChatCompletionNamedToolChoiceFunctionParam) ChatCompletionToolChoiceOptionUnionParam {
1955	var variant ChatCompletionNamedToolChoiceParam
1956	variant.Function = function
1957	return ChatCompletionToolChoiceOptionUnionParam{OfChatCompletionNamedToolChoice: &variant}
1958}
1959
1960// Only one field can be non-zero.
1961//
1962// Use [param.IsOmitted] to confirm if a field is set.
1963type ChatCompletionToolChoiceOptionUnionParam struct {
1964	// Check if union is this variant with !param.IsOmitted(union.OfAuto)
1965	OfAuto                          param.Opt[string]                   `json:",omitzero,inline"`
1966	OfChatCompletionNamedToolChoice *ChatCompletionNamedToolChoiceParam `json:",omitzero,inline"`
1967	paramUnion
1968}
1969
1970func (u ChatCompletionToolChoiceOptionUnionParam) MarshalJSON() ([]byte, error) {
1971	return param.MarshalUnion(u, u.OfAuto, u.OfChatCompletionNamedToolChoice)
1972}
1973func (u *ChatCompletionToolChoiceOptionUnionParam) UnmarshalJSON(data []byte) error {
1974	return apijson.UnmarshalRoot(data, u)
1975}
1976
1977func (u *ChatCompletionToolChoiceOptionUnionParam) asAny() any {
1978	if !param.IsOmitted(u.OfAuto) {
1979		return &u.OfAuto
1980	} else if !param.IsOmitted(u.OfChatCompletionNamedToolChoice) {
1981		return u.OfChatCompletionNamedToolChoice
1982	}
1983	return nil
1984}
1985
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.
1989type ChatCompletionToolChoiceOptionAuto string
1990
1991const (
1992	ChatCompletionToolChoiceOptionAutoNone     ChatCompletionToolChoiceOptionAuto = "none"
1993	ChatCompletionToolChoiceOptionAutoAuto     ChatCompletionToolChoiceOptionAuto = "auto"
1994	ChatCompletionToolChoiceOptionAutoRequired ChatCompletionToolChoiceOptionAuto = "required"
1995)
1996
1997// The properties Content, Role, ToolCallID are required.
1998type ChatCompletionToolMessageParam struct {
1999	// The contents of the tool message.
2000	Content ChatCompletionToolMessageParamContentUnion `json:"content,omitzero,required"`
2001	// Tool call that this message is responding to.
2002	ToolCallID string `json:"tool_call_id,required"`
2003	// The role of the messages author, in this case `tool`.
2004	//
2005	// This field can be elided, and will marshal its zero value as "tool".
2006	Role constant.Tool `json:"role,required"`
2007	paramObj
2008}
2009
2010func (r ChatCompletionToolMessageParam) MarshalJSON() (data []byte, err error) {
2011	type shadow ChatCompletionToolMessageParam
2012	return param.MarshalObject(r, (*shadow)(&r))
2013}
2014func (r *ChatCompletionToolMessageParam) UnmarshalJSON(data []byte) error {
2015	return apijson.UnmarshalRoot(data, r)
2016}
2017
2018// Only one field can be non-zero.
2019//
2020// Use [param.IsOmitted] to confirm if a field is set.
2021type ChatCompletionToolMessageParamContentUnion struct {
2022	OfString              param.Opt[string]                    `json:",omitzero,inline"`
2023	OfArrayOfContentParts []ChatCompletionContentPartTextParam `json:",omitzero,inline"`
2024	paramUnion
2025}
2026
2027func (u ChatCompletionToolMessageParamContentUnion) MarshalJSON() ([]byte, error) {
2028	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
2029}
2030func (u *ChatCompletionToolMessageParamContentUnion) UnmarshalJSON(data []byte) error {
2031	return apijson.UnmarshalRoot(data, u)
2032}
2033
2034func (u *ChatCompletionToolMessageParamContentUnion) asAny() any {
2035	if !param.IsOmitted(u.OfString) {
2036		return &u.OfString.Value
2037	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
2038		return &u.OfArrayOfContentParts
2039	}
2040	return nil
2041}
2042
2043// Messages sent by an end user, containing prompts or additional context
2044// information.
2045//
2046// The properties Content, Role are required.
2047type ChatCompletionUserMessageParam struct {
2048	// The contents of the user message.
2049	Content ChatCompletionUserMessageParamContentUnion `json:"content,omitzero,required"`
2050	// An optional name for the participant. Provides the model information to
2051	// differentiate between participants of the same role.
2052	Name param.Opt[string] `json:"name,omitzero"`
2053	// The role of the messages author, in this case `user`.
2054	//
2055	// This field can be elided, and will marshal its zero value as "user".
2056	Role constant.User `json:"role,required"`
2057	paramObj
2058}
2059
2060func (r ChatCompletionUserMessageParam) MarshalJSON() (data []byte, err error) {
2061	type shadow ChatCompletionUserMessageParam
2062	return param.MarshalObject(r, (*shadow)(&r))
2063}
2064func (r *ChatCompletionUserMessageParam) UnmarshalJSON(data []byte) error {
2065	return apijson.UnmarshalRoot(data, r)
2066}
2067
2068// Only one field can be non-zero.
2069//
2070// Use [param.IsOmitted] to confirm if a field is set.
2071type ChatCompletionUserMessageParamContentUnion struct {
2072	OfString              param.Opt[string]                     `json:",omitzero,inline"`
2073	OfArrayOfContentParts []ChatCompletionContentPartUnionParam `json:",omitzero,inline"`
2074	paramUnion
2075}
2076
2077func (u ChatCompletionUserMessageParamContentUnion) MarshalJSON() ([]byte, error) {
2078	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
2079}
2080func (u *ChatCompletionUserMessageParamContentUnion) UnmarshalJSON(data []byte) error {
2081	return apijson.UnmarshalRoot(data, u)
2082}
2083
2084func (u *ChatCompletionUserMessageParamContentUnion) asAny() any {
2085	if !param.IsOmitted(u.OfString) {
2086		return &u.OfString.Value
2087	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
2088		return &u.OfArrayOfContentParts
2089	}
2090	return nil
2091}
2092
2093type ChatCompletionNewParams struct {
2094	// A list of messages comprising the conversation so far. Depending on the
2095	// [model](https://platform.openai.com/docs/models) you use, different message
2096	// types (modalities) are supported, like
2097	// [text](https://platform.openai.com/docs/guides/text-generation),
2098	// [images](https://platform.openai.com/docs/guides/vision), and
2099	// [audio](https://platform.openai.com/docs/guides/audio).
2100	Messages []ChatCompletionMessageParamUnion `json:"messages,omitzero,required"`
2101	// Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a
2102	// wide range of models with different capabilities, performance characteristics,
2103	// and price points. Refer to the
2104	// [model guide](https://platform.openai.com/docs/models) to browse and compare
2105	// available models.
2106	Model shared.ChatModel `json:"model,omitzero,required"`
2107	// Number between -2.0 and 2.0. Positive values penalize new tokens based on their
2108	// existing frequency in the text so far, decreasing the model's likelihood to
2109	// repeat the same line verbatim.
2110	FrequencyPenalty param.Opt[float64] `json:"frequency_penalty,omitzero"`
2111	// Whether to return log probabilities of the output tokens or not. If true,
2112	// returns the log probabilities of each output token returned in the `content` of
2113	// `message`.
2114	Logprobs param.Opt[bool] `json:"logprobs,omitzero"`
2115	// An upper bound for the number of tokens that can be generated for a completion,
2116	// including visible output tokens and
2117	// [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
2118	MaxCompletionTokens param.Opt[int64] `json:"max_completion_tokens,omitzero"`
2119	// The maximum number of [tokens](/tokenizer) that can be generated in the chat
2120	// completion. This value can be used to control
2121	// [costs](https://openai.com/api/pricing/) for text generated via API.
2122	//
2123	// This value is now deprecated in favor of `max_completion_tokens`, and is not
2124	// compatible with
2125	// [o-series models](https://platform.openai.com/docs/guides/reasoning).
2126	MaxTokens param.Opt[int64] `json:"max_tokens,omitzero"`
2127	// How many chat completion choices to generate for each input message. Note that
2128	// you will be charged based on the number of generated tokens across all of the
2129	// choices. Keep `n` as `1` to minimize costs.
2130	N param.Opt[int64] `json:"n,omitzero"`
2131	// Number between -2.0 and 2.0. Positive values penalize new tokens based on
2132	// whether they appear in the text so far, increasing the model's likelihood to
2133	// talk about new topics.
2134	PresencePenalty param.Opt[float64] `json:"presence_penalty,omitzero"`
2135	// This feature is in Beta. If specified, our system will make a best effort to
2136	// sample deterministically, such that repeated requests with the same `seed` and
2137	// parameters should return the same result. Determinism is not guaranteed, and you
2138	// should refer to the `system_fingerprint` response parameter to monitor changes
2139	// in the backend.
2140	Seed param.Opt[int64] `json:"seed,omitzero"`
2141	// Whether or not to store the output of this chat completion request for use in
2142	// our [model distillation](https://platform.openai.com/docs/guides/distillation)
2143	// 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.
2146	Store param.Opt[bool] `json:"store,omitzero"`
2147	// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
2148	// make the output more random, while lower values like 0.2 will make it more
2149	// focused and deterministic. We generally recommend altering this or `top_p` but
2150	// not both.
2151	Temperature param.Opt[float64] `json:"temperature,omitzero"`
2152	// An integer between 0 and 20 specifying the number of most likely tokens to
2153	// return at each token position, each with an associated log probability.
2154	// `logprobs` must be set to `true` if this parameter is used.
2155	TopLogprobs param.Opt[int64] `json:"top_logprobs,omitzero"`
2156	// An alternative to sampling with temperature, called nucleus sampling, where the
2157	// model considers the results of the tokens with top_p probability mass. So 0.1
2158	// means only the tokens comprising the top 10% probability mass are considered.
2159	//
2160	// We generally recommend altering this or `temperature` but not both.
2161	TopP param.Opt[float64] `json:"top_p,omitzero"`
2162	// Whether to enable
2163	// [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
2164	// during tool use.
2165	ParallelToolCalls param.Opt[bool] `json:"parallel_tool_calls,omitzero"`
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.
2168	// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
2169	User param.Opt[string] `json:"user,omitzero"`
2170	// Parameters for audio output. Required when audio output is requested with
2171	// `modalities: ["audio"]`.
2172	// [Learn more](https://platform.openai.com/docs/guides/audio).
2173	Audio ChatCompletionAudioParam `json:"audio,omitzero"`
2174	// Modify the likelihood of specified tokens appearing in the completion.
2175	//
2176	// Accepts a JSON object that maps tokens (specified by their token ID in the
2177	// tokenizer) to an associated bias value from -100 to 100. Mathematically, the
2178	// bias is added to the logits generated by the model prior to sampling. The exact
2179	// effect will vary per model, but values between -1 and 1 should decrease or
2180	// increase likelihood of selection; values like -100 or 100 should result in a ban
2181	// or exclusive selection of the relevant token.
2182	LogitBias map[string]int64 `json:"logit_bias,omitzero"`
2183	// Set of 16 key-value pairs that can be attached to an object. This can be useful
2184	// for storing additional information about the object in a structured format, and
2185	// querying for objects via API or the dashboard.
2186	//
2187	// Keys are strings with a maximum length of 64 characters. Values are strings with
2188	// a maximum length of 512 characters.
2189	Metadata shared.Metadata `json:"metadata,omitzero"`
2190	// Output types that you would like the model to generate. Most models are capable
2191	// of generating text, which is the default:
2192	//
2193	// `["text"]`
2194	//
2195	// The `gpt-4o-audio-preview` model can also be used to
2196	// [generate audio](https://platform.openai.com/docs/guides/audio). To request that
2197	// this model generate both text and audio responses, you can use:
2198	//
2199	// `["text", "audio"]`
2200	//
2201	// Any of "text", "audio".
2202	Modalities []string `json:"modalities,omitzero"`
2203	// **o-series models only**
2204	//
2205	// Constrains effort on reasoning for
2206	// [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
2207	// supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
2208	// result in faster responses and fewer tokens used on reasoning in a response.
2209	//
2210	// Any of "low", "medium", "high".
2211	ReasoningEffort shared.ReasoningEffort `json:"reasoning_effort,omitzero"`
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.
2223	//   - When not set, the default behavior is 'auto'.
2224	//
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.
2229	//
2230	// Any of "auto", "default", "flex", "scale", "priority".
2231	ServiceTier ChatCompletionNewParamsServiceTier `json:"service_tier,omitzero"`
2232	// Not supported with latest reasoning models `o3` and `o4-mini`.
2233	//
2234	// Up to 4 sequences where the API will stop generating further tokens. The
2235	// returned text will not contain the stop sequence.
2236	Stop ChatCompletionNewParamsStopUnion `json:"stop,omitzero"`
2237	// Options for streaming response. Only set this when you set `stream: true`.
2238	StreamOptions ChatCompletionStreamOptionsParam `json:"stream_options,omitzero"`
2239	// Deprecated in favor of `tool_choice`.
2240	//
2241	// Controls which (if any) function is called by the model.
2242	//
2243	// `none` means the model will not call a function and instead generates a message.
2244	//
2245	// `auto` means the model can pick between generating a message or calling a
2246	// function.
2247	//
2248	// Specifying a particular function via `{"name": "my_function"}` forces the model
2249	// to call that function.
2250	//
2251	// `none` is the default when no functions are present. `auto` is the default if
2252	// functions are present.
2253	FunctionCall ChatCompletionNewParamsFunctionCallUnion `json:"function_call,omitzero"`
2254	// Deprecated in favor of `tools`.
2255	//
2256	// A list of functions the model may generate JSON inputs for.
2257	Functions []ChatCompletionNewParamsFunction `json:"functions,omitzero"`
2258	// Static predicted output content, such as the content of a text file that is
2259	// being regenerated.
2260	Prediction ChatCompletionPredictionContentParam `json:"prediction,omitzero"`
2261	// An object specifying the format that the model must output.
2262	//
2263	// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
2264	// Outputs which ensures the model will match your supplied JSON schema. Learn more
2265	// in the
2266	// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
2267	//
2268	// Setting to `{ "type": "json_object" }` enables the older JSON mode, which
2269	// ensures the message the model generates is valid JSON. Using `json_schema` is
2270	// preferred for models that support it.
2271	ResponseFormat ChatCompletionNewParamsResponseFormatUnion `json:"response_format,omitzero"`
2272	// Controls which (if any) tool is called by the model. `none` means the model will
2273	// not call any tool and instead generates a message. `auto` means the model can
2274	// pick between generating a message or calling one or more tools. `required` means
2275	// the model must call one or more tools. Specifying a particular tool via
2276	// `{"type": "function", "function": {"name": "my_function"}}` forces the model to
2277	// call that tool.
2278	//
2279	// `none` is the default when no tools are present. `auto` is the default if tools
2280	// are present.
2281	ToolChoice ChatCompletionToolChoiceOptionUnionParam `json:"tool_choice,omitzero"`
2282	// A list of tools the model may call. Currently, only functions are supported as a
2283	// tool. Use this to provide a list of functions the model may generate JSON inputs
2284	// for. A max of 128 functions are supported.
2285	Tools []ChatCompletionToolParam `json:"tools,omitzero"`
2286	// This tool searches the web for relevant results to use in a response. Learn more
2287	// about the
2288	// [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
2289	WebSearchOptions ChatCompletionNewParamsWebSearchOptions `json:"web_search_options,omitzero"`
2290	paramObj
2291}
2292
2293func (r ChatCompletionNewParams) MarshalJSON() (data []byte, err error) {
2294	type shadow ChatCompletionNewParams
2295	return param.MarshalObject(r, (*shadow)(&r))
2296}
2297func (r *ChatCompletionNewParams) UnmarshalJSON(data []byte) error {
2298	return apijson.UnmarshalRoot(data, r)
2299}
2300
2301// Only one field can be non-zero.
2302//
2303// Use [param.IsOmitted] to confirm if a field is set.
2304type ChatCompletionNewParamsFunctionCallUnion struct {
2305	// Check if union is this variant with !param.IsOmitted(union.OfFunctionCallMode)
2306	OfFunctionCallMode   param.Opt[string]                      `json:",omitzero,inline"`
2307	OfFunctionCallOption *ChatCompletionFunctionCallOptionParam `json:",omitzero,inline"`
2308	paramUnion
2309}
2310
2311func (u ChatCompletionNewParamsFunctionCallUnion) MarshalJSON() ([]byte, error) {
2312	return param.MarshalUnion(u, u.OfFunctionCallMode, u.OfFunctionCallOption)
2313}
2314func (u *ChatCompletionNewParamsFunctionCallUnion) UnmarshalJSON(data []byte) error {
2315	return apijson.UnmarshalRoot(data, u)
2316}
2317
2318func (u *ChatCompletionNewParamsFunctionCallUnion) asAny() any {
2319	if !param.IsOmitted(u.OfFunctionCallMode) {
2320		return &u.OfFunctionCallMode
2321	} else if !param.IsOmitted(u.OfFunctionCallOption) {
2322		return u.OfFunctionCallOption
2323	}
2324	return nil
2325}
2326
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.
2330type ChatCompletionNewParamsFunctionCallFunctionCallMode string
2331
2332const (
2333	ChatCompletionNewParamsFunctionCallFunctionCallModeNone ChatCompletionNewParamsFunctionCallFunctionCallMode = "none"
2334	ChatCompletionNewParamsFunctionCallFunctionCallModeAuto ChatCompletionNewParamsFunctionCallFunctionCallMode = "auto"
2335)
2336
2337// Deprecated: deprecated
2338//
2339// The property Name is required.
2340type ChatCompletionNewParamsFunction struct {
2341	// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
2342	// underscores and dashes, with a maximum length of 64.
2343	Name string `json:"name,required"`
2344	// A description of what the function does, used by the model to choose when and
2345	// how to call the function.
2346	Description param.Opt[string] `json:"description,omitzero"`
2347	// The parameters the functions accepts, described as a JSON Schema object. See the
2348	// [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
2349	// and the
2350	// [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
2351	// documentation about the format.
2352	//
2353	// Omitting `parameters` defines a function with an empty parameter list.
2354	Parameters shared.FunctionParameters `json:"parameters,omitzero"`
2355	paramObj
2356}
2357
2358func (r ChatCompletionNewParamsFunction) MarshalJSON() (data []byte, err error) {
2359	type shadow ChatCompletionNewParamsFunction
2360	return param.MarshalObject(r, (*shadow)(&r))
2361}
2362func (r *ChatCompletionNewParamsFunction) UnmarshalJSON(data []byte) error {
2363	return apijson.UnmarshalRoot(data, r)
2364}
2365
2366// Only one field can be non-zero.
2367//
2368// Use [param.IsOmitted] to confirm if a field is set.
2369type ChatCompletionNewParamsResponseFormatUnion struct {
2370	OfText       *shared.ResponseFormatTextParam       `json:",omitzero,inline"`
2371	OfJSONSchema *shared.ResponseFormatJSONSchemaParam `json:",omitzero,inline"`
2372	OfJSONObject *shared.ResponseFormatJSONObjectParam `json:",omitzero,inline"`
2373	paramUnion
2374}
2375
2376func (u ChatCompletionNewParamsResponseFormatUnion) MarshalJSON() ([]byte, error) {
2377	return param.MarshalUnion(u, u.OfText, u.OfJSONSchema, u.OfJSONObject)
2378}
2379func (u *ChatCompletionNewParamsResponseFormatUnion) UnmarshalJSON(data []byte) error {
2380	return apijson.UnmarshalRoot(data, u)
2381}
2382
2383func (u *ChatCompletionNewParamsResponseFormatUnion) asAny() any {
2384	if !param.IsOmitted(u.OfText) {
2385		return u.OfText
2386	} else if !param.IsOmitted(u.OfJSONSchema) {
2387		return u.OfJSONSchema
2388	} else if !param.IsOmitted(u.OfJSONObject) {
2389		return u.OfJSONObject
2390	}
2391	return nil
2392}
2393
2394// Returns a pointer to the underlying variant's property, if present.
2395func (u ChatCompletionNewParamsResponseFormatUnion) GetJSONSchema() *shared.ResponseFormatJSONSchemaJSONSchemaParam {
2396	if vt := u.OfJSONSchema; vt != nil {
2397		return &vt.JSONSchema
2398	}
2399	return nil
2400}
2401
2402// Returns a pointer to the underlying variant's property, if present.
2403func (u ChatCompletionNewParamsResponseFormatUnion) GetType() *string {
2404	if vt := u.OfText; vt != nil {
2405		return (*string)(&vt.Type)
2406	} else if vt := u.OfJSONSchema; vt != nil {
2407		return (*string)(&vt.Type)
2408	} else if vt := u.OfJSONObject; vt != nil {
2409		return (*string)(&vt.Type)
2410	}
2411	return nil
2412}
2413
2414// Specifies the processing type used for serving the request.
2415//
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.
2425//   - When not set, the default behavior is 'auto'.
2426//
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.
2431type ChatCompletionNewParamsServiceTier string
2432
2433const (
2434	ChatCompletionNewParamsServiceTierAuto     ChatCompletionNewParamsServiceTier = "auto"
2435	ChatCompletionNewParamsServiceTierDefault  ChatCompletionNewParamsServiceTier = "default"
2436	ChatCompletionNewParamsServiceTierFlex     ChatCompletionNewParamsServiceTier = "flex"
2437	ChatCompletionNewParamsServiceTierScale    ChatCompletionNewParamsServiceTier = "scale"
2438	ChatCompletionNewParamsServiceTierPriority ChatCompletionNewParamsServiceTier = "priority"
2439)
2440
2441// Only one field can be non-zero.
2442//
2443// Use [param.IsOmitted] to confirm if a field is set.
2444type ChatCompletionNewParamsStopUnion struct {
2445	OfString      param.Opt[string] `json:",omitzero,inline"`
2446	OfStringArray []string          `json:",omitzero,inline"`
2447	paramUnion
2448}
2449
2450func (u ChatCompletionNewParamsStopUnion) MarshalJSON() ([]byte, error) {
2451	return param.MarshalUnion(u, u.OfString, u.OfStringArray)
2452}
2453func (u *ChatCompletionNewParamsStopUnion) UnmarshalJSON(data []byte) error {
2454	return apijson.UnmarshalRoot(data, u)
2455}
2456
2457func (u *ChatCompletionNewParamsStopUnion) asAny() any {
2458	if !param.IsOmitted(u.OfString) {
2459		return &u.OfString.Value
2460	} else if !param.IsOmitted(u.OfStringArray) {
2461		return &u.OfStringArray
2462	}
2463	return nil
2464}
2465
2466// This tool searches the web for relevant results to use in a response. Learn more
2467// about the
2468// [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
2469type ChatCompletionNewParamsWebSearchOptions struct {
2470	// Approximate location parameters for the search.
2471	UserLocation ChatCompletionNewParamsWebSearchOptionsUserLocation `json:"user_location,omitzero"`
2472	// High level guidance for the amount of context window space to use for the
2473	// search. One of `low`, `medium`, or `high`. `medium` is the default.
2474	//
2475	// Any of "low", "medium", "high".
2476	SearchContextSize string `json:"search_context_size,omitzero"`
2477	paramObj
2478}
2479
2480func (r ChatCompletionNewParamsWebSearchOptions) MarshalJSON() (data []byte, err error) {
2481	type shadow ChatCompletionNewParamsWebSearchOptions
2482	return param.MarshalObject(r, (*shadow)(&r))
2483}
2484func (r *ChatCompletionNewParamsWebSearchOptions) UnmarshalJSON(data []byte) error {
2485	return apijson.UnmarshalRoot(data, r)
2486}
2487
2488func init() {
2489	apijson.RegisterFieldValidator[ChatCompletionNewParamsWebSearchOptions](
2490		"search_context_size", "low", "medium", "high",
2491	)
2492}
2493
2494// Approximate location parameters for the search.
2495//
2496// The properties Approximate, Type are required.
2497type ChatCompletionNewParamsWebSearchOptionsUserLocation struct {
2498	// Approximate location parameters for the search.
2499	Approximate ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate `json:"approximate,omitzero,required"`
2500	// The type of location approximation. Always `approximate`.
2501	//
2502	// This field can be elided, and will marshal its zero value as "approximate".
2503	Type constant.Approximate `json:"type,required"`
2504	paramObj
2505}
2506
2507func (r ChatCompletionNewParamsWebSearchOptionsUserLocation) MarshalJSON() (data []byte, err error) {
2508	type shadow ChatCompletionNewParamsWebSearchOptionsUserLocation
2509	return param.MarshalObject(r, (*shadow)(&r))
2510}
2511func (r *ChatCompletionNewParamsWebSearchOptionsUserLocation) UnmarshalJSON(data []byte) error {
2512	return apijson.UnmarshalRoot(data, r)
2513}
2514
2515// Approximate location parameters for the search.
2516type ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate struct {
2517	// Free text input for the city of the user, e.g. `San Francisco`.
2518	City param.Opt[string] `json:"city,omitzero"`
2519	// The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of
2520	// the user, e.g. `US`.
2521	Country param.Opt[string] `json:"country,omitzero"`
2522	// Free text input for the region of the user, e.g. `California`.
2523	Region param.Opt[string] `json:"region,omitzero"`
2524	// The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the
2525	// user, e.g. `America/Los_Angeles`.
2526	Timezone param.Opt[string] `json:"timezone,omitzero"`
2527	paramObj
2528}
2529
2530func (r ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate) MarshalJSON() (data []byte, err error) {
2531	type shadow ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate
2532	return param.MarshalObject(r, (*shadow)(&r))
2533}
2534func (r *ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate) UnmarshalJSON(data []byte) error {
2535	return apijson.UnmarshalRoot(data, r)
2536}
2537
2538type ChatCompletionUpdateParams struct {
2539	// Set of 16 key-value pairs that can be attached to an object. This can be useful
2540	// for storing additional information about the object in a structured format, and
2541	// querying for objects via API or the dashboard.
2542	//
2543	// Keys are strings with a maximum length of 64 characters. Values are strings with
2544	// a maximum length of 512 characters.
2545	Metadata shared.Metadata `json:"metadata,omitzero,required"`
2546	paramObj
2547}
2548
2549func (r ChatCompletionUpdateParams) MarshalJSON() (data []byte, err error) {
2550	type shadow ChatCompletionUpdateParams
2551	return param.MarshalObject(r, (*shadow)(&r))
2552}
2553func (r *ChatCompletionUpdateParams) UnmarshalJSON(data []byte) error {
2554	return apijson.UnmarshalRoot(data, r)
2555}
2556
2557type ChatCompletionListParams struct {
2558	// Identifier for the last chat completion from the previous pagination request.
2559	After param.Opt[string] `query:"after,omitzero" json:"-"`
2560	// Number of Chat Completions to retrieve.
2561	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
2562	// The model used to generate the Chat Completions.
2563	Model param.Opt[string] `query:"model,omitzero" json:"-"`
2564	// A list of metadata keys to filter the Chat Completions by. Example:
2565	//
2566	// `metadata[key1]=value1&metadata[key2]=value2`
2567	Metadata shared.Metadata `query:"metadata,omitzero" json:"-"`
2568	// Sort order for Chat Completions by timestamp. Use `asc` for ascending order or
2569	// `desc` for descending order. Defaults to `asc`.
2570	//
2571	// Any of "asc", "desc".
2572	Order ChatCompletionListParamsOrder `query:"order,omitzero" json:"-"`
2573	paramObj
2574}
2575
2576// URLQuery serializes [ChatCompletionListParams]'s query parameters as
2577// `url.Values`.
2578func (r ChatCompletionListParams) URLQuery() (v url.Values, err error) {
2579	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
2580		ArrayFormat:  apiquery.ArrayQueryFormatBrackets,
2581		NestedFormat: apiquery.NestedQueryFormatBrackets,
2582	})
2583}
2584
2585// Sort order for Chat Completions by timestamp. Use `asc` for ascending order or
2586// `desc` for descending order. Defaults to `asc`.
2587type ChatCompletionListParamsOrder string
2588
2589const (
2590	ChatCompletionListParamsOrderAsc  ChatCompletionListParamsOrder = "asc"
2591	ChatCompletionListParamsOrderDesc ChatCompletionListParamsOrder = "desc"
2592)