// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package openai

import (
	"context"
	"encoding/json"
	"errors"
	"net/http"
	"net/url"
	"slices"

	"github.com/openai/openai-go/v3/internal/apijson"
	"github.com/openai/openai-go/v3/internal/apiquery"
	"github.com/openai/openai-go/v3/internal/requestconfig"
	"github.com/openai/openai-go/v3/option"
	"github.com/openai/openai-go/v3/packages/pagination"
	"github.com/openai/openai-go/v3/packages/param"
	"github.com/openai/openai-go/v3/packages/respjson"
	"github.com/openai/openai-go/v3/packages/ssestream"
	"github.com/openai/openai-go/v3/shared"
	"github.com/openai/openai-go/v3/shared/constant"
)

// Given a list of messages comprising a conversation, the model will return a
// response.
//
// ChatCompletionService contains methods and other services that help with
// interacting with the openai API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewChatCompletionService] method instead.
type ChatCompletionService struct {
	Options []option.RequestOption
	// Given a list of messages comprising a conversation, the model will return a
	// response.
	Messages ChatCompletionMessageService
}

// NewChatCompletionService generates a new service that applies the given options
// to each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewChatCompletionService(opts ...option.RequestOption) (r ChatCompletionService) {
	r = ChatCompletionService{}
	r.Options = opts
	r.Messages = NewChatCompletionMessageService(opts...)
	return
}

// **Starting a new project?** We recommend trying
// [Responses](https://platform.openai.com/docs/api-reference/responses) to take
// advantage of the latest OpenAI platform features. Compare
// [Chat Completions with Responses](https://platform.openai.com/docs/guides/responses-vs-chat-completions?api-mode=responses).
//
// ---
//
// Creates a model response for the given chat conversation. Learn more in the
// [text generation](https://platform.openai.com/docs/guides/text-generation),
// [vision](https://platform.openai.com/docs/guides/vision), and
// [audio](https://platform.openai.com/docs/guides/audio) guides.
//
// Parameter support can differ depending on the model used to generate the
// response, particularly for newer reasoning models. Parameters that are only
// supported for reasoning models are noted below. For the current state of
// unsupported parameters in reasoning models,
// [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).
//
// Returns a chat completion object, or a streamed sequence of chat completion
// chunk objects if the request is streamed.
func (r *ChatCompletionService) New(ctx context.Context, body ChatCompletionNewParams, opts ...option.RequestOption) (res *ChatCompletion, err error) {
	var preClientOpts = []option.RequestOption{requestconfig.WithBearerAuthSecurity()}
	opts = slices.Concat(preClientOpts, r.Options, opts)
	path := "chat/completions"
	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
	return res, err
}

// **Starting a new project?** We recommend trying
// [Responses](https://platform.openai.com/docs/api-reference/responses) to take
// advantage of the latest OpenAI platform features. Compare
// [Chat Completions with Responses](https://platform.openai.com/docs/guides/responses-vs-chat-completions?api-mode=responses).
//
// ---
//
// Creates a model response for the given chat conversation. Learn more in the
// [text generation](https://platform.openai.com/docs/guides/text-generation),
// [vision](https://platform.openai.com/docs/guides/vision), and
// [audio](https://platform.openai.com/docs/guides/audio) guides.
//
// Parameter support can differ depending on the model used to generate the
// response, particularly for newer reasoning models. Parameters that are only
// supported for reasoning models are noted below. For the current state of
// unsupported parameters in reasoning models,
// [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).
//
// Returns a chat completion object, or a streamed sequence of chat completion
// chunk objects if the request is streamed.
func (r *ChatCompletionService) NewStreaming(ctx context.Context, body ChatCompletionNewParams, opts ...option.RequestOption) (stream *ssestream.Stream[ChatCompletionChunk]) {
	var (
		raw *http.Response
		err error
	)
	var preClientOpts = []option.RequestOption{requestconfig.WithBearerAuthSecurity()}
	opts = slices.Concat(preClientOpts, r.Options, opts)
	opts = append(opts, option.WithJSONSet("stream", true))
	path := "chat/completions"
	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &raw, opts...)
	return ssestream.NewStream[ChatCompletionChunk](ssestream.NewDecoder(raw), err)
}

// Get a stored chat completion. Only Chat Completions that have been created with
// the `store` parameter set to `true` will be returned.
func (r *ChatCompletionService) Get(ctx context.Context, completionID string, opts ...option.RequestOption) (res *ChatCompletion, err error) {
	var preClientOpts = []option.RequestOption{requestconfig.WithBearerAuthSecurity()}
	opts = slices.Concat(preClientOpts, r.Options, opts)
	if completionID == "" {
		err = errors.New("missing required completion_id parameter")
		return nil, err
	}
	path := requestconfig.FormatPath("chat/completions/%s", completionID)
	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
	return res, err
}

// Modify a stored chat completion. Only Chat Completions that have been created
// with the `store` parameter set to `true` can be modified. Currently, the only
// supported modification is to update the `metadata` field.
func (r *ChatCompletionService) Update(ctx context.Context, completionID string, body ChatCompletionUpdateParams, opts ...option.RequestOption) (res *ChatCompletion, err error) {
	var preClientOpts = []option.RequestOption{requestconfig.WithBearerAuthSecurity()}
	opts = slices.Concat(preClientOpts, r.Options, opts)
	if completionID == "" {
		err = errors.New("missing required completion_id parameter")
		return nil, err
	}
	path := requestconfig.FormatPath("chat/completions/%s", completionID)
	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
	return res, err
}

// List stored Chat Completions. Only Chat Completions that have been stored with
// the `store` parameter set to `true` will be returned.
func (r *ChatCompletionService) List(ctx context.Context, query ChatCompletionListParams, opts ...option.RequestOption) (res *pagination.CursorPage[ChatCompletion], err error) {
	var raw *http.Response
	var preClientOpts = []option.RequestOption{requestconfig.WithBearerAuthSecurity()}
	opts = slices.Concat(preClientOpts, r.Options, opts)
	opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
	path := "chat/completions"
	cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
	if err != nil {
		return nil, err
	}
	err = cfg.Execute()
	if err != nil {
		return nil, err
	}
	res.SetPageConfig(cfg, raw)
	return res, nil
}

// List stored Chat Completions. Only Chat Completions that have been stored with
// the `store` parameter set to `true` will be returned.
func (r *ChatCompletionService) ListAutoPaging(ctx context.Context, query ChatCompletionListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[ChatCompletion] {
	return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
}

// Delete a stored chat completion. Only Chat Completions that have been created
// with the `store` parameter set to `true` can be deleted.
func (r *ChatCompletionService) Delete(ctx context.Context, completionID string, opts ...option.RequestOption) (res *ChatCompletionDeleted, err error) {
	var preClientOpts = []option.RequestOption{requestconfig.WithBearerAuthSecurity()}
	opts = slices.Concat(preClientOpts, r.Options, opts)
	if completionID == "" {
		err = errors.New("missing required completion_id parameter")
		return nil, err
	}
	path := requestconfig.FormatPath("chat/completions/%s", completionID)
	err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
	return res, err
}

// Represents a chat completion response returned by model, based on the provided
// input.
type ChatCompletion struct {
	// A unique identifier for the chat completion.
	ID string `json:"id" api:"required"`
	// A list of chat completion choices. Can be more than one if `n` is greater
	// than 1.
	Choices []ChatCompletionChoice `json:"choices" api:"required"`
	// The Unix timestamp (in seconds) of when the chat completion was created.
	Created int64 `json:"created" api:"required" format:"unixtime"`
	// The model used for the chat completion.
	Model string `json:"model" api:"required"`
	// The object type, which is always `chat.completion`.
	Object constant.ChatCompletion `json:"object" default:"chat.completion"`
	// Moderation results for the request input and generated output, if moderated
	// completions were requested.
	Moderation ChatCompletionModeration `json:"moderation" api:"nullable"`
	// Specifies the processing type used for serving the request.
	//
	//   - If set to 'auto', then the request will be processed with the service tier
	//     configured in the Project settings. Unless otherwise configured, the Project
	//     will use 'default'.
	//   - If set to 'default', then the request will be processed with the standard
	//     pricing and performance for the selected model.
	//   - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
	//     '[priority](https://openai.com/api-priority-processing/)', then the request
	//     will be processed with the corresponding service tier.
	//   - When not set, the default behavior is 'auto'.
	//
	// When the `service_tier` parameter is set, the response body will include the
	// `service_tier` value based on the processing mode actually used to serve the
	// request. This response value may be different from the value set in the
	// parameter.
	//
	// Any of "auto", "default", "flex", "scale", "priority".
	ServiceTier ChatCompletionServiceTier `json:"service_tier" api:"nullable"`
	// This fingerprint represents the backend configuration that the model runs with.
	//
	// Can be used in conjunction with the `seed` request parameter to understand when
	// backend changes have been made that might impact determinism.
	//
	// Deprecated: deprecated
	SystemFingerprint string `json:"system_fingerprint"`
	// Usage statistics for the completion request.
	Usage CompletionUsage `json:"usage"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		ID                respjson.Field
		Choices           respjson.Field
		Created           respjson.Field
		Model             respjson.Field
		Object            respjson.Field
		Moderation        respjson.Field
		ServiceTier       respjson.Field
		SystemFingerprint respjson.Field
		Usage             respjson.Field
		ExtraFields       map[string]respjson.Field
		raw               string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletion) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

type ChatCompletionChoice struct {
	// The reason the model stopped generating tokens. This will be `stop` if the model
	// hit a natural stop point or a provided stop sequence, `length` if the maximum
	// number of tokens specified in the request was reached, `content_filter` if
	// content was omitted due to a flag from our content filters, `tool_calls` if the
	// model called a tool, or `function_call` (deprecated) if the model called a
	// function. Read the [Model Spec](https://model-spec.openai.com/2025-12-18.html)
	// for more.
	//
	// Any of "stop", "length", "tool_calls", "content_filter", "function_call".
	FinishReason string `json:"finish_reason" api:"required"`
	// The index of the choice in the list of choices.
	Index int64 `json:"index" api:"required"`
	// Log probability information for the choice.
	Logprobs ChatCompletionChoiceLogprobs `json:"logprobs" api:"required"`
	// A chat completion message generated by the model.
	Message ChatCompletionMessage `json:"message" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		FinishReason respjson.Field
		Index        respjson.Field
		Logprobs     respjson.Field
		Message      respjson.Field
		ExtraFields  map[string]respjson.Field
		raw          string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChoice) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChoice) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Log probability information for the choice.
type ChatCompletionChoiceLogprobs struct {
	// A list of message content tokens with log probability information.
	Content []ChatCompletionTokenLogprob `json:"content" api:"required"`
	// A list of message refusal tokens with log probability information.
	Refusal []ChatCompletionTokenLogprob `json:"refusal" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Content     respjson.Field
		Refusal     respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChoiceLogprobs) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChoiceLogprobs) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Moderation results for the request input and generated output, if moderated
// completions were requested.
type ChatCompletionModeration struct {
	// Moderation for the request input.
	Input ChatCompletionModerationInputUnion `json:"input" api:"required"`
	// Moderation for the generated output.
	Output ChatCompletionModerationOutputUnion `json:"output" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Input       respjson.Field
		Output      respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionModeration) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionModeration) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// ChatCompletionModerationInputUnion contains all possible properties and values
// from [ChatCompletionModerationInputModerationResults],
// [ChatCompletionModerationInputError].
//
// Use the [ChatCompletionModerationInputUnion.AsAny] method to switch on the
// variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type ChatCompletionModerationInputUnion struct {
	// This field is from variant [ChatCompletionModerationInputModerationResults].
	Model string `json:"model"`
	// This field is from variant [ChatCompletionModerationInputModerationResults].
	Results []ChatCompletionModerationInputModerationResultsResult `json:"results"`
	// Any of "moderation_results", "error".
	Type string `json:"type"`
	// This field is from variant [ChatCompletionModerationInputError].
	Code string `json:"code"`
	// This field is from variant [ChatCompletionModerationInputError].
	Message string `json:"message"`
	JSON    struct {
		Model   respjson.Field
		Results respjson.Field
		Type    respjson.Field
		Code    respjson.Field
		Message respjson.Field
		raw     string
	} `json:"-"`
}

// anyChatCompletionModerationInput is implemented by each variant of
// [ChatCompletionModerationInputUnion] to add type safety for the return type of
// [ChatCompletionModerationInputUnion.AsAny]
type anyChatCompletionModerationInput interface {
	implChatCompletionModerationInputUnion()
}

func (ChatCompletionModerationInputModerationResults) implChatCompletionModerationInputUnion() {}
func (ChatCompletionModerationInputError) implChatCompletionModerationInputUnion()             {}

// Use the following switch statement to find the correct variant
//
//	switch variant := ChatCompletionModerationInputUnion.AsAny().(type) {
//	case openai.ChatCompletionModerationInputModerationResults:
//	case openai.ChatCompletionModerationInputError:
//	default:
//	  fmt.Errorf("no variant present")
//	}
func (u ChatCompletionModerationInputUnion) AsAny() anyChatCompletionModerationInput {
	switch u.Type {
	case "moderation_results":
		return u.AsModerationResults()
	case "error":
		return u.AsError()
	}
	return nil
}

func (u ChatCompletionModerationInputUnion) AsModerationResults() (v ChatCompletionModerationInputModerationResults) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

func (u ChatCompletionModerationInputUnion) AsError() (v ChatCompletionModerationInputError) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

// Returns the unmodified JSON received from the API
func (u ChatCompletionModerationInputUnion) RawJSON() string { return u.JSON.raw }

func (r *ChatCompletionModerationInputUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Successful moderation results for the request input or generated output.
type ChatCompletionModerationInputModerationResults struct {
	// The moderation model used to generate the results.
	Model string `json:"model" api:"required"`
	// A list of moderation results.
	Results []ChatCompletionModerationInputModerationResultsResult `json:"results" api:"required"`
	// The object type, which is always `moderation_results`.
	Type constant.ModerationResults `json:"type" default:"moderation_results"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Model       respjson.Field
		Results     respjson.Field
		Type        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionModerationInputModerationResults) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionModerationInputModerationResults) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A moderation result produced for the response input or output.
type ChatCompletionModerationInputModerationResultsResult struct {
	// A dictionary of moderation categories to booleans, True if the input is flagged
	// under this category.
	Categories map[string]bool `json:"categories" api:"required"`
	// Which modalities of input are reflected by the score for each category.
	CategoryAppliedInputTypes map[string][]string `json:"category_applied_input_types" api:"required"`
	// A dictionary of moderation categories to scores.
	CategoryScores map[string]float64 `json:"category_scores" api:"required"`
	// A boolean indicating whether the content was flagged by any category.
	Flagged bool `json:"flagged" api:"required"`
	// The moderation model that produced this result.
	Model string `json:"model" api:"required"`
	// The object type, which was always `moderation_result` for successful moderation
	// results.
	Type constant.ModerationResult `json:"type" default:"moderation_result"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Categories                respjson.Field
		CategoryAppliedInputTypes respjson.Field
		CategoryScores            respjson.Field
		Flagged                   respjson.Field
		Model                     respjson.Field
		Type                      respjson.Field
		ExtraFields               map[string]respjson.Field
		raw                       string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionModerationInputModerationResultsResult) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionModerationInputModerationResultsResult) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// An error produced while attempting moderation.
type ChatCompletionModerationInputError struct {
	// The error code.
	Code string `json:"code" api:"required"`
	// The error message.
	Message string `json:"message" api:"required"`
	// The object type, which is always `error`.
	Type constant.Error `json:"type" default:"error"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Message     respjson.Field
		Type        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionModerationInputError) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionModerationInputError) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// ChatCompletionModerationOutputUnion contains all possible properties and values
// from [ChatCompletionModerationOutputModerationResults],
// [ChatCompletionModerationOutputError].
//
// Use the [ChatCompletionModerationOutputUnion.AsAny] method to switch on the
// variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type ChatCompletionModerationOutputUnion struct {
	// This field is from variant [ChatCompletionModerationOutputModerationResults].
	Model string `json:"model"`
	// This field is from variant [ChatCompletionModerationOutputModerationResults].
	Results []ChatCompletionModerationOutputModerationResultsResult `json:"results"`
	// Any of "moderation_results", "error".
	Type string `json:"type"`
	// This field is from variant [ChatCompletionModerationOutputError].
	Code string `json:"code"`
	// This field is from variant [ChatCompletionModerationOutputError].
	Message string `json:"message"`
	JSON    struct {
		Model   respjson.Field
		Results respjson.Field
		Type    respjson.Field
		Code    respjson.Field
		Message respjson.Field
		raw     string
	} `json:"-"`
}

// anyChatCompletionModerationOutput is implemented by each variant of
// [ChatCompletionModerationOutputUnion] to add type safety for the return type of
// [ChatCompletionModerationOutputUnion.AsAny]
type anyChatCompletionModerationOutput interface {
	implChatCompletionModerationOutputUnion()
}

func (ChatCompletionModerationOutputModerationResults) implChatCompletionModerationOutputUnion() {}
func (ChatCompletionModerationOutputError) implChatCompletionModerationOutputUnion()             {}

// Use the following switch statement to find the correct variant
//
//	switch variant := ChatCompletionModerationOutputUnion.AsAny().(type) {
//	case openai.ChatCompletionModerationOutputModerationResults:
//	case openai.ChatCompletionModerationOutputError:
//	default:
//	  fmt.Errorf("no variant present")
//	}
func (u ChatCompletionModerationOutputUnion) AsAny() anyChatCompletionModerationOutput {
	switch u.Type {
	case "moderation_results":
		return u.AsModerationResults()
	case "error":
		return u.AsError()
	}
	return nil
}

func (u ChatCompletionModerationOutputUnion) AsModerationResults() (v ChatCompletionModerationOutputModerationResults) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

func (u ChatCompletionModerationOutputUnion) AsError() (v ChatCompletionModerationOutputError) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

// Returns the unmodified JSON received from the API
func (u ChatCompletionModerationOutputUnion) RawJSON() string { return u.JSON.raw }

func (r *ChatCompletionModerationOutputUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Successful moderation results for the request input or generated output.
type ChatCompletionModerationOutputModerationResults struct {
	// The moderation model used to generate the results.
	Model string `json:"model" api:"required"`
	// A list of moderation results.
	Results []ChatCompletionModerationOutputModerationResultsResult `json:"results" api:"required"`
	// The object type, which is always `moderation_results`.
	Type constant.ModerationResults `json:"type" default:"moderation_results"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Model       respjson.Field
		Results     respjson.Field
		Type        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionModerationOutputModerationResults) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionModerationOutputModerationResults) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A moderation result produced for the response input or output.
type ChatCompletionModerationOutputModerationResultsResult struct {
	// A dictionary of moderation categories to booleans, True if the input is flagged
	// under this category.
	Categories map[string]bool `json:"categories" api:"required"`
	// Which modalities of input are reflected by the score for each category.
	CategoryAppliedInputTypes map[string][]string `json:"category_applied_input_types" api:"required"`
	// A dictionary of moderation categories to scores.
	CategoryScores map[string]float64 `json:"category_scores" api:"required"`
	// A boolean indicating whether the content was flagged by any category.
	Flagged bool `json:"flagged" api:"required"`
	// The moderation model that produced this result.
	Model string `json:"model" api:"required"`
	// The object type, which was always `moderation_result` for successful moderation
	// results.
	Type constant.ModerationResult `json:"type" default:"moderation_result"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Categories                respjson.Field
		CategoryAppliedInputTypes respjson.Field
		CategoryScores            respjson.Field
		Flagged                   respjson.Field
		Model                     respjson.Field
		Type                      respjson.Field
		ExtraFields               map[string]respjson.Field
		raw                       string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionModerationOutputModerationResultsResult) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionModerationOutputModerationResultsResult) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// An error produced while attempting moderation.
type ChatCompletionModerationOutputError struct {
	// The error code.
	Code string `json:"code" api:"required"`
	// The error message.
	Message string `json:"message" api:"required"`
	// The object type, which is always `error`.
	Type constant.Error `json:"type" default:"error"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Message     respjson.Field
		Type        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionModerationOutputError) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionModerationOutputError) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Specifies the processing type used for serving the request.
//
//   - If set to 'auto', then the request will be processed with the service tier
//     configured in the Project settings. Unless otherwise configured, the Project
//     will use 'default'.
//   - If set to 'default', then the request will be processed with the standard
//     pricing and performance for the selected model.
//   - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
//     '[priority](https://openai.com/api-priority-processing/)', then the request
//     will be processed with the corresponding service tier.
//   - When not set, the default behavior is 'auto'.
//
// When the `service_tier` parameter is set, the response body will include the
// `service_tier` value based on the processing mode actually used to serve the
// request. This response value may be different from the value set in the
// parameter.
type ChatCompletionServiceTier string

const (
	ChatCompletionServiceTierAuto     ChatCompletionServiceTier = "auto"
	ChatCompletionServiceTierDefault  ChatCompletionServiceTier = "default"
	ChatCompletionServiceTierFlex     ChatCompletionServiceTier = "flex"
	ChatCompletionServiceTierScale    ChatCompletionServiceTier = "scale"
	ChatCompletionServiceTierPriority ChatCompletionServiceTier = "priority"
)

// Constrains the tools available to the model to a pre-defined set.
//
// The properties AllowedTools, Type are required.
type ChatCompletionAllowedToolChoiceParam struct {
	// Constrains the tools available to the model to a pre-defined set.
	AllowedTools ChatCompletionAllowedToolsParam `json:"allowed_tools,omitzero" api:"required"`
	// Allowed tool configuration type. Always `allowed_tools`.
	//
	// This field can be elided, and will marshal its zero value as "allowed_tools".
	Type constant.AllowedTools `json:"type" default:"allowed_tools"`
	paramObj
}

func (r ChatCompletionAllowedToolChoiceParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionAllowedToolChoiceParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionAllowedToolChoiceParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Messages sent by the model in response to user messages.
//
// The property Role is required.
type ChatCompletionAssistantMessageParam struct {
	// The refusal message by the assistant.
	Refusal param.Opt[string] `json:"refusal,omitzero"`
	// An optional name for the participant. Provides the model information to
	// differentiate between participants of the same role.
	Name param.Opt[string] `json:"name,omitzero"`
	// Data about a previous audio response from the model.
	// [Learn more](https://platform.openai.com/docs/guides/audio).
	Audio ChatCompletionAssistantMessageParamAudio `json:"audio,omitzero"`
	// The contents of the assistant message. Required unless `tool_calls` or
	// `function_call` is specified.
	Content ChatCompletionAssistantMessageParamContentUnion `json:"content,omitzero"`
	// Deprecated and replaced by `tool_calls`. The name and arguments of a function
	// that should be called, as generated by the model.
	//
	// Deprecated: deprecated
	FunctionCall ChatCompletionAssistantMessageParamFunctionCall `json:"function_call,omitzero"`
	// The tool calls generated by the model, such as function calls.
	ToolCalls []ChatCompletionMessageToolCallUnionParam `json:"tool_calls,omitzero"`
	// The role of the messages author, in this case `assistant`.
	//
	// This field can be elided, and will marshal its zero value as "assistant".
	Role constant.Assistant `json:"role" default:"assistant"`
	paramObj
}

func (r ChatCompletionAssistantMessageParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionAssistantMessageParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionAssistantMessageParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Data about a previous audio response from the model.
// [Learn more](https://platform.openai.com/docs/guides/audio).
//
// The property ID is required.
type ChatCompletionAssistantMessageParamAudio struct {
	// Unique identifier for a previous audio response from the model.
	ID string `json:"id" api:"required"`
	paramObj
}

func (r ChatCompletionAssistantMessageParamAudio) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionAssistantMessageParamAudio
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionAssistantMessageParamAudio) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionAssistantMessageParamContentUnion struct {
	OfString              param.Opt[string]                                                   `json:",omitzero,inline"`
	OfArrayOfContentParts []ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionAssistantMessageParamContentUnion) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
}
func (u *ChatCompletionAssistantMessageParamContentUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionAssistantMessageParamContentUnion) asAny() any {
	if !param.IsOmitted(u.OfString) {
		return &u.OfString.Value
	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
		return &u.OfArrayOfContentParts
	}
	return nil
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion struct {
	OfText    *ChatCompletionContentPartTextParam    `json:",omitzero,inline"`
	OfRefusal *ChatCompletionContentPartRefusalParam `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfText, u.OfRefusal)
}
func (u *ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) asAny() any {
	if !param.IsOmitted(u.OfText) {
		return u.OfText
	} else if !param.IsOmitted(u.OfRefusal) {
		return u.OfRefusal
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetText() *string {
	if vt := u.OfText; vt != nil {
		return &vt.Text
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetPromptCacheBreakpoint() *ChatCompletionContentPartTextPromptCacheBreakpointParam {
	if vt := u.OfText; vt != nil {
		return &vt.PromptCacheBreakpoint
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetRefusal() *string {
	if vt := u.OfRefusal; vt != nil {
		return &vt.Refusal
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion) GetType() *string {
	if vt := u.OfText; vt != nil {
		return (*string)(&vt.Type)
	} else if vt := u.OfRefusal; vt != nil {
		return (*string)(&vt.Type)
	}
	return nil
}

func init() {
	apijson.RegisterUnion[ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion](
		"type",
		apijson.Discriminator[ChatCompletionContentPartTextParam]("text"),
		apijson.Discriminator[ChatCompletionContentPartRefusalParam]("refusal"),
	)
}

// Deprecated and replaced by `tool_calls`. The name and arguments of a function
// that should be called, as generated by the model.
//
// Deprecated: deprecated
//
// The properties Arguments, Name are required.
type ChatCompletionAssistantMessageParamFunctionCall struct {
	// The arguments to call the function with, as generated by the model in JSON
	// format. Note that the model does not always generate valid JSON, and may
	// hallucinate parameters not defined by your function schema. Validate the
	// arguments in your code before calling your function.
	Arguments string `json:"arguments" api:"required"`
	// The name of the function to call.
	Name string `json:"name" api:"required"`
	paramObj
}

func (r ChatCompletionAssistantMessageParamFunctionCall) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionAssistantMessageParamFunctionCall
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionAssistantMessageParamFunctionCall) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// If the audio output modality is requested, this object contains data about the
// audio response from the model.
// [Learn more](https://platform.openai.com/docs/guides/audio).
type ChatCompletionAudio struct {
	// Unique identifier for this audio response.
	ID string `json:"id" api:"required"`
	// Base64 encoded audio bytes generated by the model, in the format specified in
	// the request.
	Data string `json:"data" api:"required"`
	// The Unix timestamp (in seconds) for when this audio response will no longer be
	// accessible on the server for use in multi-turn conversations.
	ExpiresAt int64 `json:"expires_at" api:"required" format:"unixtime"`
	// Transcript of the audio generated by the model.
	Transcript string `json:"transcript" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		ID          respjson.Field
		Data        respjson.Field
		ExpiresAt   respjson.Field
		Transcript  respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionAudio) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionAudio) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Parameters for audio output. Required when audio output is requested with
// `modalities: ["audio"]`.
// [Learn more](https://platform.openai.com/docs/guides/audio).
//
// The properties Format, Voice are required.
type ChatCompletionAudioParam struct {
	// Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
	// or `pcm16`.
	//
	// Any of "wav", "aac", "mp3", "flac", "opus", "pcm16".
	Format ChatCompletionAudioParamFormat `json:"format,omitzero" api:"required"`
	// The voice the model uses to respond. Supported built-in voices are `alloy`,
	// `ash`, `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, `shimmer`,
	// `marin`, and `cedar`. You may also provide a custom voice object with an `id`,
	// for example `{ "id": "voice_1234" }`.
	Voice ChatCompletionAudioParamVoiceUnion `json:"voice,omitzero" api:"required"`
	paramObj
}

func (r ChatCompletionAudioParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionAudioParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionAudioParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
// or `pcm16`.
type ChatCompletionAudioParamFormat string

const (
	ChatCompletionAudioParamFormatWAV   ChatCompletionAudioParamFormat = "wav"
	ChatCompletionAudioParamFormatAAC   ChatCompletionAudioParamFormat = "aac"
	ChatCompletionAudioParamFormatMP3   ChatCompletionAudioParamFormat = "mp3"
	ChatCompletionAudioParamFormatFLAC  ChatCompletionAudioParamFormat = "flac"
	ChatCompletionAudioParamFormatOpus  ChatCompletionAudioParamFormat = "opus"
	ChatCompletionAudioParamFormatPcm16 ChatCompletionAudioParamFormat = "pcm16"
)

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionAudioParamVoiceUnion struct {
	OfString param.Opt[string] `json:",omitzero,inline"`
	// Check if union is this variant with
	// !param.IsOmitted(union.OfChatCompletionAudioVoiceString2)
	OfChatCompletionAudioVoiceString2 param.Opt[string]                `json:",omitzero,inline"`
	OfChatCompletionAudioVoiceID      *ChatCompletionAudioParamVoiceID `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionAudioParamVoiceUnion) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfString, u.OfChatCompletionAudioVoiceString2, u.OfChatCompletionAudioVoiceID)
}
func (u *ChatCompletionAudioParamVoiceUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionAudioParamVoiceUnion) asAny() any {
	if !param.IsOmitted(u.OfString) {
		return &u.OfString.Value
	} else if !param.IsOmitted(u.OfChatCompletionAudioVoiceString2) {
		return &u.OfChatCompletionAudioVoiceString2
	} else if !param.IsOmitted(u.OfChatCompletionAudioVoiceID) {
		return u.OfChatCompletionAudioVoiceID
	}
	return nil
}

type ChatCompletionAudioParamVoiceString2 string

const (
	ChatCompletionAudioParamVoiceString2Alloy   ChatCompletionAudioParamVoiceString2 = "alloy"
	ChatCompletionAudioParamVoiceString2Ash     ChatCompletionAudioParamVoiceString2 = "ash"
	ChatCompletionAudioParamVoiceString2Ballad  ChatCompletionAudioParamVoiceString2 = "ballad"
	ChatCompletionAudioParamVoiceString2Coral   ChatCompletionAudioParamVoiceString2 = "coral"
	ChatCompletionAudioParamVoiceString2Echo    ChatCompletionAudioParamVoiceString2 = "echo"
	ChatCompletionAudioParamVoiceString2Sage    ChatCompletionAudioParamVoiceString2 = "sage"
	ChatCompletionAudioParamVoiceString2Shimmer ChatCompletionAudioParamVoiceString2 = "shimmer"
	ChatCompletionAudioParamVoiceString2Verse   ChatCompletionAudioParamVoiceString2 = "verse"
	ChatCompletionAudioParamVoiceString2Marin   ChatCompletionAudioParamVoiceString2 = "marin"
	ChatCompletionAudioParamVoiceString2Cedar   ChatCompletionAudioParamVoiceString2 = "cedar"
)

// Custom voice reference.
//
// The property ID is required.
type ChatCompletionAudioParamVoiceID struct {
	// The custom voice ID, e.g. `voice_1234`.
	ID string `json:"id" api:"required"`
	paramObj
}

func (r ChatCompletionAudioParamVoiceID) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionAudioParamVoiceID
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionAudioParamVoiceID) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Represents a streamed chunk of a chat completion response returned by the model,
// based on the provided input.
// [Learn more](https://platform.openai.com/docs/guides/streaming-responses).
type ChatCompletionChunk struct {
	// A unique identifier for the chat completion. Each chunk has the same ID.
	ID string `json:"id" api:"required"`
	// A list of chat completion choices. Can contain more than one elements if `n` is
	// greater than 1. Can also be empty for the last chunk if you set
	// `stream_options: {"include_usage": true}`.
	Choices []ChatCompletionChunkChoice `json:"choices" api:"required"`
	// The Unix timestamp (in seconds) of when the chat completion was created. Each
	// chunk has the same timestamp.
	Created int64 `json:"created" api:"required" format:"unixtime"`
	// The model to generate the completion.
	Model string `json:"model" api:"required"`
	// The object type, which is always `chat.completion.chunk`.
	Object constant.ChatCompletionChunk `json:"object" default:"chat.completion.chunk"`
	// Moderation results for the request input and generated output. Present on the
	// moderation chunk when moderated completions are requested.
	Moderation ChatCompletionChunkModeration `json:"moderation" api:"nullable"`
	// Specifies the processing type used for serving the request.
	//
	//   - If set to 'auto', then the request will be processed with the service tier
	//     configured in the Project settings. Unless otherwise configured, the Project
	//     will use 'default'.
	//   - If set to 'default', then the request will be processed with the standard
	//     pricing and performance for the selected model.
	//   - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
	//     '[priority](https://openai.com/api-priority-processing/)', then the request
	//     will be processed with the corresponding service tier.
	//   - When not set, the default behavior is 'auto'.
	//
	// When the `service_tier` parameter is set, the response body will include the
	// `service_tier` value based on the processing mode actually used to serve the
	// request. This response value may be different from the value set in the
	// parameter.
	//
	// Any of "auto", "default", "flex", "scale", "priority".
	ServiceTier ChatCompletionChunkServiceTier `json:"service_tier" api:"nullable"`
	// This fingerprint represents the backend configuration that the model runs with.
	// Can be used in conjunction with the `seed` request parameter to understand when
	// backend changes have been made that might impact determinism.
	//
	// Deprecated: deprecated
	SystemFingerprint string `json:"system_fingerprint"`
	// An optional field that will only be present when you set
	// `stream_options: {"include_usage": true}` in your request. When present, it
	// contains a null value **except for the last chunk** which contains the token
	// usage statistics for the entire request.
	//
	// **NOTE:** If the stream is interrupted or cancelled, you may not receive the
	// final usage chunk which contains the total token usage for the request.
	Usage CompletionUsage `json:"usage" api:"nullable"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		ID                respjson.Field
		Choices           respjson.Field
		Created           respjson.Field
		Model             respjson.Field
		Object            respjson.Field
		Moderation        respjson.Field
		ServiceTier       respjson.Field
		SystemFingerprint respjson.Field
		Usage             respjson.Field
		ExtraFields       map[string]respjson.Field
		raw               string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunk) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunk) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

type ChatCompletionChunkChoice struct {
	// A chat completion delta generated by streamed model responses.
	Delta ChatCompletionChunkChoiceDelta `json:"delta" api:"required"`
	// The reason the model stopped generating tokens. This will be `stop` if the model
	// hit a natural stop point or a provided stop sequence, `length` if the maximum
	// number of tokens specified in the request was reached, `content_filter` if
	// content was omitted due to a flag from our content filters, `tool_calls` if the
	// model called a tool, or `function_call` (deprecated) if the model called a
	// function.
	//
	// Any of "stop", "length", "tool_calls", "content_filter", "function_call".
	FinishReason string `json:"finish_reason" api:"required"`
	// The index of the choice in the list of choices.
	Index int64 `json:"index" api:"required"`
	// Log probability information for the choice.
	Logprobs ChatCompletionChunkChoiceLogprobs `json:"logprobs" api:"nullable"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Delta        respjson.Field
		FinishReason respjson.Field
		Index        respjson.Field
		Logprobs     respjson.Field
		ExtraFields  map[string]respjson.Field
		raw          string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkChoice) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunkChoice) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A chat completion delta generated by streamed model responses.
type ChatCompletionChunkChoiceDelta struct {
	// The contents of the chunk message.
	Content string `json:"content" api:"nullable"`
	// Deprecated and replaced by `tool_calls`. The name and arguments of a function
	// that should be called, as generated by the model.
	//
	// Deprecated: deprecated
	FunctionCall ChatCompletionChunkChoiceDeltaFunctionCall `json:"function_call"`
	// The refusal message generated by the model.
	Refusal string `json:"refusal" api:"nullable"`
	// The role of the author of this message.
	//
	// Any of "developer", "system", "user", "assistant", "tool".
	Role      string                                   `json:"role"`
	ToolCalls []ChatCompletionChunkChoiceDeltaToolCall `json:"tool_calls"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Content      respjson.Field
		FunctionCall respjson.Field
		Refusal      respjson.Field
		Role         respjson.Field
		ToolCalls    respjson.Field
		ExtraFields  map[string]respjson.Field
		raw          string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkChoiceDelta) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunkChoiceDelta) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Deprecated and replaced by `tool_calls`. The name and arguments of a function
// that should be called, as generated by the model.
//
// Deprecated: deprecated
type ChatCompletionChunkChoiceDeltaFunctionCall struct {
	// The arguments to call the function with, as generated by the model in JSON
	// format. Note that the model does not always generate valid JSON, and may
	// hallucinate parameters not defined by your function schema. Validate the
	// arguments in your code before calling your function.
	Arguments string `json:"arguments"`
	// The name of the function to call.
	Name string `json:"name"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Arguments   respjson.Field
		Name        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkChoiceDeltaFunctionCall) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunkChoiceDeltaFunctionCall) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

type ChatCompletionChunkChoiceDeltaToolCall struct {
	Index int64 `json:"index" api:"required"`
	// The ID of the tool call.
	ID       string                                         `json:"id"`
	Function ChatCompletionChunkChoiceDeltaToolCallFunction `json:"function"`
	// The type of the tool. Currently, only `function` is supported.
	//
	// Any of "function".
	Type string `json:"type"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Index       respjson.Field
		ID          respjson.Field
		Function    respjson.Field
		Type        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkChoiceDeltaToolCall) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunkChoiceDeltaToolCall) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

type ChatCompletionChunkChoiceDeltaToolCallFunction struct {
	// The arguments to call the function with, as generated by the model in JSON
	// format. Note that the model does not always generate valid JSON, and may
	// hallucinate parameters not defined by your function schema. Validate the
	// arguments in your code before calling your function.
	Arguments string `json:"arguments"`
	// The name of the function to call.
	Name string `json:"name"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Arguments   respjson.Field
		Name        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkChoiceDeltaToolCallFunction) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunkChoiceDeltaToolCallFunction) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Log probability information for the choice.
type ChatCompletionChunkChoiceLogprobs struct {
	// A list of message content tokens with log probability information.
	Content []ChatCompletionTokenLogprob `json:"content" api:"required"`
	// A list of message refusal tokens with log probability information.
	Refusal []ChatCompletionTokenLogprob `json:"refusal" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Content     respjson.Field
		Refusal     respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkChoiceLogprobs) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunkChoiceLogprobs) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Moderation results for the request input and generated output. Present on the
// moderation chunk when moderated completions are requested.
type ChatCompletionChunkModeration struct {
	// Moderation for the request input.
	Input ChatCompletionChunkModerationInputUnion `json:"input" api:"required"`
	// Moderation for the generated output.
	Output ChatCompletionChunkModerationOutputUnion `json:"output" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Input       respjson.Field
		Output      respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkModeration) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunkModeration) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// ChatCompletionChunkModerationInputUnion contains all possible properties and
// values from [ChatCompletionChunkModerationInputModerationResults],
// [ChatCompletionChunkModerationInputError].
//
// Use the [ChatCompletionChunkModerationInputUnion.AsAny] method to switch on the
// variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type ChatCompletionChunkModerationInputUnion struct {
	// This field is from variant
	// [ChatCompletionChunkModerationInputModerationResults].
	Model string `json:"model"`
	// This field is from variant
	// [ChatCompletionChunkModerationInputModerationResults].
	Results []ChatCompletionChunkModerationInputModerationResultsResult `json:"results"`
	// Any of "moderation_results", "error".
	Type string `json:"type"`
	// This field is from variant [ChatCompletionChunkModerationInputError].
	Code string `json:"code"`
	// This field is from variant [ChatCompletionChunkModerationInputError].
	Message string `json:"message"`
	JSON    struct {
		Model   respjson.Field
		Results respjson.Field
		Type    respjson.Field
		Code    respjson.Field
		Message respjson.Field
		raw     string
	} `json:"-"`
}

// anyChatCompletionChunkModerationInput is implemented by each variant of
// [ChatCompletionChunkModerationInputUnion] to add type safety for the return type
// of [ChatCompletionChunkModerationInputUnion.AsAny]
type anyChatCompletionChunkModerationInput interface {
	implChatCompletionChunkModerationInputUnion()
}

func (ChatCompletionChunkModerationInputModerationResults) implChatCompletionChunkModerationInputUnion() {
}
func (ChatCompletionChunkModerationInputError) implChatCompletionChunkModerationInputUnion() {}

// Use the following switch statement to find the correct variant
//
//	switch variant := ChatCompletionChunkModerationInputUnion.AsAny().(type) {
//	case openai.ChatCompletionChunkModerationInputModerationResults:
//	case openai.ChatCompletionChunkModerationInputError:
//	default:
//	  fmt.Errorf("no variant present")
//	}
func (u ChatCompletionChunkModerationInputUnion) AsAny() anyChatCompletionChunkModerationInput {
	switch u.Type {
	case "moderation_results":
		return u.AsModerationResults()
	case "error":
		return u.AsError()
	}
	return nil
}

func (u ChatCompletionChunkModerationInputUnion) AsModerationResults() (v ChatCompletionChunkModerationInputModerationResults) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

func (u ChatCompletionChunkModerationInputUnion) AsError() (v ChatCompletionChunkModerationInputError) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

// Returns the unmodified JSON received from the API
func (u ChatCompletionChunkModerationInputUnion) RawJSON() string { return u.JSON.raw }

func (r *ChatCompletionChunkModerationInputUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Successful moderation results for the request input or generated output.
type ChatCompletionChunkModerationInputModerationResults struct {
	// The moderation model used to generate the results.
	Model string `json:"model" api:"required"`
	// A list of moderation results.
	Results []ChatCompletionChunkModerationInputModerationResultsResult `json:"results" api:"required"`
	// The object type, which is always `moderation_results`.
	Type constant.ModerationResults `json:"type" default:"moderation_results"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Model       respjson.Field
		Results     respjson.Field
		Type        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkModerationInputModerationResults) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunkModerationInputModerationResults) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A moderation result produced for the response input or output.
type ChatCompletionChunkModerationInputModerationResultsResult struct {
	// A dictionary of moderation categories to booleans, True if the input is flagged
	// under this category.
	Categories map[string]bool `json:"categories" api:"required"`
	// Which modalities of input are reflected by the score for each category.
	CategoryAppliedInputTypes map[string][]string `json:"category_applied_input_types" api:"required"`
	// A dictionary of moderation categories to scores.
	CategoryScores map[string]float64 `json:"category_scores" api:"required"`
	// A boolean indicating whether the content was flagged by any category.
	Flagged bool `json:"flagged" api:"required"`
	// The moderation model that produced this result.
	Model string `json:"model" api:"required"`
	// The object type, which was always `moderation_result` for successful moderation
	// results.
	Type constant.ModerationResult `json:"type" default:"moderation_result"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Categories                respjson.Field
		CategoryAppliedInputTypes respjson.Field
		CategoryScores            respjson.Field
		Flagged                   respjson.Field
		Model                     respjson.Field
		Type                      respjson.Field
		ExtraFields               map[string]respjson.Field
		raw                       string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkModerationInputModerationResultsResult) RawJSON() string {
	return r.JSON.raw
}
func (r *ChatCompletionChunkModerationInputModerationResultsResult) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// An error produced while attempting moderation.
type ChatCompletionChunkModerationInputError struct {
	// The error code.
	Code string `json:"code" api:"required"`
	// The error message.
	Message string `json:"message" api:"required"`
	// The object type, which is always `error`.
	Type constant.Error `json:"type" default:"error"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Message     respjson.Field
		Type        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkModerationInputError) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunkModerationInputError) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// ChatCompletionChunkModerationOutputUnion contains all possible properties and
// values from [ChatCompletionChunkModerationOutputModerationResults],
// [ChatCompletionChunkModerationOutputError].
//
// Use the [ChatCompletionChunkModerationOutputUnion.AsAny] method to switch on the
// variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type ChatCompletionChunkModerationOutputUnion struct {
	// This field is from variant
	// [ChatCompletionChunkModerationOutputModerationResults].
	Model string `json:"model"`
	// This field is from variant
	// [ChatCompletionChunkModerationOutputModerationResults].
	Results []ChatCompletionChunkModerationOutputModerationResultsResult `json:"results"`
	// Any of "moderation_results", "error".
	Type string `json:"type"`
	// This field is from variant [ChatCompletionChunkModerationOutputError].
	Code string `json:"code"`
	// This field is from variant [ChatCompletionChunkModerationOutputError].
	Message string `json:"message"`
	JSON    struct {
		Model   respjson.Field
		Results respjson.Field
		Type    respjson.Field
		Code    respjson.Field
		Message respjson.Field
		raw     string
	} `json:"-"`
}

// anyChatCompletionChunkModerationOutput is implemented by each variant of
// [ChatCompletionChunkModerationOutputUnion] to add type safety for the return
// type of [ChatCompletionChunkModerationOutputUnion.AsAny]
type anyChatCompletionChunkModerationOutput interface {
	implChatCompletionChunkModerationOutputUnion()
}

func (ChatCompletionChunkModerationOutputModerationResults) implChatCompletionChunkModerationOutputUnion() {
}
func (ChatCompletionChunkModerationOutputError) implChatCompletionChunkModerationOutputUnion() {}

// Use the following switch statement to find the correct variant
//
//	switch variant := ChatCompletionChunkModerationOutputUnion.AsAny().(type) {
//	case openai.ChatCompletionChunkModerationOutputModerationResults:
//	case openai.ChatCompletionChunkModerationOutputError:
//	default:
//	  fmt.Errorf("no variant present")
//	}
func (u ChatCompletionChunkModerationOutputUnion) AsAny() anyChatCompletionChunkModerationOutput {
	switch u.Type {
	case "moderation_results":
		return u.AsModerationResults()
	case "error":
		return u.AsError()
	}
	return nil
}

func (u ChatCompletionChunkModerationOutputUnion) AsModerationResults() (v ChatCompletionChunkModerationOutputModerationResults) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

func (u ChatCompletionChunkModerationOutputUnion) AsError() (v ChatCompletionChunkModerationOutputError) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

// Returns the unmodified JSON received from the API
func (u ChatCompletionChunkModerationOutputUnion) RawJSON() string { return u.JSON.raw }

func (r *ChatCompletionChunkModerationOutputUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Successful moderation results for the request input or generated output.
type ChatCompletionChunkModerationOutputModerationResults struct {
	// The moderation model used to generate the results.
	Model string `json:"model" api:"required"`
	// A list of moderation results.
	Results []ChatCompletionChunkModerationOutputModerationResultsResult `json:"results" api:"required"`
	// The object type, which is always `moderation_results`.
	Type constant.ModerationResults `json:"type" default:"moderation_results"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Model       respjson.Field
		Results     respjson.Field
		Type        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkModerationOutputModerationResults) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunkModerationOutputModerationResults) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A moderation result produced for the response input or output.
type ChatCompletionChunkModerationOutputModerationResultsResult struct {
	// A dictionary of moderation categories to booleans, True if the input is flagged
	// under this category.
	Categories map[string]bool `json:"categories" api:"required"`
	// Which modalities of input are reflected by the score for each category.
	CategoryAppliedInputTypes map[string][]string `json:"category_applied_input_types" api:"required"`
	// A dictionary of moderation categories to scores.
	CategoryScores map[string]float64 `json:"category_scores" api:"required"`
	// A boolean indicating whether the content was flagged by any category.
	Flagged bool `json:"flagged" api:"required"`
	// The moderation model that produced this result.
	Model string `json:"model" api:"required"`
	// The object type, which was always `moderation_result` for successful moderation
	// results.
	Type constant.ModerationResult `json:"type" default:"moderation_result"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Categories                respjson.Field
		CategoryAppliedInputTypes respjson.Field
		CategoryScores            respjson.Field
		Flagged                   respjson.Field
		Model                     respjson.Field
		Type                      respjson.Field
		ExtraFields               map[string]respjson.Field
		raw                       string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkModerationOutputModerationResultsResult) RawJSON() string {
	return r.JSON.raw
}
func (r *ChatCompletionChunkModerationOutputModerationResultsResult) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// An error produced while attempting moderation.
type ChatCompletionChunkModerationOutputError struct {
	// The error code.
	Code string `json:"code" api:"required"`
	// The error message.
	Message string `json:"message" api:"required"`
	// The object type, which is always `error`.
	Type constant.Error `json:"type" default:"error"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Code        respjson.Field
		Message     respjson.Field
		Type        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionChunkModerationOutputError) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionChunkModerationOutputError) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Specifies the processing type used for serving the request.
//
//   - If set to 'auto', then the request will be processed with the service tier
//     configured in the Project settings. Unless otherwise configured, the Project
//     will use 'default'.
//   - If set to 'default', then the request will be processed with the standard
//     pricing and performance for the selected model.
//   - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
//     '[priority](https://openai.com/api-priority-processing/)', then the request
//     will be processed with the corresponding service tier.
//   - When not set, the default behavior is 'auto'.
//
// When the `service_tier` parameter is set, the response body will include the
// `service_tier` value based on the processing mode actually used to serve the
// request. This response value may be different from the value set in the
// parameter.
type ChatCompletionChunkServiceTier string

const (
	ChatCompletionChunkServiceTierAuto     ChatCompletionChunkServiceTier = "auto"
	ChatCompletionChunkServiceTierDefault  ChatCompletionChunkServiceTier = "default"
	ChatCompletionChunkServiceTierFlex     ChatCompletionChunkServiceTier = "flex"
	ChatCompletionChunkServiceTierScale    ChatCompletionChunkServiceTier = "scale"
	ChatCompletionChunkServiceTierPriority ChatCompletionChunkServiceTier = "priority"
)

func TextContentPart(text string) ChatCompletionContentPartUnionParam {
	var variant ChatCompletionContentPartTextParam
	variant.Text = text
	return ChatCompletionContentPartUnionParam{OfText: &variant}
}

func ImageContentPart(imageURL ChatCompletionContentPartImageImageURLParam) ChatCompletionContentPartUnionParam {
	var variant ChatCompletionContentPartImageParam
	variant.ImageURL = imageURL
	return ChatCompletionContentPartUnionParam{OfImageURL: &variant}
}

func InputAudioContentPart(inputAudio ChatCompletionContentPartInputAudioInputAudioParam) ChatCompletionContentPartUnionParam {
	var variant ChatCompletionContentPartInputAudioParam
	variant.InputAudio = inputAudio
	return ChatCompletionContentPartUnionParam{OfInputAudio: &variant}
}

func FileContentPart(file ChatCompletionContentPartFileFileParam) ChatCompletionContentPartUnionParam {
	var variant ChatCompletionContentPartFileParam
	variant.File = file
	return ChatCompletionContentPartUnionParam{OfFile: &variant}
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionContentPartUnionParam struct {
	OfText       *ChatCompletionContentPartTextParam       `json:",omitzero,inline"`
	OfImageURL   *ChatCompletionContentPartImageParam      `json:",omitzero,inline"`
	OfInputAudio *ChatCompletionContentPartInputAudioParam `json:",omitzero,inline"`
	OfFile       *ChatCompletionContentPartFileParam       `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionContentPartUnionParam) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfText, u.OfImageURL, u.OfInputAudio, u.OfFile)
}
func (u *ChatCompletionContentPartUnionParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionContentPartUnionParam) asAny() any {
	if !param.IsOmitted(u.OfText) {
		return u.OfText
	} else if !param.IsOmitted(u.OfImageURL) {
		return u.OfImageURL
	} else if !param.IsOmitted(u.OfInputAudio) {
		return u.OfInputAudio
	} else if !param.IsOmitted(u.OfFile) {
		return u.OfFile
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionContentPartUnionParam) GetText() *string {
	if vt := u.OfText; vt != nil {
		return &vt.Text
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionContentPartUnionParam) GetImageURL() *ChatCompletionContentPartImageImageURLParam {
	if vt := u.OfImageURL; vt != nil {
		return &vt.ImageURL
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionContentPartUnionParam) GetInputAudio() *ChatCompletionContentPartInputAudioInputAudioParam {
	if vt := u.OfInputAudio; vt != nil {
		return &vt.InputAudio
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionContentPartUnionParam) GetFile() *ChatCompletionContentPartFileFileParam {
	if vt := u.OfFile; vt != nil {
		return &vt.File
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionContentPartUnionParam) GetType() *string {
	if vt := u.OfText; vt != nil {
		return (*string)(&vt.Type)
	} else if vt := u.OfImageURL; vt != nil {
		return (*string)(&vt.Type)
	} else if vt := u.OfInputAudio; vt != nil {
		return (*string)(&vt.Type)
	} else if vt := u.OfFile; vt != nil {
		return (*string)(&vt.Type)
	}
	return nil
}

// Returns a subunion which exports methods to access subproperties
//
// Or use AsAny() to get the underlying value
func (u ChatCompletionContentPartUnionParam) GetPromptCacheBreakpoint() (res chatCompletionContentPartUnionParamPromptCacheBreakpoint) {
	if vt := u.OfText; vt != nil {
		res.any = &vt.PromptCacheBreakpoint
	} else if vt := u.OfImageURL; vt != nil {
		res.any = &vt.PromptCacheBreakpoint
	} else if vt := u.OfInputAudio; vt != nil {
		res.any = &vt.PromptCacheBreakpoint
	} else if vt := u.OfFile; vt != nil {
		res.any = &vt.PromptCacheBreakpoint
	}
	return
}

// Can have the runtime types
// [*ChatCompletionContentPartTextPromptCacheBreakpointParam],
// [*ChatCompletionContentPartImagePromptCacheBreakpointParam],
// [*ChatCompletionContentPartInputAudioPromptCacheBreakpointParam],
// [*ChatCompletionContentPartFilePromptCacheBreakpointParam]
type chatCompletionContentPartUnionParamPromptCacheBreakpoint struct{ any }

// Use the following switch statement to get the type of the union:
//
//	switch u.AsAny().(type) {
//	case *openai.ChatCompletionContentPartTextPromptCacheBreakpointParam:
//	case *openai.ChatCompletionContentPartImagePromptCacheBreakpointParam:
//	case *openai.ChatCompletionContentPartInputAudioPromptCacheBreakpointParam:
//	case *openai.ChatCompletionContentPartFilePromptCacheBreakpointParam:
//	default:
//	    fmt.Errorf("not present")
//	}
func (u chatCompletionContentPartUnionParamPromptCacheBreakpoint) AsAny() any { return u.any }

// Returns a pointer to the underlying variant's property, if present.
func (u chatCompletionContentPartUnionParamPromptCacheBreakpoint) GetMode() *string {
	switch vt := u.any.(type) {
	case *ChatCompletionContentPartTextPromptCacheBreakpointParam:
		return (*string)(&vt.Mode)
	case *ChatCompletionContentPartImagePromptCacheBreakpointParam:
		return (*string)(&vt.Mode)
	case *ChatCompletionContentPartInputAudioPromptCacheBreakpointParam:
		return (*string)(&vt.Mode)
	case *ChatCompletionContentPartFilePromptCacheBreakpointParam:
		return (*string)(&vt.Mode)
	}
	return nil
}

func init() {
	apijson.RegisterUnion[ChatCompletionContentPartUnionParam](
		"type",
		apijson.Discriminator[ChatCompletionContentPartTextParam]("text"),
		apijson.Discriminator[ChatCompletionContentPartImageParam]("image_url"),
		apijson.Discriminator[ChatCompletionContentPartInputAudioParam]("input_audio"),
		apijson.Discriminator[ChatCompletionContentPartFileParam]("file"),
	)
}

// Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text
// generation.
//
// The properties File, Type are required.
type ChatCompletionContentPartFileParam struct {
	File ChatCompletionContentPartFileFileParam `json:"file,omitzero" api:"required"`
	// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
	// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
	// token block.
	PromptCacheBreakpoint ChatCompletionContentPartFilePromptCacheBreakpointParam `json:"prompt_cache_breakpoint,omitzero"`
	// The type of the content part. Always `file`.
	//
	// This field can be elided, and will marshal its zero value as "file".
	Type constant.File `json:"type" default:"file"`
	paramObj
}

func (r ChatCompletionContentPartFileParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartFileParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartFileParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

type ChatCompletionContentPartFileFileParam struct {
	// The base64 encoded file data, used when passing the file to the model as a
	// string.
	FileData param.Opt[string] `json:"file_data,omitzero"`
	// The ID of an uploaded file to use as input.
	FileID param.Opt[string] `json:"file_id,omitzero"`
	// The name of the file, used when passing the file to the model as a string.
	Filename param.Opt[string] `json:"filename,omitzero"`
	paramObj
}

func (r ChatCompletionContentPartFileFileParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartFileFileParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartFileFileParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func NewChatCompletionContentPartFilePromptCacheBreakpointParam() ChatCompletionContentPartFilePromptCacheBreakpointParam {
	return ChatCompletionContentPartFilePromptCacheBreakpointParam{
		Mode: "explicit",
	}
}

// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
// token block.
//
// This struct has a constant value, construct it with
// [NewChatCompletionContentPartFilePromptCacheBreakpointParam].
type ChatCompletionContentPartFilePromptCacheBreakpointParam struct {
	// The breakpoint mode. Always `explicit`.
	Mode constant.Explicit `json:"mode" default:"explicit"`
	paramObj
}

func (r ChatCompletionContentPartFilePromptCacheBreakpointParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartFilePromptCacheBreakpointParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartFilePromptCacheBreakpointParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
type ChatCompletionContentPartImage struct {
	ImageURL ChatCompletionContentPartImageImageURL `json:"image_url" api:"required"`
	// The type of the content part.
	Type constant.ImageURL `json:"type" default:"image_url"`
	// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
	// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
	// token block.
	PromptCacheBreakpoint ChatCompletionContentPartImagePromptCacheBreakpoint `json:"prompt_cache_breakpoint"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		ImageURL              respjson.Field
		Type                  respjson.Field
		PromptCacheBreakpoint respjson.Field
		ExtraFields           map[string]respjson.Field
		raw                   string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionContentPartImage) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionContentPartImage) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// ToParam converts this ChatCompletionContentPartImage to a
// ChatCompletionContentPartImageParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// ChatCompletionContentPartImageParam.Overrides()
func (r ChatCompletionContentPartImage) ToParam() ChatCompletionContentPartImageParam {
	return param.Override[ChatCompletionContentPartImageParam](json.RawMessage(r.RawJSON()))
}

type ChatCompletionContentPartImageImageURL struct {
	// Either a URL of the image or the base64 encoded image data.
	URL string `json:"url" api:"required" format:"uri"`
	// Specifies the detail level of the image. Learn more in the
	// [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
	//
	// Any of "auto", "low", "high".
	Detail string `json:"detail"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		URL         respjson.Field
		Detail      respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionContentPartImageImageURL) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionContentPartImageImageURL) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
// token block.
type ChatCompletionContentPartImagePromptCacheBreakpoint struct {
	// The breakpoint mode. Always `explicit`.
	Mode constant.Explicit `json:"mode" default:"explicit"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Mode        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionContentPartImagePromptCacheBreakpoint) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionContentPartImagePromptCacheBreakpoint) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
//
// The properties ImageURL, Type are required.
type ChatCompletionContentPartImageParam struct {
	ImageURL ChatCompletionContentPartImageImageURLParam `json:"image_url,omitzero" api:"required"`
	// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
	// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
	// token block.
	PromptCacheBreakpoint ChatCompletionContentPartImagePromptCacheBreakpointParam `json:"prompt_cache_breakpoint,omitzero"`
	// The type of the content part.
	//
	// This field can be elided, and will marshal its zero value as "image_url".
	Type constant.ImageURL `json:"type" default:"image_url"`
	paramObj
}

func (r ChatCompletionContentPartImageParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartImageParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartImageParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// The property URL is required.
type ChatCompletionContentPartImageImageURLParam struct {
	// Either a URL of the image or the base64 encoded image data.
	URL string `json:"url" api:"required" format:"uri"`
	// Specifies the detail level of the image. Learn more in the
	// [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
	//
	// Any of "auto", "low", "high".
	Detail string `json:"detail,omitzero"`
	paramObj
}

func (r ChatCompletionContentPartImageImageURLParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartImageImageURLParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartImageImageURLParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func init() {
	apijson.RegisterFieldValidator[ChatCompletionContentPartImageImageURLParam](
		"detail", "auto", "low", "high",
	)
}

func NewChatCompletionContentPartImagePromptCacheBreakpointParam() ChatCompletionContentPartImagePromptCacheBreakpointParam {
	return ChatCompletionContentPartImagePromptCacheBreakpointParam{
		Mode: "explicit",
	}
}

// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
// token block.
//
// This struct has a constant value, construct it with
// [NewChatCompletionContentPartImagePromptCacheBreakpointParam].
type ChatCompletionContentPartImagePromptCacheBreakpointParam struct {
	// The breakpoint mode. Always `explicit`.
	Mode constant.Explicit `json:"mode" default:"explicit"`
	paramObj
}

func (r ChatCompletionContentPartImagePromptCacheBreakpointParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartImagePromptCacheBreakpointParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartImagePromptCacheBreakpointParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
//
// The properties InputAudio, Type are required.
type ChatCompletionContentPartInputAudioParam struct {
	InputAudio ChatCompletionContentPartInputAudioInputAudioParam `json:"input_audio,omitzero" api:"required"`
	// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
	// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
	// token block.
	PromptCacheBreakpoint ChatCompletionContentPartInputAudioPromptCacheBreakpointParam `json:"prompt_cache_breakpoint,omitzero"`
	// The type of the content part. Always `input_audio`.
	//
	// This field can be elided, and will marshal its zero value as "input_audio".
	Type constant.InputAudio `json:"type" default:"input_audio"`
	paramObj
}

func (r ChatCompletionContentPartInputAudioParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartInputAudioParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartInputAudioParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// The properties Data, Format are required.
type ChatCompletionContentPartInputAudioInputAudioParam struct {
	// Base64 encoded audio data.
	Data string `json:"data" api:"required"`
	// The format of the encoded audio data. Currently supports "wav" and "mp3".
	//
	// Any of "wav", "mp3".
	Format string `json:"format,omitzero" api:"required"`
	paramObj
}

func (r ChatCompletionContentPartInputAudioInputAudioParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartInputAudioInputAudioParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartInputAudioInputAudioParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func init() {
	apijson.RegisterFieldValidator[ChatCompletionContentPartInputAudioInputAudioParam](
		"format", "wav", "mp3",
	)
}

func NewChatCompletionContentPartInputAudioPromptCacheBreakpointParam() ChatCompletionContentPartInputAudioPromptCacheBreakpointParam {
	return ChatCompletionContentPartInputAudioPromptCacheBreakpointParam{
		Mode: "explicit",
	}
}

// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
// token block.
//
// This struct has a constant value, construct it with
// [NewChatCompletionContentPartInputAudioPromptCacheBreakpointParam].
type ChatCompletionContentPartInputAudioPromptCacheBreakpointParam struct {
	// The breakpoint mode. Always `explicit`.
	Mode constant.Explicit `json:"mode" default:"explicit"`
	paramObj
}

func (r ChatCompletionContentPartInputAudioPromptCacheBreakpointParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartInputAudioPromptCacheBreakpointParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartInputAudioPromptCacheBreakpointParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// The properties Refusal, Type are required.
type ChatCompletionContentPartRefusalParam struct {
	// The refusal message generated by the model.
	Refusal string `json:"refusal" api:"required"`
	// The type of the content part.
	//
	// This field can be elided, and will marshal its zero value as "refusal".
	Type constant.Refusal `json:"type" default:"refusal"`
	paramObj
}

func (r ChatCompletionContentPartRefusalParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartRefusalParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartRefusalParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Learn about
// [text inputs](https://platform.openai.com/docs/guides/text-generation).
type ChatCompletionContentPartText struct {
	// The text content.
	Text string `json:"text" api:"required"`
	// The type of the content part.
	Type constant.Text `json:"type" default:"text"`
	// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
	// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
	// token block.
	PromptCacheBreakpoint ChatCompletionContentPartTextPromptCacheBreakpoint `json:"prompt_cache_breakpoint"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Text                  respjson.Field
		Type                  respjson.Field
		PromptCacheBreakpoint respjson.Field
		ExtraFields           map[string]respjson.Field
		raw                   string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionContentPartText) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionContentPartText) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// ToParam converts this ChatCompletionContentPartText to a
// ChatCompletionContentPartTextParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// ChatCompletionContentPartTextParam.Overrides()
func (r ChatCompletionContentPartText) ToParam() ChatCompletionContentPartTextParam {
	return param.Override[ChatCompletionContentPartTextParam](json.RawMessage(r.RawJSON()))
}

// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
// token block.
type ChatCompletionContentPartTextPromptCacheBreakpoint struct {
	// The breakpoint mode. Always `explicit`.
	Mode constant.Explicit `json:"mode" default:"explicit"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Mode        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionContentPartTextPromptCacheBreakpoint) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionContentPartTextPromptCacheBreakpoint) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Learn about
// [text inputs](https://platform.openai.com/docs/guides/text-generation).
//
// The properties Text, Type are required.
type ChatCompletionContentPartTextParam struct {
	// The text content.
	Text string `json:"text" api:"required"`
	// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
	// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
	// token block.
	PromptCacheBreakpoint ChatCompletionContentPartTextPromptCacheBreakpointParam `json:"prompt_cache_breakpoint,omitzero"`
	// The type of the content part.
	//
	// This field can be elided, and will marshal its zero value as "text".
	Type constant.Text `json:"type" default:"text"`
	paramObj
}

func (r ChatCompletionContentPartTextParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartTextParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartTextParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func NewChatCompletionContentPartTextPromptCacheBreakpointParam() ChatCompletionContentPartTextPromptCacheBreakpointParam {
	return ChatCompletionContentPartTextPromptCacheBreakpointParam{
		Mode: "explicit",
	}
}

// Marks the exact end of a reusable prompt prefix. The breakpoint inherits its TTL
// from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a
// token block.
//
// This struct has a constant value, construct it with
// [NewChatCompletionContentPartTextPromptCacheBreakpointParam].
type ChatCompletionContentPartTextPromptCacheBreakpointParam struct {
	// The breakpoint mode. Always `explicit`.
	Mode constant.Explicit `json:"mode" default:"explicit"`
	paramObj
}

func (r ChatCompletionContentPartTextPromptCacheBreakpointParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionContentPartTextPromptCacheBreakpointParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionContentPartTextPromptCacheBreakpointParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A custom tool that processes input using a specified format.
//
// The properties Custom, Type are required.
type ChatCompletionCustomToolParam struct {
	// Properties of the custom tool.
	Custom ChatCompletionCustomToolCustomParam `json:"custom,omitzero" api:"required"`
	// The type of the custom tool. Always `custom`.
	//
	// This field can be elided, and will marshal its zero value as "custom".
	Type constant.Custom `json:"type" default:"custom"`
	paramObj
}

func (r ChatCompletionCustomToolParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionCustomToolParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionCustomToolParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Properties of the custom tool.
//
// The property Name is required.
type ChatCompletionCustomToolCustomParam struct {
	// The name of the custom tool, used to identify it in tool calls.
	Name string `json:"name" api:"required"`
	// Optional description of the custom tool, used to provide more context.
	Description param.Opt[string] `json:"description,omitzero"`
	// The input format for the custom tool. Default is unconstrained text.
	Format ChatCompletionCustomToolCustomFormatUnionParam `json:"format,omitzero"`
	paramObj
}

func (r ChatCompletionCustomToolCustomParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionCustomToolCustomParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionCustomToolCustomParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionCustomToolCustomFormatUnionParam struct {
	OfText    *ChatCompletionCustomToolCustomFormatTextParam    `json:",omitzero,inline"`
	OfGrammar *ChatCompletionCustomToolCustomFormatGrammarParam `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionCustomToolCustomFormatUnionParam) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfText, u.OfGrammar)
}
func (u *ChatCompletionCustomToolCustomFormatUnionParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionCustomToolCustomFormatUnionParam) asAny() any {
	if !param.IsOmitted(u.OfText) {
		return u.OfText
	} else if !param.IsOmitted(u.OfGrammar) {
		return u.OfGrammar
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionCustomToolCustomFormatUnionParam) GetGrammar() *ChatCompletionCustomToolCustomFormatGrammarGrammarParam {
	if vt := u.OfGrammar; vt != nil {
		return &vt.Grammar
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionCustomToolCustomFormatUnionParam) GetType() *string {
	if vt := u.OfText; vt != nil {
		return (*string)(&vt.Type)
	} else if vt := u.OfGrammar; vt != nil {
		return (*string)(&vt.Type)
	}
	return nil
}

func init() {
	apijson.RegisterUnion[ChatCompletionCustomToolCustomFormatUnionParam](
		"type",
		apijson.Discriminator[ChatCompletionCustomToolCustomFormatTextParam]("text"),
		apijson.Discriminator[ChatCompletionCustomToolCustomFormatGrammarParam]("grammar"),
	)
}

func NewChatCompletionCustomToolCustomFormatTextParam() ChatCompletionCustomToolCustomFormatTextParam {
	return ChatCompletionCustomToolCustomFormatTextParam{
		Type: "text",
	}
}

// Unconstrained free-form text.
//
// This struct has a constant value, construct it with
// [NewChatCompletionCustomToolCustomFormatTextParam].
type ChatCompletionCustomToolCustomFormatTextParam struct {
	// Unconstrained text format. Always `text`.
	Type constant.Text `json:"type" default:"text"`
	paramObj
}

func (r ChatCompletionCustomToolCustomFormatTextParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionCustomToolCustomFormatTextParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionCustomToolCustomFormatTextParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A grammar defined by the user.
//
// The properties Grammar, Type are required.
type ChatCompletionCustomToolCustomFormatGrammarParam struct {
	// Your chosen grammar.
	Grammar ChatCompletionCustomToolCustomFormatGrammarGrammarParam `json:"grammar,omitzero" api:"required"`
	// Grammar format. Always `grammar`.
	//
	// This field can be elided, and will marshal its zero value as "grammar".
	Type constant.Grammar `json:"type" default:"grammar"`
	paramObj
}

func (r ChatCompletionCustomToolCustomFormatGrammarParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionCustomToolCustomFormatGrammarParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionCustomToolCustomFormatGrammarParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Your chosen grammar.
//
// The properties Definition, Syntax are required.
type ChatCompletionCustomToolCustomFormatGrammarGrammarParam struct {
	// The grammar definition.
	Definition string `json:"definition" api:"required"`
	// The syntax of the grammar definition. One of `lark` or `regex`.
	//
	// Any of "lark", "regex".
	Syntax string `json:"syntax,omitzero" api:"required"`
	paramObj
}

func (r ChatCompletionCustomToolCustomFormatGrammarGrammarParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionCustomToolCustomFormatGrammarGrammarParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionCustomToolCustomFormatGrammarGrammarParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func init() {
	apijson.RegisterFieldValidator[ChatCompletionCustomToolCustomFormatGrammarGrammarParam](
		"syntax", "lark", "regex",
	)
}

type ChatCompletionDeleted struct {
	// The ID of the chat completion that was deleted.
	ID string `json:"id" api:"required"`
	// Whether the chat completion was deleted.
	Deleted bool `json:"deleted" api:"required"`
	// The type of object being deleted.
	Object constant.ChatCompletionDeleted `json:"object" default:"chat.completion.deleted"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		ID          respjson.Field
		Deleted     respjson.Field
		Object      respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionDeleted) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionDeleted) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Developer-provided instructions that the model should follow, regardless of
// messages sent by the user. With o1 models and newer, `developer` messages
// replace the previous `system` messages.
//
// The properties Content, Role are required.
type ChatCompletionDeveloperMessageParam struct {
	// The contents of the developer message.
	Content ChatCompletionDeveloperMessageParamContentUnion `json:"content,omitzero" api:"required"`
	// An optional name for the participant. Provides the model information to
	// differentiate between participants of the same role.
	Name param.Opt[string] `json:"name,omitzero"`
	// The role of the messages author, in this case `developer`.
	//
	// This field can be elided, and will marshal its zero value as "developer".
	Role constant.Developer `json:"role" default:"developer"`
	paramObj
}

func (r ChatCompletionDeveloperMessageParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionDeveloperMessageParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionDeveloperMessageParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionDeveloperMessageParamContentUnion struct {
	OfString              param.Opt[string]                    `json:",omitzero,inline"`
	OfArrayOfContentParts []ChatCompletionContentPartTextParam `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionDeveloperMessageParamContentUnion) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
}
func (u *ChatCompletionDeveloperMessageParamContentUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionDeveloperMessageParamContentUnion) asAny() any {
	if !param.IsOmitted(u.OfString) {
		return &u.OfString.Value
	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
		return &u.OfArrayOfContentParts
	}
	return nil
}

// Specifying a particular function via `{"name": "my_function"}` forces the model
// to call that function.
//
// The property Name is required.
type ChatCompletionFunctionCallOptionParam struct {
	// The name of the function to call.
	Name string `json:"name" api:"required"`
	paramObj
}

func (r ChatCompletionFunctionCallOptionParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionFunctionCallOptionParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionFunctionCallOptionParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Deprecated: deprecated
//
// The properties Content, Name, Role are required.
type ChatCompletionFunctionMessageParam struct {
	// The contents of the function message.
	Content param.Opt[string] `json:"content,omitzero" api:"required"`
	// The name of the function to call.
	Name string `json:"name" api:"required"`
	// The role of the messages author, in this case `function`.
	//
	// This field can be elided, and will marshal its zero value as "function".
	Role constant.Function `json:"role" default:"function"`
	paramObj
}

func (r ChatCompletionFunctionMessageParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionFunctionMessageParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionFunctionMessageParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A function tool that can be used to generate a response.
//
// The properties Function, Type are required.
type ChatCompletionFunctionToolParam struct {
	Function shared.FunctionDefinitionParam `json:"function,omitzero" api:"required"`
	// The type of the tool. Currently, only `function` is supported.
	//
	// This field can be elided, and will marshal its zero value as "function".
	Type constant.Function `json:"type" default:"function"`
	paramObj
}

func (r ChatCompletionFunctionToolParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionFunctionToolParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionFunctionToolParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A chat completion message generated by the model.
type ChatCompletionMessage struct {
	// The contents of the message.
	Content string `json:"content" api:"required"`
	// The refusal message generated by the model.
	Refusal string `json:"refusal" api:"required"`
	// The role of the author of this message.
	Role constant.Assistant `json:"role" default:"assistant"`
	// Annotations for the message, when applicable, as when using the
	// [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
	Annotations []ChatCompletionMessageAnnotation `json:"annotations"`
	// If the audio output modality is requested, this object contains data about the
	// audio response from the model.
	// [Learn more](https://platform.openai.com/docs/guides/audio).
	Audio ChatCompletionAudio `json:"audio" api:"nullable"`
	// Deprecated and replaced by `tool_calls`. The name and arguments of a function
	// that should be called, as generated by the model.
	//
	// Deprecated: deprecated
	FunctionCall ChatCompletionMessageFunctionCall `json:"function_call"`
	// The tool calls generated by the model, such as function calls.
	ToolCalls []ChatCompletionMessageToolCallUnion `json:"tool_calls"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Content      respjson.Field
		Refusal      respjson.Field
		Role         respjson.Field
		Annotations  respjson.Field
		Audio        respjson.Field
		FunctionCall respjson.Field
		ToolCalls    respjson.Field
		ExtraFields  map[string]respjson.Field
		raw          string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionMessage) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionMessage) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func (r ChatCompletionMessage) ToParam() ChatCompletionMessageParamUnion {
	asst := r.ToAssistantMessageParam()
	return ChatCompletionMessageParamUnion{OfAssistant: &asst}
}

func (r ChatCompletionMessage) ToAssistantMessageParam() ChatCompletionAssistantMessageParam {
	var p ChatCompletionAssistantMessageParam

	// It is important to not rely on the JSON metadata property
	// here, it may be unset if the receiver was generated via a
	// [ChatCompletionAccumulator].
	//
	// Explicit null is intentionally elided from the response.
	if r.Content != "" {
		p.Content.OfString = String(r.Content)
	}
	if r.Refusal != "" {
		p.Refusal = String(r.Refusal)
	}

	p.Audio.ID = r.Audio.ID
	p.Role = r.Role
	p.FunctionCall.Arguments = r.FunctionCall.Arguments
	p.FunctionCall.Name = r.FunctionCall.Name

	if len(r.ToolCalls) > 0 {
		for _, v := range r.ToolCalls {
			u := ChatCompletionMessageToolCallUnionParam{}
			switch v.AsAny().(type) {
			case ChatCompletionMessageFunctionToolCall:
				u.OfFunction = &ChatCompletionMessageFunctionToolCallParam{
					ID: v.ID,
					Function: ChatCompletionMessageFunctionToolCallFunctionParam{
						Arguments: v.Function.Arguments,
						Name:      v.Function.Name,
					},
				}
			case ChatCompletionMessageCustomToolCall:
				u.OfCustom = &ChatCompletionMessageCustomToolCallParam{
					ID: v.ID,
					Custom: ChatCompletionMessageCustomToolCallCustomParam{
						Input: v.Custom.Input,
						Name:  v.Custom.Name,
					},
				}
			}

			p.ToolCalls = append(p.ToolCalls, u)
		}
	}
	return p
}

// A URL citation when using web search.
type ChatCompletionMessageAnnotation struct {
	// The type of the URL citation. Always `url_citation`.
	Type constant.URLCitation `json:"type" default:"url_citation"`
	// A URL citation when using web search.
	URLCitation ChatCompletionMessageAnnotationURLCitation `json:"url_citation" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Type        respjson.Field
		URLCitation respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionMessageAnnotation) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionMessageAnnotation) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A URL citation when using web search.
type ChatCompletionMessageAnnotationURLCitation struct {
	// The index of the last character of the URL citation in the message.
	EndIndex int64 `json:"end_index" api:"required"`
	// The index of the first character of the URL citation in the message.
	StartIndex int64 `json:"start_index" api:"required"`
	// The title of the web resource.
	Title string `json:"title" api:"required"`
	// The URL of the web resource.
	URL string `json:"url" api:"required" format:"uri"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		EndIndex    respjson.Field
		StartIndex  respjson.Field
		Title       respjson.Field
		URL         respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionMessageAnnotationURLCitation) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionMessageAnnotationURLCitation) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Deprecated and replaced by `tool_calls`. The name and arguments of a function
// that should be called, as generated by the model.
//
// Deprecated: deprecated
type ChatCompletionMessageFunctionCall struct {
	// The arguments to call the function with, as generated by the model in JSON
	// format. Note that the model does not always generate valid JSON, and may
	// hallucinate parameters not defined by your function schema. Validate the
	// arguments in your code before calling your function.
	Arguments string `json:"arguments" api:"required"`
	// The name of the function to call.
	Name string `json:"name" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Arguments   respjson.Field
		Name        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionMessageFunctionCall) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionMessageFunctionCall) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A call to a custom tool created by the model.
type ChatCompletionMessageCustomToolCall struct {
	// The ID of the tool call.
	ID string `json:"id" api:"required"`
	// The custom tool that the model called.
	Custom ChatCompletionMessageCustomToolCallCustom `json:"custom" api:"required"`
	// The type of the tool. Always `custom`.
	Type constant.Custom `json:"type" default:"custom"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		ID          respjson.Field
		Custom      respjson.Field
		Type        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionMessageCustomToolCall) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionMessageCustomToolCall) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// ToParam converts this ChatCompletionMessageCustomToolCall to a
// ChatCompletionMessageCustomToolCallParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// ChatCompletionMessageCustomToolCallParam.Overrides()
func (r ChatCompletionMessageCustomToolCall) ToParam() ChatCompletionMessageCustomToolCallParam {
	return param.Override[ChatCompletionMessageCustomToolCallParam](json.RawMessage(r.RawJSON()))
}

// The custom tool that the model called.
type ChatCompletionMessageCustomToolCallCustom struct {
	// The input for the custom tool call generated by the model.
	Input string `json:"input" api:"required"`
	// The name of the custom tool to call.
	Name string `json:"name" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Input       respjson.Field
		Name        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionMessageCustomToolCallCustom) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionMessageCustomToolCallCustom) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A call to a custom tool created by the model.
//
// The properties ID, Custom, Type are required.
type ChatCompletionMessageCustomToolCallParam struct {
	// The ID of the tool call.
	ID string `json:"id" api:"required"`
	// The custom tool that the model called.
	Custom ChatCompletionMessageCustomToolCallCustomParam `json:"custom,omitzero" api:"required"`
	// The type of the tool. Always `custom`.
	//
	// This field can be elided, and will marshal its zero value as "custom".
	Type constant.Custom `json:"type" default:"custom"`
	paramObj
}

func (r ChatCompletionMessageCustomToolCallParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionMessageCustomToolCallParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionMessageCustomToolCallParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// The custom tool that the model called.
//
// The properties Input, Name are required.
type ChatCompletionMessageCustomToolCallCustomParam struct {
	// The input for the custom tool call generated by the model.
	Input string `json:"input" api:"required"`
	// The name of the custom tool to call.
	Name string `json:"name" api:"required"`
	paramObj
}

func (r ChatCompletionMessageCustomToolCallCustomParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionMessageCustomToolCallCustomParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionMessageCustomToolCallCustomParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A call to a function tool created by the model.
type ChatCompletionMessageFunctionToolCall struct {
	// The ID of the tool call.
	ID string `json:"id" api:"required"`
	// The function that the model called.
	Function ChatCompletionMessageFunctionToolCallFunction `json:"function" api:"required"`
	// The type of the tool. Currently, only `function` is supported.
	Type constant.Function `json:"type" default:"function"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		ID          respjson.Field
		Function    respjson.Field
		Type        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionMessageFunctionToolCall) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionMessageFunctionToolCall) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// ToParam converts this ChatCompletionMessageFunctionToolCall to a
// ChatCompletionMessageFunctionToolCallParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// ChatCompletionMessageFunctionToolCallParam.Overrides()
func (r ChatCompletionMessageFunctionToolCall) ToParam() ChatCompletionMessageFunctionToolCallParam {
	return param.Override[ChatCompletionMessageFunctionToolCallParam](json.RawMessage(r.RawJSON()))
}

// The function that the model called.
type ChatCompletionMessageFunctionToolCallFunction struct {
	// The arguments to call the function with, as generated by the model in JSON
	// format. Note that the model does not always generate valid JSON, and may
	// hallucinate parameters not defined by your function schema. Validate the
	// arguments in your code before calling your function.
	Arguments string `json:"arguments" api:"required"`
	// The name of the function to call.
	Name string `json:"name" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Arguments   respjson.Field
		Name        respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionMessageFunctionToolCallFunction) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionMessageFunctionToolCallFunction) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// A call to a function tool created by the model.
//
// The properties ID, Function, Type are required.
type ChatCompletionMessageFunctionToolCallParam struct {
	// The ID of the tool call.
	ID string `json:"id" api:"required"`
	// The function that the model called.
	Function ChatCompletionMessageFunctionToolCallFunctionParam `json:"function,omitzero" api:"required"`
	// The type of the tool. Currently, only `function` is supported.
	//
	// This field can be elided, and will marshal its zero value as "function".
	Type constant.Function `json:"type" default:"function"`
	paramObj
}

func (r ChatCompletionMessageFunctionToolCallParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionMessageFunctionToolCallParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionMessageFunctionToolCallParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// The function that the model called.
//
// The properties Arguments, Name are required.
type ChatCompletionMessageFunctionToolCallFunctionParam struct {
	// The arguments to call the function with, as generated by the model in JSON
	// format. Note that the model does not always generate valid JSON, and may
	// hallucinate parameters not defined by your function schema. Validate the
	// arguments in your code before calling your function.
	Arguments string `json:"arguments" api:"required"`
	// The name of the function to call.
	Name string `json:"name" api:"required"`
	paramObj
}

func (r ChatCompletionMessageFunctionToolCallFunctionParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionMessageFunctionToolCallFunctionParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionMessageFunctionToolCallFunctionParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func AssistantMessage[T string | []ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion](content T) ChatCompletionMessageParamUnion {
	var assistant ChatCompletionAssistantMessageParam
	switch v := any(content).(type) {
	case string:
		assistant.Content.OfString = param.NewOpt(v)
	case []ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion:
		assistant.Content.OfArrayOfContentParts = v
	}
	return ChatCompletionMessageParamUnion{OfAssistant: &assistant}
}

func DeveloperMessage[T string | []ChatCompletionContentPartTextParam](content T) ChatCompletionMessageParamUnion {
	var developer ChatCompletionDeveloperMessageParam
	switch v := any(content).(type) {
	case string:
		developer.Content.OfString = param.NewOpt(v)
	case []ChatCompletionContentPartTextParam:
		developer.Content.OfArrayOfContentParts = v
	}
	return ChatCompletionMessageParamUnion{OfDeveloper: &developer}
}

func SystemMessage[T string | []ChatCompletionContentPartTextParam](content T) ChatCompletionMessageParamUnion {
	var system ChatCompletionSystemMessageParam
	switch v := any(content).(type) {
	case string:
		system.Content.OfString = param.NewOpt(v)
	case []ChatCompletionContentPartTextParam:
		system.Content.OfArrayOfContentParts = v
	}
	return ChatCompletionMessageParamUnion{OfSystem: &system}
}

func UserMessage[T string | []ChatCompletionContentPartUnionParam](content T) ChatCompletionMessageParamUnion {
	var user ChatCompletionUserMessageParam
	switch v := any(content).(type) {
	case string:
		user.Content.OfString = param.NewOpt(v)
	case []ChatCompletionContentPartUnionParam:
		user.Content.OfArrayOfContentParts = v
	}
	return ChatCompletionMessageParamUnion{OfUser: &user}
}

func ChatCompletionMessageParamOfAssistant[
	T string | []ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion,
](content T) ChatCompletionMessageParamUnion {
	var assistant ChatCompletionAssistantMessageParam
	switch v := any(content).(type) {
	case string:
		assistant.Content.OfString = param.NewOpt(v)
	case []ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion:
		assistant.Content.OfArrayOfContentParts = v
	}
	return ChatCompletionMessageParamUnion{OfAssistant: &assistant}
}

func ToolMessage[T string | []ChatCompletionContentPartTextParam](content T, toolCallID string) ChatCompletionMessageParamUnion {
	var tool ChatCompletionToolMessageParam
	switch v := any(content).(type) {
	case string:
		tool.Content.OfString = param.NewOpt(v)
	case []ChatCompletionContentPartTextParam:
		tool.Content.OfArrayOfContentParts = v
	}
	tool.ToolCallID = toolCallID
	return ChatCompletionMessageParamUnion{OfTool: &tool}
}

func ChatCompletionMessageParamOfFunction(content string, name string) ChatCompletionMessageParamUnion {
	var function ChatCompletionFunctionMessageParam
	function.Content = param.NewOpt(content)
	function.Name = name
	return ChatCompletionMessageParamUnion{OfFunction: &function}
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionMessageParamUnion struct {
	OfDeveloper *ChatCompletionDeveloperMessageParam `json:",omitzero,inline"`
	OfSystem    *ChatCompletionSystemMessageParam    `json:",omitzero,inline"`
	OfUser      *ChatCompletionUserMessageParam      `json:",omitzero,inline"`
	OfAssistant *ChatCompletionAssistantMessageParam `json:",omitzero,inline"`
	OfTool      *ChatCompletionToolMessageParam      `json:",omitzero,inline"`
	OfFunction  *ChatCompletionFunctionMessageParam  `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionMessageParamUnion) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfDeveloper,
		u.OfSystem,
		u.OfUser,
		u.OfAssistant,
		u.OfTool,
		u.OfFunction)
}
func (u *ChatCompletionMessageParamUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionMessageParamUnion) asAny() any {
	if !param.IsOmitted(u.OfDeveloper) {
		return u.OfDeveloper
	} else if !param.IsOmitted(u.OfSystem) {
		return u.OfSystem
	} else if !param.IsOmitted(u.OfUser) {
		return u.OfUser
	} else if !param.IsOmitted(u.OfAssistant) {
		return u.OfAssistant
	} else if !param.IsOmitted(u.OfTool) {
		return u.OfTool
	} else if !param.IsOmitted(u.OfFunction) {
		return u.OfFunction
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionMessageParamUnion) GetAudio() *ChatCompletionAssistantMessageParamAudio {
	if vt := u.OfAssistant; vt != nil {
		return &vt.Audio
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionMessageParamUnion) GetFunctionCall() *ChatCompletionAssistantMessageParamFunctionCall {
	if vt := u.OfAssistant; vt != nil {
		return &vt.FunctionCall
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionMessageParamUnion) GetRefusal() *string {
	if vt := u.OfAssistant; vt != nil && vt.Refusal.Valid() {
		return &vt.Refusal.Value
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionMessageParamUnion) GetToolCalls() []ChatCompletionMessageToolCallUnionParam {
	if vt := u.OfAssistant; vt != nil {
		return vt.ToolCalls
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionMessageParamUnion) GetToolCallID() *string {
	if vt := u.OfTool; vt != nil {
		return &vt.ToolCallID
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionMessageParamUnion) GetRole() *string {
	if vt := u.OfDeveloper; vt != nil {
		return (*string)(&vt.Role)
	} else if vt := u.OfSystem; vt != nil {
		return (*string)(&vt.Role)
	} else if vt := u.OfUser; vt != nil {
		return (*string)(&vt.Role)
	} else if vt := u.OfAssistant; vt != nil {
		return (*string)(&vt.Role)
	} else if vt := u.OfTool; vt != nil {
		return (*string)(&vt.Role)
	} else if vt := u.OfFunction; vt != nil {
		return (*string)(&vt.Role)
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionMessageParamUnion) GetName() *string {
	if vt := u.OfDeveloper; vt != nil && vt.Name.Valid() {
		return &vt.Name.Value
	} else if vt := u.OfSystem; vt != nil && vt.Name.Valid() {
		return &vt.Name.Value
	} else if vt := u.OfUser; vt != nil && vt.Name.Valid() {
		return &vt.Name.Value
	} else if vt := u.OfAssistant; vt != nil && vt.Name.Valid() {
		return &vt.Name.Value
	} else if vt := u.OfFunction; vt != nil {
		return (*string)(&vt.Name)
	}
	return nil
}

// Returns a subunion which exports methods to access subproperties
//
// Or use AsAny() to get the underlying value
func (u ChatCompletionMessageParamUnion) GetContent() (res chatCompletionMessageParamUnionContent) {
	if vt := u.OfDeveloper; vt != nil {
		res.any = vt.Content.asAny()
	} else if vt := u.OfSystem; vt != nil {
		res.any = vt.Content.asAny()
	} else if vt := u.OfUser; vt != nil {
		res.any = vt.Content.asAny()
	} else if vt := u.OfAssistant; vt != nil {
		res.any = vt.Content.asAny()
	} else if vt := u.OfTool; vt != nil {
		res.any = vt.Content.asAny()
	} else if vt := u.OfFunction; vt != nil && vt.Content.Valid() {
		res.any = &vt.Content.Value
	}
	return
}

// Can have the runtime types [*string], [_[]ChatCompletionContentPartTextParam],
// [_[]ChatCompletionContentPartUnionParam],
// [\*[]ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion]
type chatCompletionMessageParamUnionContent struct{ any }

// Use the following switch statement to get the type of the union:
//
//	switch u.AsAny().(type) {
//	case *string:
//	case *[]openai.ChatCompletionContentPartTextParam:
//	case *[]openai.ChatCompletionContentPartUnionParam:
//	case *[]openai.ChatCompletionAssistantMessageParamContentArrayOfContentPartUnion:
//	default:
//	    fmt.Errorf("not present")
//	}
func (u chatCompletionMessageParamUnionContent) AsAny() any { return u.any }

func init() {
	apijson.RegisterUnion[ChatCompletionMessageParamUnion](
		"role",
		apijson.Discriminator[ChatCompletionDeveloperMessageParam]("developer"),
		apijson.Discriminator[ChatCompletionSystemMessageParam]("system"),
		apijson.Discriminator[ChatCompletionUserMessageParam]("user"),
		apijson.Discriminator[ChatCompletionAssistantMessageParam]("assistant"),
		apijson.Discriminator[ChatCompletionToolMessageParam]("tool"),
		apijson.Discriminator[ChatCompletionFunctionMessageParam]("function"),
	)
}

// ChatCompletionMessageToolCallUnion contains all possible properties and values
// from [ChatCompletionMessageFunctionToolCall],
// [ChatCompletionMessageCustomToolCall].
//
// Use the [ChatCompletionMessageToolCallUnion.AsAny] method to switch on the
// variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type ChatCompletionMessageToolCallUnion struct {
	ID string `json:"id"`
	// This field is from variant [ChatCompletionMessageFunctionToolCall].
	Function ChatCompletionMessageFunctionToolCallFunction `json:"function"`
	// Any of "function", "custom".
	Type string `json:"type"`
	// This field is from variant [ChatCompletionMessageCustomToolCall].
	Custom ChatCompletionMessageCustomToolCallCustom `json:"custom"`
	JSON   struct {
		ID       respjson.Field
		Function respjson.Field
		Type     respjson.Field
		Custom   respjson.Field
		raw      string
	} `json:"-"`
}

// anyChatCompletionMessageToolCall is implemented by each variant of
// [ChatCompletionMessageToolCallUnion] to add type safety for the return type of
// [ChatCompletionMessageToolCallUnion.AsAny]
type anyChatCompletionMessageToolCall interface {
	implChatCompletionMessageToolCallUnion()
}

func (ChatCompletionMessageFunctionToolCall) implChatCompletionMessageToolCallUnion() {}
func (ChatCompletionMessageCustomToolCall) implChatCompletionMessageToolCallUnion()   {}

// Use the following switch statement to find the correct variant
//
//	switch variant := ChatCompletionMessageToolCallUnion.AsAny().(type) {
//	case openai.ChatCompletionMessageFunctionToolCall:
//	case openai.ChatCompletionMessageCustomToolCall:
//	default:
//	  fmt.Errorf("no variant present")
//	}
func (u ChatCompletionMessageToolCallUnion) AsAny() anyChatCompletionMessageToolCall {
	switch u.Type {
	case "function":
		return u.AsFunction()
	case "custom":
		return u.AsCustom()
	}
	return nil
}

func (u ChatCompletionMessageToolCallUnion) AsFunction() (v ChatCompletionMessageFunctionToolCall) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

func (u ChatCompletionMessageToolCallUnion) AsCustom() (v ChatCompletionMessageCustomToolCall) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

// Returns the unmodified JSON received from the API
func (u ChatCompletionMessageToolCallUnion) RawJSON() string { return u.JSON.raw }

func (r *ChatCompletionMessageToolCallUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// ToParam converts this ChatCompletionMessageToolCallUnion to a
// ChatCompletionMessageToolCallUnionParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// ChatCompletionMessageToolCallUnionParam.Overrides()
func (r ChatCompletionMessageToolCallUnion) ToParam() ChatCompletionMessageToolCallUnionParam {
	return param.Override[ChatCompletionMessageToolCallUnionParam](json.RawMessage(r.RawJSON()))
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionMessageToolCallUnionParam struct {
	OfFunction *ChatCompletionMessageFunctionToolCallParam `json:",omitzero,inline"`
	OfCustom   *ChatCompletionMessageCustomToolCallParam   `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionMessageToolCallUnionParam) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfFunction, u.OfCustom)
}
func (u *ChatCompletionMessageToolCallUnionParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionMessageToolCallUnionParam) asAny() any {
	if !param.IsOmitted(u.OfFunction) {
		return u.OfFunction
	} else if !param.IsOmitted(u.OfCustom) {
		return u.OfCustom
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionMessageToolCallUnionParam) GetFunction() *ChatCompletionMessageFunctionToolCallFunctionParam {
	if vt := u.OfFunction; vt != nil {
		return &vt.Function
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionMessageToolCallUnionParam) GetCustom() *ChatCompletionMessageCustomToolCallCustomParam {
	if vt := u.OfCustom; vt != nil {
		return &vt.Custom
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionMessageToolCallUnionParam) GetID() *string {
	if vt := u.OfFunction; vt != nil {
		return (*string)(&vt.ID)
	} else if vt := u.OfCustom; vt != nil {
		return (*string)(&vt.ID)
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionMessageToolCallUnionParam) GetType() *string {
	if vt := u.OfFunction; vt != nil {
		return (*string)(&vt.Type)
	} else if vt := u.OfCustom; vt != nil {
		return (*string)(&vt.Type)
	}
	return nil
}

func init() {
	apijson.RegisterUnion[ChatCompletionMessageToolCallUnionParam](
		"type",
		apijson.Discriminator[ChatCompletionMessageFunctionToolCallParam]("function"),
		apijson.Discriminator[ChatCompletionMessageCustomToolCallParam]("custom"),
	)
}

// Specifies a tool the model should use. Use to force the model to call a specific
// function.
//
// The properties Function, Type are required.
type ChatCompletionNamedToolChoiceParam struct {
	Function ChatCompletionNamedToolChoiceFunctionParam `json:"function,omitzero" api:"required"`
	// For function calling, the type is always `function`.
	//
	// This field can be elided, and will marshal its zero value as "function".
	Type constant.Function `json:"type" default:"function"`
	paramObj
}

func (r ChatCompletionNamedToolChoiceParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNamedToolChoiceParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNamedToolChoiceParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// The property Name is required.
type ChatCompletionNamedToolChoiceFunctionParam struct {
	// The name of the function to call.
	Name string `json:"name" api:"required"`
	paramObj
}

func (r ChatCompletionNamedToolChoiceFunctionParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNamedToolChoiceFunctionParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNamedToolChoiceFunctionParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Specifies a tool the model should use. Use to force the model to call a specific
// custom tool.
//
// The properties Custom, Type are required.
type ChatCompletionNamedToolChoiceCustomParam struct {
	Custom ChatCompletionNamedToolChoiceCustomCustomParam `json:"custom,omitzero" api:"required"`
	// For custom tool calling, the type is always `custom`.
	//
	// This field can be elided, and will marshal its zero value as "custom".
	Type constant.Custom `json:"type" default:"custom"`
	paramObj
}

func (r ChatCompletionNamedToolChoiceCustomParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNamedToolChoiceCustomParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNamedToolChoiceCustomParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// The property Name is required.
type ChatCompletionNamedToolChoiceCustomCustomParam struct {
	// The name of the custom tool to call.
	Name string `json:"name" api:"required"`
	paramObj
}

func (r ChatCompletionNamedToolChoiceCustomCustomParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNamedToolChoiceCustomCustomParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNamedToolChoiceCustomCustomParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Static predicted output content, such as the content of a text file that is
// being regenerated.
//
// The properties Content, Type are required.
type ChatCompletionPredictionContentParam struct {
	// The content that should be matched when generating a model response. If
	// generated tokens would match this content, the entire model response can be
	// returned much more quickly.
	Content ChatCompletionPredictionContentContentUnionParam `json:"content,omitzero" api:"required"`
	// The type of the predicted content you want to provide. This type is currently
	// always `content`.
	//
	// This field can be elided, and will marshal its zero value as "content".
	Type constant.Content `json:"type" default:"content"`
	paramObj
}

func (r ChatCompletionPredictionContentParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionPredictionContentParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionPredictionContentParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionPredictionContentContentUnionParam struct {
	OfString              param.Opt[string]                    `json:",omitzero,inline"`
	OfArrayOfContentParts []ChatCompletionContentPartTextParam `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionPredictionContentContentUnionParam) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
}
func (u *ChatCompletionPredictionContentContentUnionParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionPredictionContentContentUnionParam) asAny() any {
	if !param.IsOmitted(u.OfString) {
		return &u.OfString.Value
	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
		return &u.OfArrayOfContentParts
	}
	return nil
}

// A chat completion message generated by the model.
type ChatCompletionStoreMessage struct {
	// The identifier of the chat message.
	ID string `json:"id" api:"required"`
	// If a content parts array was provided, this is an array of `text` and
	// `image_url` parts. Otherwise, null.
	ContentParts []ChatCompletionStoreMessageContentPartUnion `json:"content_parts" api:"nullable"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		ID           respjson.Field
		ContentParts respjson.Field
		ExtraFields  map[string]respjson.Field
		raw          string
	} `json:"-"`
	ChatCompletionMessage
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionStoreMessage) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionStoreMessage) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// ChatCompletionStoreMessageContentPartUnion contains all possible properties and
// values from [ChatCompletionContentPartText], [ChatCompletionContentPartImage].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type ChatCompletionStoreMessageContentPartUnion struct {
	// This field is from variant [ChatCompletionContentPartText].
	Text string `json:"text"`
	Type string `json:"type"`
	// This field is a union of [ChatCompletionContentPartTextPromptCacheBreakpoint],
	// [ChatCompletionContentPartImagePromptCacheBreakpoint]
	PromptCacheBreakpoint ChatCompletionStoreMessageContentPartUnionPromptCacheBreakpoint `json:"prompt_cache_breakpoint"`
	// This field is from variant [ChatCompletionContentPartImage].
	ImageURL ChatCompletionContentPartImageImageURL `json:"image_url"`
	JSON     struct {
		Text                  respjson.Field
		Type                  respjson.Field
		PromptCacheBreakpoint respjson.Field
		ImageURL              respjson.Field
		raw                   string
	} `json:"-"`
}

func (u ChatCompletionStoreMessageContentPartUnion) AsTextContentPart() (v ChatCompletionContentPartText) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

func (u ChatCompletionStoreMessageContentPartUnion) AsImageContentPart() (v ChatCompletionContentPartImage) {
	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
	return
}

// Returns the unmodified JSON received from the API
func (u ChatCompletionStoreMessageContentPartUnion) RawJSON() string { return u.JSON.raw }

func (r *ChatCompletionStoreMessageContentPartUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// ChatCompletionStoreMessageContentPartUnionPromptCacheBreakpoint is an implicit
// subunion of [ChatCompletionStoreMessageContentPartUnion].
// ChatCompletionStoreMessageContentPartUnionPromptCacheBreakpoint provides
// convenient access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [ChatCompletionStoreMessageContentPartUnion].
type ChatCompletionStoreMessageContentPartUnionPromptCacheBreakpoint struct {
	// This field is from variant [ChatCompletionContentPartTextPromptCacheBreakpoint].
	Mode constant.Explicit `json:"mode"`
	JSON struct {
		Mode respjson.Field
		raw  string
	} `json:"-"`
}

func (r *ChatCompletionStoreMessageContentPartUnionPromptCacheBreakpoint) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Options for streaming response. Only set this when you set `stream: true`.
type ChatCompletionStreamOptionsParam struct {
	// When true, stream obfuscation will be enabled. Stream obfuscation adds random
	// characters to an `obfuscation` field on streaming delta events to normalize
	// payload sizes as a mitigation to certain side-channel attacks. These obfuscation
	// fields are included by default, but add a small amount of overhead to the data
	// stream. You can set `include_obfuscation` to false to optimize for bandwidth if
	// you trust the network links between your application and the OpenAI API.
	IncludeObfuscation param.Opt[bool] `json:"include_obfuscation,omitzero"`
	// If set, an additional chunk will be streamed before the `data: [DONE]` message.
	// The `usage` field on this chunk shows the token usage statistics for the entire
	// request, and the `choices` field will always be an empty array.
	//
	// All other chunks will also include a `usage` field, but with a null value.
	// **NOTE:** If the stream is interrupted, you may not receive the final usage
	// chunk which contains the total token usage for the request.
	IncludeUsage param.Opt[bool] `json:"include_usage,omitzero"`
	paramObj
}

func (r ChatCompletionStreamOptionsParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionStreamOptionsParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionStreamOptionsParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Developer-provided instructions that the model should follow, regardless of
// messages sent by the user. With o1 models and newer, use `developer` messages
// for this purpose instead.
//
// The properties Content, Role are required.
type ChatCompletionSystemMessageParam struct {
	// The contents of the system message.
	Content ChatCompletionSystemMessageParamContentUnion `json:"content,omitzero" api:"required"`
	// An optional name for the participant. Provides the model information to
	// differentiate between participants of the same role.
	Name param.Opt[string] `json:"name,omitzero"`
	// The role of the messages author, in this case `system`.
	//
	// This field can be elided, and will marshal its zero value as "system".
	Role constant.System `json:"role" default:"system"`
	paramObj
}

func (r ChatCompletionSystemMessageParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionSystemMessageParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionSystemMessageParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionSystemMessageParamContentUnion struct {
	OfString              param.Opt[string]                    `json:",omitzero,inline"`
	OfArrayOfContentParts []ChatCompletionContentPartTextParam `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionSystemMessageParamContentUnion) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
}
func (u *ChatCompletionSystemMessageParamContentUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionSystemMessageParamContentUnion) asAny() any {
	if !param.IsOmitted(u.OfString) {
		return &u.OfString.Value
	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
		return &u.OfArrayOfContentParts
	}
	return nil
}

type ChatCompletionTokenLogprob struct {
	// The token.
	Token string `json:"token" api:"required"`
	// A list of integers representing the UTF-8 bytes representation of the token.
	// Useful in instances where characters are represented by multiple tokens and
	// their byte representations must be combined to generate the correct text
	// representation. Can be `null` if there is no bytes representation for the token.
	Bytes []int64 `json:"bytes" api:"required"`
	// The log probability of this token, if it is within the top 20 most likely
	// tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
	// unlikely.
	Logprob float64 `json:"logprob" api:"required"`
	// List of the most likely tokens and their log probability, at this token
	// position. The number of entries may be fewer than the requested `top_logprobs`.
	TopLogprobs []ChatCompletionTokenLogprobTopLogprob `json:"top_logprobs" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Token       respjson.Field
		Bytes       respjson.Field
		Logprob     respjson.Field
		TopLogprobs respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionTokenLogprob) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionTokenLogprob) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

type ChatCompletionTokenLogprobTopLogprob struct {
	// The token.
	Token string `json:"token" api:"required"`
	// A list of integers representing the UTF-8 bytes representation of the token.
	// Useful in instances where characters are represented by multiple tokens and
	// their byte representations must be combined to generate the correct text
	// representation. Can be `null` if there is no bytes representation for the token.
	Bytes []int64 `json:"bytes" api:"required"`
	// The log probability of this token, if it is within the top 20 most likely
	// tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
	// unlikely.
	Logprob float64 `json:"logprob" api:"required"`
	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
	JSON struct {
		Token       respjson.Field
		Bytes       respjson.Field
		Logprob     respjson.Field
		ExtraFields map[string]respjson.Field
		raw         string
	} `json:"-"`
}

// Returns the unmodified JSON received from the API
func (r ChatCompletionTokenLogprobTopLogprob) RawJSON() string { return r.JSON.raw }
func (r *ChatCompletionTokenLogprobTopLogprob) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func ChatCompletionFunctionTool(function shared.FunctionDefinitionParam) ChatCompletionToolUnionParam {
	var variant ChatCompletionFunctionToolParam
	variant.Function = function
	return ChatCompletionToolUnionParam{OfFunction: &variant}
}

func ChatCompletionCustomTool(custom ChatCompletionCustomToolCustomParam) ChatCompletionToolUnionParam {
	var variant ChatCompletionCustomToolParam
	variant.Custom = custom
	return ChatCompletionToolUnionParam{OfCustom: &variant}
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionToolUnionParam struct {
	OfFunction *ChatCompletionFunctionToolParam `json:",omitzero,inline"`
	OfCustom   *ChatCompletionCustomToolParam   `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionToolUnionParam) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfFunction, u.OfCustom)
}
func (u *ChatCompletionToolUnionParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionToolUnionParam) asAny() any {
	if !param.IsOmitted(u.OfFunction) {
		return u.OfFunction
	} else if !param.IsOmitted(u.OfCustom) {
		return u.OfCustom
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionToolUnionParam) GetFunction() *shared.FunctionDefinitionParam {
	if vt := u.OfFunction; vt != nil {
		return &vt.Function
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionToolUnionParam) GetCustom() *ChatCompletionCustomToolCustomParam {
	if vt := u.OfCustom; vt != nil {
		return &vt.Custom
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionToolUnionParam) GetType() *string {
	if vt := u.OfFunction; vt != nil {
		return (*string)(&vt.Type)
	} else if vt := u.OfCustom; vt != nil {
		return (*string)(&vt.Type)
	}
	return nil
}

func init() {
	apijson.RegisterUnion[ChatCompletionToolUnionParam](
		"type",
		apijson.Discriminator[ChatCompletionFunctionToolParam]("function"),
		apijson.Discriminator[ChatCompletionCustomToolParam]("custom"),
	)
}

func ToolChoiceOptionAllowedTools(allowedTools ChatCompletionAllowedToolsParam) ChatCompletionToolChoiceOptionUnionParam {
	var variant ChatCompletionAllowedToolChoiceParam
	variant.AllowedTools = allowedTools
	return ChatCompletionToolChoiceOptionUnionParam{OfAllowedTools: &variant}
}

func ToolChoiceOptionFunctionToolChoice(function ChatCompletionNamedToolChoiceFunctionParam) ChatCompletionToolChoiceOptionUnionParam {
	var variant ChatCompletionNamedToolChoiceParam
	variant.Function = function
	return ChatCompletionToolChoiceOptionUnionParam{OfFunctionToolChoice: &variant}
}

func ToolChoiceOptionCustomToolChoice(custom ChatCompletionNamedToolChoiceCustomCustomParam) ChatCompletionToolChoiceOptionUnionParam {
	var variant ChatCompletionNamedToolChoiceCustomParam
	variant.Custom = custom
	return ChatCompletionToolChoiceOptionUnionParam{OfCustomToolChoice: &variant}
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionToolChoiceOptionUnionParam struct {
	// Check if union is this variant with !param.IsOmitted(union.OfAuto)
	OfAuto               param.Opt[string]                         `json:",omitzero,inline"`
	OfAllowedTools       *ChatCompletionAllowedToolChoiceParam     `json:",omitzero,inline"`
	OfFunctionToolChoice *ChatCompletionNamedToolChoiceParam       `json:",omitzero,inline"`
	OfCustomToolChoice   *ChatCompletionNamedToolChoiceCustomParam `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionToolChoiceOptionUnionParam) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfAuto, u.OfAllowedTools, u.OfFunctionToolChoice, u.OfCustomToolChoice)
}
func (u *ChatCompletionToolChoiceOptionUnionParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionToolChoiceOptionUnionParam) asAny() any {
	if !param.IsOmitted(u.OfAuto) {
		return &u.OfAuto
	} else if !param.IsOmitted(u.OfAllowedTools) {
		return u.OfAllowedTools
	} else if !param.IsOmitted(u.OfFunctionToolChoice) {
		return u.OfFunctionToolChoice
	} else if !param.IsOmitted(u.OfCustomToolChoice) {
		return u.OfCustomToolChoice
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionToolChoiceOptionUnionParam) GetAllowedTools() *ChatCompletionAllowedToolsParam {
	if vt := u.OfAllowedTools; vt != nil {
		return &vt.AllowedTools
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionToolChoiceOptionUnionParam) GetFunction() *ChatCompletionNamedToolChoiceFunctionParam {
	if vt := u.OfFunctionToolChoice; vt != nil {
		return &vt.Function
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionToolChoiceOptionUnionParam) GetCustom() *ChatCompletionNamedToolChoiceCustomCustomParam {
	if vt := u.OfCustomToolChoice; vt != nil {
		return &vt.Custom
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionToolChoiceOptionUnionParam) GetType() *string {
	if vt := u.OfAllowedTools; vt != nil {
		return (*string)(&vt.Type)
	} else if vt := u.OfFunctionToolChoice; vt != nil {
		return (*string)(&vt.Type)
	} else if vt := u.OfCustomToolChoice; vt != nil {
		return (*string)(&vt.Type)
	}
	return nil
}

// `none` means the model will not call any tool and instead generates a message.
// `auto` means the model can pick between generating a message or calling one or
// more tools. `required` means the model must call one or more tools.
type ChatCompletionToolChoiceOptionAuto string

const (
	ChatCompletionToolChoiceOptionAutoNone     ChatCompletionToolChoiceOptionAuto = "none"
	ChatCompletionToolChoiceOptionAutoAuto     ChatCompletionToolChoiceOptionAuto = "auto"
	ChatCompletionToolChoiceOptionAutoRequired ChatCompletionToolChoiceOptionAuto = "required"
)

// The properties Content, Role, ToolCallID are required.
type ChatCompletionToolMessageParam struct {
	// The contents of the tool message.
	Content ChatCompletionToolMessageParamContentUnion `json:"content,omitzero" api:"required"`
	// Tool call that this message is responding to.
	ToolCallID string `json:"tool_call_id" api:"required"`
	// The role of the messages author, in this case `tool`.
	//
	// This field can be elided, and will marshal its zero value as "tool".
	Role constant.Tool `json:"role" default:"tool"`
	paramObj
}

func (r ChatCompletionToolMessageParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionToolMessageParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionToolMessageParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionToolMessageParamContentUnion struct {
	OfString              param.Opt[string]                    `json:",omitzero,inline"`
	OfArrayOfContentParts []ChatCompletionContentPartTextParam `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionToolMessageParamContentUnion) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
}
func (u *ChatCompletionToolMessageParamContentUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionToolMessageParamContentUnion) asAny() any {
	if !param.IsOmitted(u.OfString) {
		return &u.OfString.Value
	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
		return &u.OfArrayOfContentParts
	}
	return nil
}

// Messages sent by an end user, containing prompts or additional context
// information.
//
// The properties Content, Role are required.
type ChatCompletionUserMessageParam struct {
	// The contents of the user message.
	Content ChatCompletionUserMessageParamContentUnion `json:"content,omitzero" api:"required"`
	// An optional name for the participant. Provides the model information to
	// differentiate between participants of the same role.
	Name param.Opt[string] `json:"name,omitzero"`
	// The role of the messages author, in this case `user`.
	//
	// This field can be elided, and will marshal its zero value as "user".
	Role constant.User `json:"role" default:"user"`
	paramObj
}

func (r ChatCompletionUserMessageParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionUserMessageParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionUserMessageParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionUserMessageParamContentUnion struct {
	OfString              param.Opt[string]                     `json:",omitzero,inline"`
	OfArrayOfContentParts []ChatCompletionContentPartUnionParam `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionUserMessageParamContentUnion) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
}
func (u *ChatCompletionUserMessageParamContentUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionUserMessageParamContentUnion) asAny() any {
	if !param.IsOmitted(u.OfString) {
		return &u.OfString.Value
	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
		return &u.OfArrayOfContentParts
	}
	return nil
}

// Constrains the tools available to the model to a pre-defined set.
//
// The properties Mode, Tools are required.
type ChatCompletionAllowedToolsParam struct {
	// Constrains the tools available to the model to a pre-defined set.
	//
	// `auto` allows the model to pick from among the allowed tools and generate a
	// message.
	//
	// `required` requires the model to call one or more of the allowed tools.
	//
	// Any of "auto", "required".
	Mode ChatCompletionAllowedToolsMode `json:"mode,omitzero" api:"required"`
	// A list of tool definitions that the model should be allowed to call.
	//
	// For the Chat Completions API, the list of tool definitions might look like:
	//
	// ```json
	// [
	//
	//	{ "type": "function", "function": { "name": "get_weather" } },
	//	{ "type": "function", "function": { "name": "get_time" } }
	//
	// ]
	// ```
	Tools []map[string]any `json:"tools,omitzero" api:"required"`
	paramObj
}

func (r ChatCompletionAllowedToolsParam) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionAllowedToolsParam
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionAllowedToolsParam) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Constrains the tools available to the model to a pre-defined set.
//
// `auto` allows the model to pick from among the allowed tools and generate a
// message.
//
// `required` requires the model to call one or more of the allowed tools.
type ChatCompletionAllowedToolsMode string

const (
	ChatCompletionAllowedToolsModeAuto     ChatCompletionAllowedToolsMode = "auto"
	ChatCompletionAllowedToolsModeRequired ChatCompletionAllowedToolsMode = "required"
)

type ChatCompletionNewParams struct {
	// A list of messages comprising the conversation so far. Depending on the
	// [model](https://platform.openai.com/docs/models) you use, different message
	// types (modalities) are supported, like
	// [text](https://platform.openai.com/docs/guides/text-generation),
	// [images](https://platform.openai.com/docs/guides/vision), and
	// [audio](https://platform.openai.com/docs/guides/audio).
	Messages []ChatCompletionMessageParamUnion `json:"messages,omitzero" api:"required"`
	// Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a
	// wide range of models with different capabilities, performance characteristics,
	// and price points. Refer to the
	// [model guide](https://platform.openai.com/docs/models) to browse and compare
	// available models.
	Model shared.ChatModel `json:"model,omitzero" api:"required"`
	// Number between -2.0 and 2.0. Positive values penalize new tokens based on their
	// existing frequency in the text so far, decreasing the model's likelihood to
	// repeat the same line verbatim.
	FrequencyPenalty param.Opt[float64] `json:"frequency_penalty,omitzero"`
	// Whether to return log probabilities of the output tokens or not. If true,
	// returns the log probabilities of each output token returned in the `content` of
	// `message`.
	Logprobs param.Opt[bool] `json:"logprobs,omitzero"`
	// An upper bound for the number of tokens that can be generated for a completion,
	// including visible output tokens and
	// [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
	MaxCompletionTokens param.Opt[int64] `json:"max_completion_tokens,omitzero"`
	// The maximum number of [tokens](/tokenizer) that can be generated in the chat
	// completion. This value can be used to control
	// [costs](https://openai.com/api/pricing/) for text generated via API.
	//
	// This value is now deprecated in favor of `max_completion_tokens`, and is not
	// compatible with
	// [o-series models](https://platform.openai.com/docs/guides/reasoning).
	MaxTokens param.Opt[int64] `json:"max_tokens,omitzero"`
	// How many chat completion choices to generate for each input message. Note that
	// you will be charged based on the number of generated tokens across all of the
	// choices. Keep `n` as `1` to minimize costs.
	N param.Opt[int64] `json:"n,omitzero"`
	// Number between -2.0 and 2.0. Positive values penalize new tokens based on
	// whether they appear in the text so far, increasing the model's likelihood to
	// talk about new topics.
	PresencePenalty param.Opt[float64] `json:"presence_penalty,omitzero"`
	// This feature is in Beta. If specified, our system will make a best effort to
	// sample deterministically, such that repeated requests with the same `seed` and
	// parameters should return the same result. Determinism is not guaranteed, and you
	// should refer to the `system_fingerprint` response parameter to monitor changes
	// in the backend.
	Seed param.Opt[int64] `json:"seed,omitzero"`
	// Whether or not to store the output of this chat completion request for use in
	// our [model distillation](https://platform.openai.com/docs/guides/distillation)
	// or [evals](https://platform.openai.com/docs/guides/evals) products.
	//
	// Supports text and image inputs. Note: image inputs over 8MB will be dropped.
	Store param.Opt[bool] `json:"store,omitzero"`
	// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
	// make the output more random, while lower values like 0.2 will make it more
	// focused and deterministic. We generally recommend altering this or `top_p` but
	// not both.
	Temperature param.Opt[float64] `json:"temperature,omitzero"`
	// An integer between 0 and 20 specifying the maximum number of most likely tokens
	// to return at each token position, each with an associated log probability. In
	// some cases, the number of returned tokens may be fewer than requested.
	// `logprobs` must be set to `true` if this parameter is used.
	TopLogprobs param.Opt[int64] `json:"top_logprobs,omitzero"`
	// An alternative to sampling with temperature, called nucleus sampling, where the
	// model considers the results of the tokens with top_p probability mass. So 0.1
	// means only the tokens comprising the top 10% probability mass are considered.
	//
	// We generally recommend altering this or `temperature` but not both.
	TopP param.Opt[float64] `json:"top_p,omitzero"`
	// Whether to enable
	// [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
	// during tool use.
	ParallelToolCalls param.Opt[bool] `json:"parallel_tool_calls,omitzero"`
	// Used by OpenAI to cache responses for similar requests to optimize your cache
	// hit rates. Replaces the `user` field.
	// [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
	PromptCacheKey param.Opt[string] `json:"prompt_cache_key,omitzero"`
	// A stable identifier used to help detect users of your application that may be
	// violating OpenAI's usage policies. The IDs should be a string that uniquely
	// identifies each user, with a maximum length of 64 characters. We recommend
	// hashing their username or email address, in order to avoid sending us any
	// identifying information.
	// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
	SafetyIdentifier param.Opt[string] `json:"safety_identifier,omitzero"`
	// This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use
	// `prompt_cache_key` instead to maintain caching optimizations. A stable
	// identifier for your end-users. Used to boost cache hit rates by better bucketing
	// similar requests and to help OpenAI detect and prevent abuse.
	// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
	User param.Opt[string] `json:"user,omitzero"`
	// Parameters for audio output. Required when audio output is requested with
	// `modalities: ["audio"]`.
	// [Learn more](https://platform.openai.com/docs/guides/audio).
	Audio ChatCompletionAudioParam `json:"audio,omitzero"`
	// Modify the likelihood of specified tokens appearing in the completion.
	//
	// Accepts a JSON object that maps tokens (specified by their token ID in the
	// tokenizer) to an associated bias value from -100 to 100. Mathematically, the
	// bias is added to the logits generated by the model prior to sampling. The exact
	// effect will vary per model, but values between -1 and 1 should decrease or
	// increase likelihood of selection; values like -100 or 100 should result in a ban
	// or exclusive selection of the relevant token.
	LogitBias map[string]int64 `json:"logit_bias,omitzero"`
	// Set of 16 key-value pairs that can be attached to an object. This can be useful
	// for storing additional information about the object in a structured format, and
	// querying for objects via API or the dashboard.
	//
	// Keys are strings with a maximum length of 64 characters. Values are strings with
	// a maximum length of 512 characters.
	Metadata shared.Metadata `json:"metadata,omitzero"`
	// Output types that you would like the model to generate. Most models are capable
	// of generating text, which is the default:
	//
	// `["text"]`
	//
	// The `gpt-4o-audio-preview` model can also be used to
	// [generate audio](https://platform.openai.com/docs/guides/audio). To request that
	// this model generate both text and audio responses, you can use:
	//
	// `["text", "audio"]`
	//
	// Any of "text", "audio".
	Modalities []string `json:"modalities,omitzero"`
	// Configuration for running moderation on the request input and generated output.
	Moderation ChatCompletionNewParamsModeration `json:"moderation,omitzero"`
	// Deprecated. Use `prompt_cache_options.ttl` instead.
	//
	// The retention policy for the prompt cache. Set to `24h` to enable extended
	// prompt caching, which keeps cached prefixes active for longer, up to a maximum
	// of 24 hours.
	// [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).
	// This field expresses a maximum retention policy, while
	// `prompt_cache_options.ttl` expresses a minimum cache lifetime. The two fields
	// are independent and do not interact. For `gpt-5.5`, `gpt-5.5-pro`, and future
	// models, only `24h` is supported.
	//
	// For older models that support both `in_memory` and `24h`, the default depends on
	// your organization's data retention policy:
	//
	//   - Organizations without ZDR enabled default to `24h`.
	//   - Organizations with ZDR enabled default to `in_memory` when
	//     `prompt_cache_retention` is not specified.
	//
	// Any of "in_memory", "24h".
	PromptCacheRetention ChatCompletionNewParamsPromptCacheRetention `json:"prompt_cache_retention,omitzero"`
	// Constrains effort on reasoning for reasoning models. Currently supported values
	// are `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`. Reducing
	// reasoning effort can result in faster responses and fewer tokens used on
	// reasoning in a response. Not all reasoning models support every value. See the
	// [reasoning guide](https://platform.openai.com/docs/guides/reasoning) for
	// model-specific support.
	//
	// Any of "none", "minimal", "low", "medium", "high", "xhigh", "max".
	ReasoningEffort shared.ReasoningEffort `json:"reasoning_effort,omitzero"`
	// Specifies the processing type used for serving the request.
	//
	//   - If set to 'auto', then the request will be processed with the service tier
	//     configured in the Project settings. Unless otherwise configured, the Project
	//     will use 'default'.
	//   - If set to 'default', then the request will be processed with the standard
	//     pricing and performance for the selected model.
	//   - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
	//     '[priority](https://openai.com/api-priority-processing/)', then the request
	//     will be processed with the corresponding service tier.
	//   - When not set, the default behavior is 'auto'.
	//
	// When the `service_tier` parameter is set, the response body will include the
	// `service_tier` value based on the processing mode actually used to serve the
	// request. This response value may be different from the value set in the
	// parameter.
	//
	// Any of "auto", "default", "flex", "scale", "priority".
	ServiceTier ChatCompletionNewParamsServiceTier `json:"service_tier,omitzero"`
	// Not supported with latest reasoning models `o3` and `o4-mini`.
	//
	// Up to 4 sequences where the API will stop generating further tokens. The
	// returned text will not contain the stop sequence.
	Stop ChatCompletionNewParamsStopUnion `json:"stop,omitzero"`
	// Options for streaming response. Only set this when you set `stream: true`.
	StreamOptions ChatCompletionStreamOptionsParam `json:"stream_options,omitzero"`
	// Constrains the verbosity of the model's response. Lower values will result in
	// more concise responses, while higher values will result in more verbose
	// responses. Currently supported values are `low`, `medium`, and `high`.
	//
	// Any of "low", "medium", "high".
	Verbosity ChatCompletionNewParamsVerbosity `json:"verbosity,omitzero"`
	// Deprecated in favor of `tool_choice`.
	//
	// Controls which (if any) function is called by the model.
	//
	// `none` means the model will not call a function and instead generates a message.
	//
	// `auto` means the model can pick between generating a message or calling a
	// function.
	//
	// Specifying a particular function via `{"name": "my_function"}` forces the model
	// to call that function.
	//
	// `none` is the default when no functions are present. `auto` is the default if
	// functions are present.
	FunctionCall ChatCompletionNewParamsFunctionCallUnion `json:"function_call,omitzero"`
	// Deprecated in favor of `tools`.
	//
	// A list of functions the model may generate JSON inputs for.
	Functions []ChatCompletionNewParamsFunction `json:"functions,omitzero"`
	// Static predicted output content, such as the content of a text file that is
	// being regenerated.
	Prediction ChatCompletionPredictionContentParam `json:"prediction,omitzero"`
	// Options for prompt caching. Supported for `gpt-5.6` and later models. By
	// default, OpenAI automatically chooses one implicit cache breakpoint. You can add
	// explicit breakpoints to content blocks with `prompt_cache_breakpoint`. Each
	// request can write up to four breakpoints. For cache matching, OpenAI considers
	// up to the latest 80 breakpoints in the conversation, without a content-block
	// lookback limit. Set `mode` to `explicit` to disable the implicit breakpoint. The
	// `ttl` defaults to `30m`, which is currently the only supported value. See the
	// [prompt caching guide](https://platform.openai.com/docs/guides/prompt-caching)
	// for current details.
	PromptCacheOptions ChatCompletionNewParamsPromptCacheOptions `json:"prompt_cache_options,omitzero"`
	// An object specifying the format that the model must output.
	//
	// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
	// Outputs which ensures the model will match your supplied JSON schema. Learn more
	// in the
	// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
	//
	// Setting to `{ "type": "json_object" }` enables the older JSON mode, which
	// ensures the message the model generates is valid JSON. Using `json_schema` is
	// preferred for models that support it.
	ResponseFormat ChatCompletionNewParamsResponseFormatUnion `json:"response_format,omitzero"`
	// Controls which (if any) tool is called by the model. `none` means the model will
	// not call any tool and instead generates a message. `auto` means the model can
	// pick between generating a message or calling one or more tools. `required` means
	// the model must call one or more tools. Specifying a particular tool via
	// `{"type": "function", "function": {"name": "my_function"}}` forces the model to
	// call that tool.
	//
	// `none` is the default when no tools are present. `auto` is the default if tools
	// are present.
	ToolChoice ChatCompletionToolChoiceOptionUnionParam `json:"tool_choice,omitzero"`
	// A list of tools the model may call. You can provide either
	// [custom tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)
	// or [function tools](https://platform.openai.com/docs/guides/function-calling).
	Tools []ChatCompletionToolUnionParam `json:"tools,omitzero"`
	// This tool searches the web for relevant results to use in a response. Learn more
	// about the
	// [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
	WebSearchOptions ChatCompletionNewParamsWebSearchOptions `json:"web_search_options,omitzero"`
	paramObj
}

func (r ChatCompletionNewParams) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNewParams
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNewParams) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionNewParamsFunctionCallUnion struct {
	// Check if union is this variant with !param.IsOmitted(union.OfFunctionCallMode)
	OfFunctionCallMode   param.Opt[string]                      `json:",omitzero,inline"`
	OfFunctionCallOption *ChatCompletionFunctionCallOptionParam `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionNewParamsFunctionCallUnion) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfFunctionCallMode, u.OfFunctionCallOption)
}
func (u *ChatCompletionNewParamsFunctionCallUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionNewParamsFunctionCallUnion) asAny() any {
	if !param.IsOmitted(u.OfFunctionCallMode) {
		return &u.OfFunctionCallMode
	} else if !param.IsOmitted(u.OfFunctionCallOption) {
		return u.OfFunctionCallOption
	}
	return nil
}

// `none` means the model will not call a function and instead generates a message.
// `auto` means the model can pick between generating a message or calling a
// function.
type ChatCompletionNewParamsFunctionCallFunctionCallMode string

const (
	ChatCompletionNewParamsFunctionCallFunctionCallModeNone ChatCompletionNewParamsFunctionCallFunctionCallMode = "none"
	ChatCompletionNewParamsFunctionCallFunctionCallModeAuto ChatCompletionNewParamsFunctionCallFunctionCallMode = "auto"
)

// Deprecated: deprecated
//
// The property Name is required.
type ChatCompletionNewParamsFunction struct {
	// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
	// underscores and dashes, with a maximum length of 64.
	Name string `json:"name" api:"required"`
	// A description of what the function does, used by the model to choose when and
	// how to call the function.
	Description param.Opt[string] `json:"description,omitzero"`
	// The parameters the functions accepts, described as a JSON Schema object. See the
	// [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
	// and the
	// [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
	// documentation about the format.
	//
	// Omitting `parameters` defines a function with an empty parameter list.
	Parameters shared.FunctionParameters `json:"parameters,omitzero"`
	paramObj
}

func (r ChatCompletionNewParamsFunction) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNewParamsFunction
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNewParamsFunction) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Configuration for running moderation on the request input and generated output.
//
// The property Model is required.
type ChatCompletionNewParamsModeration struct {
	// The moderation model to use for moderated completions, e.g.
	// 'omni-moderation-latest'.
	Model string `json:"model" api:"required"`
	// The policy to apply to moderated response input and output.
	Policy ChatCompletionNewParamsModerationPolicy `json:"policy,omitzero"`
	paramObj
}

func (r ChatCompletionNewParamsModeration) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNewParamsModeration
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNewParamsModeration) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// The policy to apply to moderated response input and output.
type ChatCompletionNewParamsModerationPolicy struct {
	// The moderation policy for the response input.
	Input ChatCompletionNewParamsModerationPolicyInput `json:"input,omitzero"`
	// The moderation policy for the response output.
	Output ChatCompletionNewParamsModerationPolicyOutput `json:"output,omitzero"`
	paramObj
}

func (r ChatCompletionNewParamsModerationPolicy) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNewParamsModerationPolicy
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNewParamsModerationPolicy) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// The moderation policy for the response input.
//
// The property Mode is required.
type ChatCompletionNewParamsModerationPolicyInput struct {
	// Any of "score", "block".
	Mode string `json:"mode,omitzero" api:"required"`
	paramObj
}

func (r ChatCompletionNewParamsModerationPolicyInput) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNewParamsModerationPolicyInput
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNewParamsModerationPolicyInput) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func init() {
	apijson.RegisterFieldValidator[ChatCompletionNewParamsModerationPolicyInput](
		"mode", "score", "block",
	)
}

// The moderation policy for the response output.
//
// The property Mode is required.
type ChatCompletionNewParamsModerationPolicyOutput struct {
	// Any of "score", "block".
	Mode string `json:"mode,omitzero" api:"required"`
	paramObj
}

func (r ChatCompletionNewParamsModerationPolicyOutput) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNewParamsModerationPolicyOutput
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNewParamsModerationPolicyOutput) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func init() {
	apijson.RegisterFieldValidator[ChatCompletionNewParamsModerationPolicyOutput](
		"mode", "score", "block",
	)
}

// Options for prompt caching. Supported for `gpt-5.6` and later models. By
// default, OpenAI automatically chooses one implicit cache breakpoint. You can add
// explicit breakpoints to content blocks with `prompt_cache_breakpoint`. Each
// request can write up to four breakpoints. For cache matching, OpenAI considers
// up to the latest 80 breakpoints in the conversation, without a content-block
// lookback limit. Set `mode` to `explicit` to disable the implicit breakpoint. The
// `ttl` defaults to `30m`, which is currently the only supported value. See the
// [prompt caching guide](https://platform.openai.com/docs/guides/prompt-caching)
// for current details.
type ChatCompletionNewParamsPromptCacheOptions struct {
	// Controls whether OpenAI automatically creates an implicit cache breakpoint.
	// Defaults to `implicit`. With `implicit`, OpenAI creates one implicit breakpoint
	// and writes up to the latest three explicit breakpoints in the request. With
	// `explicit`, OpenAI does not create an implicit breakpoint and writes up to the
	// latest four explicit breakpoints. If there are no explicit breakpoints, the
	// request does not use prompt caching.
	//
	// Any of "implicit", "explicit".
	Mode string `json:"mode,omitzero"`
	// The minimum lifetime applied to every implicit and explicit cache breakpoint
	// written by the request. Defaults to `30m`, which is currently the only supported
	// value. The backend may retain cache entries for longer.
	//
	// Any of "30m".
	Ttl string `json:"ttl,omitzero"`
	paramObj
}

func (r ChatCompletionNewParamsPromptCacheOptions) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNewParamsPromptCacheOptions
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNewParamsPromptCacheOptions) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func init() {
	apijson.RegisterFieldValidator[ChatCompletionNewParamsPromptCacheOptions](
		"mode", "implicit", "explicit",
	)
	apijson.RegisterFieldValidator[ChatCompletionNewParamsPromptCacheOptions](
		"ttl", "30m",
	)
}

// Deprecated. Use `prompt_cache_options.ttl` instead.
//
// The retention policy for the prompt cache. Set to `24h` to enable extended
// prompt caching, which keeps cached prefixes active for longer, up to a maximum
// of 24 hours.
// [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).
// This field expresses a maximum retention policy, while
// `prompt_cache_options.ttl` expresses a minimum cache lifetime. The two fields
// are independent and do not interact. For `gpt-5.5`, `gpt-5.5-pro`, and future
// models, only `24h` is supported.
//
// For older models that support both `in_memory` and `24h`, the default depends on
// your organization's data retention policy:
//
//   - Organizations without ZDR enabled default to `24h`.
//   - Organizations with ZDR enabled default to `in_memory` when
//     `prompt_cache_retention` is not specified.
type ChatCompletionNewParamsPromptCacheRetention string

const (
	ChatCompletionNewParamsPromptCacheRetentionInMemory ChatCompletionNewParamsPromptCacheRetention = "in_memory"
	ChatCompletionNewParamsPromptCacheRetention24h      ChatCompletionNewParamsPromptCacheRetention = "24h"
)

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionNewParamsResponseFormatUnion struct {
	OfText       *shared.ResponseFormatTextParam       `json:",omitzero,inline"`
	OfJSONSchema *shared.ResponseFormatJSONSchemaParam `json:",omitzero,inline"`
	OfJSONObject *shared.ResponseFormatJSONObjectParam `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionNewParamsResponseFormatUnion) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfText, u.OfJSONSchema, u.OfJSONObject)
}
func (u *ChatCompletionNewParamsResponseFormatUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionNewParamsResponseFormatUnion) asAny() any {
	if !param.IsOmitted(u.OfText) {
		return u.OfText
	} else if !param.IsOmitted(u.OfJSONSchema) {
		return u.OfJSONSchema
	} else if !param.IsOmitted(u.OfJSONObject) {
		return u.OfJSONObject
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionNewParamsResponseFormatUnion) GetJSONSchema() *shared.ResponseFormatJSONSchemaJSONSchemaParam {
	if vt := u.OfJSONSchema; vt != nil {
		return &vt.JSONSchema
	}
	return nil
}

// Returns a pointer to the underlying variant's property, if present.
func (u ChatCompletionNewParamsResponseFormatUnion) GetType() *string {
	if vt := u.OfText; vt != nil {
		return (*string)(&vt.Type)
	} else if vt := u.OfJSONSchema; vt != nil {
		return (*string)(&vt.Type)
	} else if vt := u.OfJSONObject; vt != nil {
		return (*string)(&vt.Type)
	}
	return nil
}

func init() {
	apijson.RegisterUnion[ChatCompletionNewParamsResponseFormatUnion](
		"type",
		apijson.Discriminator[shared.ResponseFormatTextParam]("text"),
		apijson.Discriminator[shared.ResponseFormatJSONSchemaParam]("json_schema"),
		apijson.Discriminator[shared.ResponseFormatJSONObjectParam]("json_object"),
	)
}

// Specifies the processing type used for serving the request.
//
//   - If set to 'auto', then the request will be processed with the service tier
//     configured in the Project settings. Unless otherwise configured, the Project
//     will use 'default'.
//   - If set to 'default', then the request will be processed with the standard
//     pricing and performance for the selected model.
//   - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or
//     '[priority](https://openai.com/api-priority-processing/)', then the request
//     will be processed with the corresponding service tier.
//   - When not set, the default behavior is 'auto'.
//
// When the `service_tier` parameter is set, the response body will include the
// `service_tier` value based on the processing mode actually used to serve the
// request. This response value may be different from the value set in the
// parameter.
type ChatCompletionNewParamsServiceTier string

const (
	ChatCompletionNewParamsServiceTierAuto     ChatCompletionNewParamsServiceTier = "auto"
	ChatCompletionNewParamsServiceTierDefault  ChatCompletionNewParamsServiceTier = "default"
	ChatCompletionNewParamsServiceTierFlex     ChatCompletionNewParamsServiceTier = "flex"
	ChatCompletionNewParamsServiceTierScale    ChatCompletionNewParamsServiceTier = "scale"
	ChatCompletionNewParamsServiceTierPriority ChatCompletionNewParamsServiceTier = "priority"
)

// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatCompletionNewParamsStopUnion struct {
	OfString      param.Opt[string] `json:",omitzero,inline"`
	OfStringArray []string          `json:",omitzero,inline"`
	paramUnion
}

func (u ChatCompletionNewParamsStopUnion) MarshalJSON() ([]byte, error) {
	return param.MarshalUnion(u, u.OfString, u.OfStringArray)
}
func (u *ChatCompletionNewParamsStopUnion) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, u)
}

func (u *ChatCompletionNewParamsStopUnion) asAny() any {
	if !param.IsOmitted(u.OfString) {
		return &u.OfString.Value
	} else if !param.IsOmitted(u.OfStringArray) {
		return &u.OfStringArray
	}
	return nil
}

// Constrains the verbosity of the model's response. Lower values will result in
// more concise responses, while higher values will result in more verbose
// responses. Currently supported values are `low`, `medium`, and `high`.
type ChatCompletionNewParamsVerbosity string

const (
	ChatCompletionNewParamsVerbosityLow    ChatCompletionNewParamsVerbosity = "low"
	ChatCompletionNewParamsVerbosityMedium ChatCompletionNewParamsVerbosity = "medium"
	ChatCompletionNewParamsVerbosityHigh   ChatCompletionNewParamsVerbosity = "high"
)

// This tool searches the web for relevant results to use in a response. Learn more
// about the
// [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
type ChatCompletionNewParamsWebSearchOptions struct {
	// Approximate location parameters for the search.
	UserLocation ChatCompletionNewParamsWebSearchOptionsUserLocation `json:"user_location,omitzero"`
	// High level guidance for the amount of context window space to use for the
	// search. One of `low`, `medium`, or `high`. `medium` is the default.
	//
	// Any of "low", "medium", "high".
	SearchContextSize string `json:"search_context_size,omitzero"`
	paramObj
}

func (r ChatCompletionNewParamsWebSearchOptions) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNewParamsWebSearchOptions
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNewParamsWebSearchOptions) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

func init() {
	apijson.RegisterFieldValidator[ChatCompletionNewParamsWebSearchOptions](
		"search_context_size", "low", "medium", "high",
	)
}

// Approximate location parameters for the search.
//
// The properties Approximate, Type are required.
type ChatCompletionNewParamsWebSearchOptionsUserLocation struct {
	// Approximate location parameters for the search.
	Approximate ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate `json:"approximate,omitzero" api:"required"`
	// The type of location approximation. Always `approximate`.
	//
	// This field can be elided, and will marshal its zero value as "approximate".
	Type constant.Approximate `json:"type" default:"approximate"`
	paramObj
}

func (r ChatCompletionNewParamsWebSearchOptionsUserLocation) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNewParamsWebSearchOptionsUserLocation
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNewParamsWebSearchOptionsUserLocation) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

// Approximate location parameters for the search.
type ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate struct {
	// Free text input for the city of the user, e.g. `San Francisco`.
	City param.Opt[string] `json:"city,omitzero"`
	// The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of
	// the user, e.g. `US`.
	Country param.Opt[string] `json:"country,omitzero"`
	// Free text input for the region of the user, e.g. `California`.
	Region param.Opt[string] `json:"region,omitzero"`
	// The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the
	// user, e.g. `America/Los_Angeles`.
	Timezone param.Opt[string] `json:"timezone,omitzero"`
	paramObj
}

func (r ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

type ChatCompletionUpdateParams struct {
	// Set of 16 key-value pairs that can be attached to an object. This can be useful
	// for storing additional information about the object in a structured format, and
	// querying for objects via API or the dashboard.
	//
	// Keys are strings with a maximum length of 64 characters. Values are strings with
	// a maximum length of 512 characters.
	Metadata shared.Metadata `json:"metadata,omitzero" api:"required"`
	paramObj
}

func (r ChatCompletionUpdateParams) MarshalJSON() (data []byte, err error) {
	type shadow ChatCompletionUpdateParams
	return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatCompletionUpdateParams) UnmarshalJSON(data []byte) error {
	return apijson.UnmarshalRoot(data, r)
}

type ChatCompletionListParams struct {
	// Identifier for the last chat completion from the previous pagination request.
	After param.Opt[string] `query:"after,omitzero" json:"-"`
	// Number of Chat Completions to retrieve.
	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
	// The model used to generate the Chat Completions.
	Model param.Opt[string] `query:"model,omitzero" json:"-"`
	// A list of metadata keys to filter the Chat Completions by. Example:
	//
	// `metadata[key1]=value1&metadata[key2]=value2`
	Metadata shared.Metadata `query:"metadata,omitzero" json:"-"`
	// Sort order for Chat Completions by timestamp. Use `asc` for ascending order or
	// `desc` for descending order. Defaults to `asc`.
	//
	// Any of "asc", "desc".
	Order ChatCompletionListParamsOrder `query:"order,omitzero" json:"-"`
	paramObj
}

// URLQuery serializes [ChatCompletionListParams]'s query parameters as
// `url.Values`.
func (r ChatCompletionListParams) URLQuery() (v url.Values, err error) {
	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
		ArrayFormat:  apiquery.ArrayQueryFormatBrackets,
		NestedFormat: apiquery.NestedQueryFormatBrackets,
	})
}

// Sort order for Chat Completions by timestamp. Use `asc` for ascending order or
// `desc` for descending order. Defaults to `asc`.
type ChatCompletionListParamsOrder string

const (
	ChatCompletionListParamsOrderAsc  ChatCompletionListParamsOrder = "asc"
	ChatCompletionListParamsOrderDesc ChatCompletionListParamsOrder = "desc"
)
