# generated by datamodel-codegen:
#   filename:  openai.yaml (subset for Chat Completions)
#   timestamp: 2025-04-10T17:23:37+00:00

from __future__ import annotations

from typing import Dict, List, Literal, Optional, Union

from pydantic import AnyUrl, BaseModel, ConfigDict, Field, RootModel


class FunctionDefinition(BaseModel):
    name: str = Field(..., description="The name of the function to call.")


class AssistantsNamedToolChoice(BaseModel):
    type: str = Field(
        ...,
        description="The type of the tool. If type is `function`, the function name must be set. Possible values: ['function', 'code_interpreter', 'file_search']",
    )
    function: FunctionDefinition | None = None


class ChatCompletionFunctionCallOption(FunctionDefinition):
    pass


class ChatCompletionDeleted(BaseModel):
    object: str = Field(
        ...,
        description="The type of object being deleted. Possible values: ['list', 'assistant', 'chat.completion.deleted', 'chat.completion', 'chat.completion.chunk']",
    )
    id: str = Field(..., description="The ID of the chat completion that was deleted.")
    deleted: bool = Field(..., description="Whether the chat completion was deleted.")


class FunctionCall(BaseModel):
    name: str = Field(..., description="The name of the function to call.")
    arguments: str = Field(
        ...,
        description="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.",
    )


class ChatCompletionMessageToolCall(BaseModel):
    id: str = Field(..., description="The ID of the tool call.")
    type: Literal["function"] = Field(
        ...,
        description="The type of the tool. Currently, only `function` is supported.",
    )
    function: FunctionCall = Field(
        ..., description="The function that the model called."
    )


class FunctionCallChunk(BaseModel):
    name: str | None = Field(None, description="The name of the function to call.")
    arguments: str | None = Field(
        None,
        description="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.",
    )


class ChatCompletionMessageToolCallChunk(BaseModel):
    index: int
    id: str | None = Field(None, description="The ID of the tool call.")
    type: Literal["function"] | None = Field(
        None,
        description="The type of the tool. Currently, only `function` is supported.",
    )
    function: FunctionCallChunk | None = None


class ChatCompletionMessageToolCalls(RootModel[List[ChatCompletionMessageToolCall]]):
    root: List[ChatCompletionMessageToolCall] = Field(
        ...,
        description="The tool calls generated by the model, such as function calls.",
    )


class ChatCompletionModalities(RootModel[List[str] | None]):
    root: List[str] | None = Field(
        None,
        description='Output types that you would like the model to generate for this request.\\nMost models are capable of generating text, which is the default:\\n\\n`["text"]`\\n\\nThe `gpt-4o-audio-preview` model can also be used to [generate audio](/docs/guides/audio). To\\nrequest that this model generate both text and audio responses, you can\\nuse:\\n\\n`["text", "audio"]`\\n\'. Possible values: [\'text\', \'audio\']',
    )


class ChatCompletionNamedToolChoice(BaseModel):
    type: Literal["function"] = Field(
        ...,
        description="The type of the tool. Currently, only `function` is supported.",
    )
    function: FunctionDefinition


class AudioInputData(BaseModel):
    id: str = Field(
        ...,
        description="Unique identifier for a previous audio response from the model.\n",
    )


class ResponseFunctionCall(BaseModel):
    arguments: str = Field(
        ...,
        description="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.",
    )
    name: str = Field(..., description="The name of the function to call.")


class ChatCompletionRequestFunctionMessage(BaseModel):
    role: Literal["function"] = Field(
        ..., description="The role of the messages author, in this case `function`."
    )
    content: str = Field(..., description="The contents of the function message.")
    name: str = Field(..., description="The name of the function to call.")


class InputAudio(BaseModel):
    data: str = Field(..., description="Base64 encoded audio data.")
    format: str = Field(
        ...,
        description="The format of the encoded audio data. Currently supports \"wav\" and \"mp3\".\\n'. Possible values: ['wav', 'mp3']",
    )


class ChatCompletionRequestMessageContentPartAudio(BaseModel):
    type: str = Field(
        ..., description="The type of the content part. Always `input_audio`."
    )
    input_audio: InputAudio


class FileData(BaseModel):
    filename: str | None = Field(
        None,
        description="The name of the file, used when passing the file to the model as a \nstring.\n",
    )
    file_data: str | None = Field(
        None,
        description="The base64 encoded file data, used when passing the file to the model \nas a string.\n",
    )
    file_id: str | None = Field(
        None, description="The ID of an uploaded file to use as input.\n"
    )


class ChatCompletionRequestMessageContentPartFile(BaseModel):
    type: str = Field(..., description="The type of the content part. Always `file`.")
    file: FileData


class ImageUrl(BaseModel):
    url: AnyUrl = Field(
        ..., description="Either a URL of the image or the base64 encoded image data."
    )
    detail: str | None = Field(
        "auto",
        description="Specifies the detail level of the image. Learn more in the [Vision guide](/docs/guides/vision#low-or-high-fidelity-image-understanding). Possible values: ['auto', 'low', 'high']",
    )


class ChatCompletionRequestMessageContentPartImage(BaseModel):
    type: str = Field(
        ..., description="The type of the content part. Always `image_url`."
    )
    image_url: ImageUrl


class ChatCompletionRequestMessageContentPartRefusal(BaseModel):
    type: str = Field(
        ..., description="The type of the content part. Always `refusal`."
    )
    refusal: str = Field(..., description="The refusal message generated by the model.")


class ChatCompletionRequestMessageContentPartText(BaseModel):
    type: str = Field(..., description="The type of the content part. Always `text`.")
    text: str = Field(..., description="The text content.")


class ChatCompletionRequestSystemMessageContentPart(
    RootModel[ChatCompletionRequestMessageContentPartText]
):
    root: ChatCompletionRequestMessageContentPartText


class ChatCompletionRequestToolMessageContentPart(
    ChatCompletionRequestSystemMessageContentPart
):
    pass


class ChatCompletionRequestUserMessageContentPart(
    RootModel[
        Union[
            ChatCompletionRequestMessageContentPartText,
            ChatCompletionRequestMessageContentPartImage,
            ChatCompletionRequestMessageContentPartAudio,
            ChatCompletionRequestMessageContentPartFile,
        ]
    ]
):
    root: Union[
        ChatCompletionRequestMessageContentPartText,
        ChatCompletionRequestMessageContentPartImage,
        ChatCompletionRequestMessageContentPartAudio,
        ChatCompletionRequestMessageContentPartFile,
    ]


class ChatCompletionRequestAssistantMessageContentPart(
    RootModel[
        Union[
            ChatCompletionRequestMessageContentPartText,
            ChatCompletionRequestMessageContentPartRefusal,
        ]
    ]
):
    root: Union[
        ChatCompletionRequestMessageContentPartText,
        ChatCompletionRequestMessageContentPartRefusal,
    ]


class ChatCompletionRequestDeveloperMessageContent(
    RootModel[List[ChatCompletionRequestMessageContentPartText]]
):
    root: List[ChatCompletionRequestMessageContentPartText] = Field(
        ...,
        description="An array of content parts with a defined type. For developer messages, only type `text` is supported.",
        min_length=1,
        title="Array of content parts",
    )


class ChatCompletionRequestDeveloperMessage(BaseModel):
    content: Union[str, ChatCompletionRequestDeveloperMessageContent] = Field(
        ..., description="The contents of the developer message."
    )
    role: Literal["developer"] = Field(
        ..., description="The role of the messages author, in this case `developer`."
    )
    name: str | None = Field(
        None,
        description="An optional name for the participant. Provides the model information to differentiate between participants of the same role.",
    )


class ChatCompletionRequestSystemMessageContent(
    RootModel[List[ChatCompletionRequestSystemMessageContentPart]]
):
    root: List[ChatCompletionRequestSystemMessageContentPart] = Field(
        ...,
        description="An array of content parts with a defined type. For system messages, only type `text` is supported.",
        min_length=1,
        title="Array of content parts",
    )


class ChatCompletionRequestSystemMessage(BaseModel):
    content: Union[str, ChatCompletionRequestSystemMessageContent] = Field(
        ..., description="The contents of the system message."
    )
    role: Literal["system"] = Field(
        ..., description="The role of the messages author, in this case `system`."
    )
    name: str | None = Field(
        None,
        description="An optional name for the participant. Provides the model information to differentiate between participants of the same role.",
    )


class ChatCompletionRequestToolMessageContent(
    RootModel[List[ChatCompletionRequestToolMessageContentPart]]
):
    root: List[ChatCompletionRequestToolMessageContentPart] = Field(
        ...,
        description="An array of content parts with a defined type. For tool messages, only type `text` is supported.",
        min_length=1,
        title="Array of content parts",
    )


class ChatCompletionRequestToolMessage(BaseModel):
    role: Literal["tool"] = Field(
        ..., description="The role of the messages author, in this case `tool`."
    )
    content: Union[str, ChatCompletionRequestToolMessageContent] = Field(
        ..., description="The contents of the tool message."
    )
    tool_call_id: str = Field(
        ..., description="Tool call that this message is responding to."
    )


class ChatCompletionRequestUserMessageContent(
    RootModel[List[ChatCompletionRequestUserMessageContentPart]]
):
    root: List[ChatCompletionRequestUserMessageContentPart] = Field(
        ...,
        description="An array of content parts with a defined type. Supported options differ based on the [model](/docs/models) being used to generate the response. Can contain text, image, or audio inputs.",
        min_length=1,
        title="Array of content parts",
    )


class ChatCompletionRequestUserMessage(BaseModel):
    content: Union[str, ChatCompletionRequestUserMessageContent] = Field(
        ..., description="The contents of the user message.\n"
    )
    role: Literal["user"] = Field(
        ..., description="The role of the messages author, in this case `user`."
    )
    name: str | None = Field(
        None,
        description="An optional name for the participant. Provides the model information to differentiate between participants of the same role.",
    )


class ChatCompletionRequestAssistantMessageContent(
    RootModel[List[ChatCompletionRequestAssistantMessageContentPart] | None]
):
    root: List[ChatCompletionRequestAssistantMessageContentPart] | None = Field(
        None,
        description="An array of content parts with a defined type. Can be one or more of type `text`, or exactly one of type `refusal`.",
        min_length=1,
        title="Array of content parts",
    )


class ChatCompletionRequestAssistantMessage(BaseModel):
    content: Union[str, ChatCompletionRequestAssistantMessageContent, None] = Field(
        None,
        description="The contents of the assistant message. Required unless `tool_calls` or `function_call` is specified.\n",
    )
    refusal: str | None = Field(
        None, description="The refusal message by the assistant."
    )
    role: Literal["assistant"] = Field(
        ..., description="The role of the messages author, in this case `assistant`."
    )
    name: str | None = Field(
        None,
        description="An optional name for the participant. Provides the model information to differentiate between participants of the same role.",
    )
    audio: AudioInputData | None = Field(
        None,
        description="Data about a previous audio response from the model. \n[Learn more](/docs/guides/audio).\n",
    )
    tool_calls: ChatCompletionMessageToolCalls | None = None
    function_call: ResponseFunctionCall | None = Field(  # Changed from FunctionCall
        None,
        description="Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model.",
    )


class ChatCompletionRequestMessage(
    RootModel[
        Union[
            ChatCompletionRequestDeveloperMessage,
            ChatCompletionRequestSystemMessage,
            ChatCompletionRequestUserMessage,
            ChatCompletionRequestAssistantMessage,
            ChatCompletionRequestToolMessage,
            ChatCompletionRequestFunctionMessage,
        ]
    ]
):
    root: Union[
        ChatCompletionRequestDeveloperMessage,
        ChatCompletionRequestSystemMessage,
        ChatCompletionRequestUserMessage,
        ChatCompletionRequestAssistantMessage,
        ChatCompletionRequestToolMessage,
        ChatCompletionRequestFunctionMessage,
    ]


class FunctionParameters(BaseModel):
    pass
    model_config = ConfigDict(
        extra="allow",
    )


class FunctionObject(BaseModel):
    description: str | None = Field(
        None,
        description="A description of what the function does, used by the model to choose when and how to call the function.",
    )
    name: str = Field(
        ...,
        description="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.",
    )
    parameters: FunctionParameters | None = None
    strict: bool | None = Field(
        False,
        description="Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the `parameters` field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn more about Structured Outputs in the [function calling guide](docs/guides/function-calling).",
    )


class ChatCompletionTool(BaseModel):
    type: Literal["function"] = Field(
        ...,
        description="The type of the tool. Currently, only `function` is supported.",
    )
    function: FunctionObject


class ChatCompletionFunctions(BaseModel):
    description: str | None = Field(
        None,
        description="A description of what the function does, used by the model to choose when and how to call the function.",
    )
    name: str = Field(
        ...,
        description="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.",
    )
    parameters: FunctionParameters | None = None


class PredictionContentText(
    RootModel[List[ChatCompletionRequestMessageContentPartText]]
):
    root: List[ChatCompletionRequestMessageContentPartText] = Field(
        ...,
        description="An array of content parts with a defined type. Supported options differ based on the [model](/docs/models) being used to generate the response. Can contain text inputs.",
        min_length=1,
        title="Array of content parts",
    )


class PredictionContent(BaseModel):
    type: str = Field(
        ...,
        description="The type of the predicted content you want to provide. This type is\ncurrently always `content`.\n. Possible values: ['content']",
    )
    content: Union[str, PredictionContentText] = Field(
        ...,
        description="The content that should be matched when generating a model response.\nIf generated tokens would match this content, the entire model response\ncan be returned much more quickly.\n",
    )


class ResponseFormatJsonObject(BaseModel):
    type: Literal["json_object"] = Field(
        ...,
        description="The type of response format being defined. Always `json_object`.",
    )


class ResponseFormatJsonSchemaSchema(FunctionParameters):
    pass


class ResponseFormatText(BaseModel):
    type: Literal["text"] = Field(
        ..., description="The type of response format being defined. Always `text`."
    )


class JsonSchemaDefinition(BaseModel):
    description: str | None = Field(
        None,
        description="A description of what the response format is for, used by the model to\ndetermine how to respond in the format.\n",
    )
    name: str | None = Field(  # Make optional as per TextResponseFormatJsonSchema
        None,
        description="The name of the response format. Must be a-z, A-Z, 0-9, or contain\nunderscores and dashes, with a maximum length of 64.\n",
    )
    schema_: ResponseFormatJsonSchemaSchema = Field(..., alias="schema")
    strict: bool | None = Field(
        False,
        description="Whether to enable strict schema adherence when generating the output.\nIf set to true, the model will always follow the exact schema defined\nin the `schema` field. Only a subset of JSON Schema is supported when\n`strict` is `true`. To learn more, read the [Structured Outputs\nguide](/docs/guides/structured-outputs).\n",
    )


class ResponseFormatJsonSchema(BaseModel):
    type: Literal["json_schema"] = Field(
        ...,
        description="The type of response format being defined. Always `json_schema`.",
    )
    json_schema: JsonSchemaDefinition = Field(
        ...,
        description="Structured Outputs configuration options, including a JSON Schema.\n",
        title="JSON schema",
    )


class StopConfigurationItem(RootModel[List[str] | None]):
    root: List[str] | None = Field(
        None,
        description="Up to 4 sequences where the API will stop generating further tokens. The\nreturned text will not contain the stop sequence.\n",
        max_length=4,
        min_length=1,
    )


class StopConfiguration(RootModel[Union[str, StopConfigurationItem, None]]):
    root: Union[str, StopConfigurationItem, None] = Field(
        None,
        description="Up to 4 sequences where the API will stop generating further tokens. The\nreturned text will not contain the stop sequence.\n",
    )


class ModelIdsShared(RootModel[str]):
    root: str = Field(..., examples=["gpt-4o"])


class WebSearchLocation(BaseModel):
    country: str | None = Field(
        None,
        description="The two-letter \n[ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of the user,\ne.g. `US`.\n",
    )
    region: str | None = Field(
        None,
        description="Free text input for the region of the user, e.g. `California`.\n",
    )
    city: str | None = Field(
        None,
        description="Free text input for the city of the user, e.g. `San Francisco`.\n",
    )
    timezone: str | None = Field(
        None,
        description="The [IANA timezone](https://timeapi.io/documentation/iana-timezones) \nof the user, e.g. `America/Los_Angeles`.\n",
    )


class UserLocation(BaseModel):
    type: str = Field(
        ...,
        description="The type of location approximation. Always `approximate`.\n"
        " Possible values: ['approximate']",
    )
    approximate: WebSearchLocation


class WebSearchOptions(BaseModel):
    user_location: UserLocation | None = Field(
        None, description="Approximate location parameters for the search.\n"
    )
    search_context_size: str | None = (
        "medium"  # Possible values: ['low', 'medium', 'high']
    )


class VoiceIdsShared(RootModel[str]):
    root: str = Field(..., examples=["ash"])


class AudioOutputSettings(BaseModel):
    voice: VoiceIdsShared = Field(
        ...,
        description="The voice the model uses to respond. Supported voices are \n`alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, and `shimmer`.\n",
    )
    format: str = Field(
        ...,
        description="Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`,\n`opus`, or `pcm16`.\n. Possible values: ['wav', 'mp3', 'flac', 'opus', 'pcm16']",
    )


class ParallelToolCalls(RootModel[bool]):
    root: bool = Field(
        ...,
        description="Whether to enable [parallel function calling](/docs/guides/function-calling#configuring-parallel-function-calling) during tool use.",
    )


class ModelResponseProperties(BaseModel):
    metadata: Dict[str, str] | None = (
        None  # Added based on CreateModelResponseProperties
    )
    temperature: float | None = Field(
        1.0,
        description="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.\nWe generally recommend altering this or `top_p` but not both.\n",
        examples=[1],
        ge=0.0,
        le=2.0,
    )
    top_p: float | None = Field(
        1.0,
        description="An alternative to sampling with temperature, called nucleus sampling,\nwhere the model considers the results of the tokens with top_p probability\nmass. So 0.1 means only the tokens comprising the top 10% probability mass\nare considered.\n\nWe generally recommend altering this or `temperature` but not both.\n",
        examples=[1],
        ge=0.0,
        le=1.0,
    )
    user: str | None = Field(
        None,
        description="A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices#end-user-ids).\n",
        examples=["user-1234"],
    )


class ChatCompletionRequest(ModelResponseProperties):
    messages: List[ChatCompletionRequestMessage] = Field(
        ...,
        description="A list of messages comprising the conversation so far. Depending on the\n[model](/docs/models) you use, different message types (modalities) are\nsupported, like [text](/docs/guides/text-generation),\n[images](/docs/guides/vision), and [audio](/docs/guides/audio).\n",
        min_length=1,
    )
    model: str = Field(
        ...,
        description="Model ID used to generate the response, like `gpt-4o` or `o1`. OpenAI\noffers a wide range of models with different capabilities, performance\ncharacteristics, and price points. Refer to the [model guide](/docs/models)\nto browse and compare available models.\n",
    )
    modalities: ChatCompletionModalities | None = None
    reasoning_effort: str | None = (
        "medium"  # Possible values: ['low', 'medium', 'high']
    )
    max_completion_tokens: int | None = Field(
        None,
        description="An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and [reasoning tokens](/docs/guides/reasoning).\n",
    )
    frequency_penalty: float | None = Field(
        0.0,
        description="Number between -2.0 and 2.0. Positive values penalize new tokens based on\ntheir existing frequency in the text so far, decreasing the model's\nlikelihood to repeat the same line verbatim.\n",
        ge=-2.0,
        le=2.0,
    )
    presence_penalty: float | None = Field(
        0.0,
        description="Number between -2.0 and 2.0. Positive values penalize new tokens based on\nwhether they appear in the text so far, increasing the model's likelihood\nto talk about new topics.\n",
        ge=-2.0,
        le=2.0,
    )
    web_search_options: WebSearchOptions | None = Field(
        None,
        description="This tool searches the web for relevant results to use in a response.\nLearn more about the [web search tool](/docs/guides/tools-web-search?api-mode=chat).\n",
        title="Web search",
    )
    top_logprobs: int | None = Field(
        None,
        description="An integer between 0 and 20 specifying the number of most likely tokens to\nreturn at each token position, each with an associated log probability.\n`logprobs` must be set to `true` if this parameter is used.\n",
        ge=0,
        le=20,
    )
    response_format: Union[
        ResponseFormatText, ResponseFormatJsonSchema, ResponseFormatJsonObject, None
    ] = Field(
        None,
        description='An object specifying the format that the model must output.\n\nSetting to `{ "type": "json_schema", "json_schema": {...} }` enables\nStructured Outputs which ensures the model will match your supplied JSON\nschema. Learn more in the [Structured Outputs\nguide](/docs/guides/structured-outputs).\n\nSetting to `{ "type": "json_object" }` enables the older JSON mode, which\nensures the message the model generates is valid JSON. Using `json_schema`\nis preferred for models that support it.\n',
    )
    service_tier: str | None = Field(
        "auto",
        description="Specifies the latency tier to use for processing the request. This parameter is relevant for customers subscribed to the scale tier service:\n  - If set to 'auto', and the Project is Scale tier enabled, the system\n    will utilize scale tier credits until they are exhausted.\n  - If set to 'auto', and the Project is not Scale tier enabled, the request will be processed using the default service tier with a lower uptime SLA and no latency guarentee.\n  - If set to 'default', the request will be processed using the default service tier with a lower uptime SLA and no latency guarentee.\n  - When not set, the default behavior is 'auto'.\n\n  When this parameter is set, the response body will include the `service_tier` utilized.\n"
        + " Possible values: ['scale', 'default', 'auto']",
    )
    audio: AudioOutputSettings | None = Field(
        None,
        description='Parameters for audio output. Required when audio output is requested with\n`modalities: ["audio"]`. [Learn more](/docs/guides/audio).\n',
    )
    store: bool | None = Field(
        False,
        description="Whether or not to store the output of this chat completion request for \nuse in our [model distillation](/docs/guides/distillation) or\n[evals](/docs/guides/evals) products.\n",
    )
    stream: bool | None = Field(
        False,
        description="If set to true, the model response data will be streamed to the client\nas it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\nSee the [Streaming section below](/docs/api-reference/chat/streaming)\nfor more information, along with the [streaming responses](/docs/guides/streaming-responses)\nguide for more information on how to handle the streaming events.\n",
    )
    stop: StopConfiguration | None = None
    logit_bias: Dict[str, int] | None = Field(
        None,
        description="Modify the likelihood of specified tokens appearing in the completion.\n\nAccepts a JSON object that maps tokens (specified by their token ID in the\ntokenizer) to an associated bias value from -100 to 100. Mathematically,\nthe bias is added to the logits generated by the model prior to sampling.\nThe exact effect will vary per model, but values between -1 and 1 should\ndecrease or increase likelihood of selection; values like -100 or 100\nshould result in a ban or exclusive selection of the relevant token.\n",
    )
    logprobs: bool | None = Field(
        False,
        description="Whether to return log probabilities of the output tokens or not. If true,\nreturns the log probabilities of each output token returned in the\n`content` of `message`.\\n",
    )
    max_tokens: int | None = Field(
        None,
        description="The maximum number of [tokens](/tokenizer) that can be generated in the\nchat completion. This value can be used to control\n[costs](https://openai.com/api/pricing/) for text generated via API.\\n\\nThis value is now deprecated in favor of `max_completion_tokens`, and is\\nnot compatible with [o1 series models](/docs/guides/reasoning).\\n",
    )
    n: int | None = Field(
        1,
        description="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.",
        examples=[1],
        ge=1,
        le=128,
    )
    prediction: PredictionContent | None = Field(
        None,
        description="Configuration for a [Predicted Output](/docs/guides/predicted-outputs),\nwhich can greatly improve response times when large parts of the model\nresponse are known ahead of time. This is most common when you are\\nregenerating a file with only minor changes to most of the content.\\n",
    )
    seed: int | None = Field(
        None,
        description="This feature is in Beta.\\nIf 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.\\nDeterminism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.\\n",
    )
    stream_options: ChatCompletionStreamOptions | None = None
    tools: List[ChatCompletionTool] | None = Field(
        None,
        description="A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.\\n",
    )
    tool_choice: ChatCompletionToolChoiceOption | None = None
    parallel_tool_calls: ParallelToolCalls | None = Field(
        default_factory=lambda: ParallelToolCalls.model_validate(True)
    )
    function_call: Union[str, ChatCompletionFunctionCallOption, None] = Field(
        None,
        description="Deprecated in favor of `tool_choice`.\\n\\nControls which (if any) function is called by the model.\\n\\n`none` means the model will not call a function and instead generates a\\nmessage.\\n\\n`auto` means the model can pick between generating a message or calling a\\nfunction.\\n\\nSpecifying a particular function via `{\"name\": \"my_function\"}` forces the\\nmodel to call that function.\\n\\n`none` is the default when no functions are present. `auto` is the default\\nif functions are present.\\n'. Possible values for string: ['none', 'auto']",
    )
    functions: List[ChatCompletionFunctions] | None = Field(
        None,
        description="Deprecated in favor of `tools`.\\n\\nA list of functions the model may generate JSON inputs for.\\n",
        max_length=128,
        min_length=1,
    )


# Insert missing class definition
class ChatCompletionStreamOptions(BaseModel):
    include_usage: bool | None = Field(
        None,
        description="If set, an additional chunk will be streamed before the `data: [DONE]`\\\\\\\\nmessage. The `usage` field on this chunk shows the token usage statistics\\\\\\\\nfor the entire request, and the `choices` field will always be an empty\\\\\\\\narray. \\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\nAll other chunks will also include a `usage` field, but with a null\\\\\\\\\\\\\\\\\\\\\\\\nvalue. **NOTE:** If the stream is interrupted, you may not receive the\\\\\\\\\\\\\\\\\\\\\\\\nfinal usage chunk which contains the total token usage for the request.\\\\\\\\\\\\\\\\\\\\\\\\n",
    )


class ChatCompletionToolChoiceOption(
    RootModel[Union[str, ChatCompletionNamedToolChoice]]
):
    root: Union[str, ChatCompletionNamedToolChoice] = Field(
        ...,
        description=(
            'Controls which (if any) tool is called by the model.\\n`none` means the model will not call a function and instead generates a message.\\n`auto` means the model can pick between generating a message or calling one or more tools.\\n`required` means the model must call one or more tools.\\nSpecifying a particular tool via `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool.\\n\\n`none` is the default when no tools are present. `auto` is the default if tools are present.\\n'
            " Possible values for string: ['none', 'auto', 'required']"
        ),
    )


class CompletionUsage(BaseModel):
    completion_tokens: int = Field(
        ..., description="Number of tokens in the generated completion."
    )


# Re-insert ChatCompletionChoice definition
class ChatCompletionChoice(BaseModel):
    finish_reason: str | None = Field(  # Made optional as per stream response
        None,
        description="The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,\\n`length` if the maximum number of tokens specified in the request was reached,\\n`content_filter` if content was omitted due to a flag from our content filters,\\n`tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.\\n"
        + " Possible values: ['stop', 'length', 'tool_calls', 'content_filter', 'function_call']",
    )
    index: int = Field(
        ..., description="The index of the choice in the list of choices."
    )
    message: "ChatCompletionResponseMessage"
    logprobs: Union["Logprobs", None] = (
        Field(  # Made optional as per CreateChatCompletionFunctionResponse
            None, description="Log probability information for the choice."
        )
    )


# Re-insert CreateChatCompletionResponse definition
class ChatCompletionResponse(BaseModel):
    id: str = Field(..., description="A unique identifier for the chat completion.")
    choices: List[ChatCompletionChoice] = Field(
        ...,
        description="A list of chat completion choices. Can be more than one if `n` is greater than 1.",
    )
    created: int = Field(
        ...,
        description="The Unix timestamp (in seconds) of when the chat completion was created.",
    )
    model: str = Field(..., description="The model used for the chat completion.")
    service_tier: str | None = Field(
        None,
        description="The service tier used for processing the request. Possible values: ['scale', 'default', 'auto']",
        examples=["scale"],
    )
    system_fingerprint: str | None = Field(
        None,
        description="This fingerprint represents the backend configuration that the model runs with.\\n\\nCan be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.\\n",
    )
    object: Literal["chat.completion"] = Field(
        ..., description="The object type, which is always `chat.completion`."
    )
    usage: CompletionUsage | None = None


# Re-insert ChatCompletionStreamChoice definition
class ChatCompletionStreamChoice(BaseModel):
    delta: "ChatCompletionStreamResponseDelta"
    logprobs: Union["Logprobs", None] = Field(
        None, description="Log probability information for the choice."
    )
    finish_reason: str | None = Field(  # Made optional
        None,
        description="The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,\\n`length` if the maximum number of tokens specified in the request was reached,\\n`content_filter` if content was omitted due to a flag from our content filters,\\n`tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.\\n"
        + " Possible values: ['stop', 'length', 'tool_calls', 'content_filter', 'function_call']",
    )
    index: int = Field(
        ..., description="The index of the choice in the list of choices."
    )


# Re-insert CreateChatCompletionStreamResponse definition
class CreateChatCompletionStreamResponse(BaseModel):
    id: str = Field(
        ...,
        description="A unique identifier for the chat completion. Each chunk has the same ID.",
    )
    choices: List[ChatCompletionStreamChoice] = Field(
        ...,
        description=(
            "A list of chat completion choices. Can contain more than one elements if `n` is greater than 1. Can also be empty for the"
            '\\nlast chunk if you set `stream_options: {"include_usage": true}` in your request.\\n'
        ),
    )
    created: int = Field(
        ...,
        description="The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp.",
    )
    model: str = Field(..., description="The model to generate the completion.")
    service_tier: str | None = Field(
        None,
        description="The service tier used for processing the request. Possible values: ['scale', 'default', 'auto']",
        examples=["scale"],
    )
    system_fingerprint: str | None = Field(
        None,
        description="This fingerprint represents the backend configuration that the model runs with.\\nCan be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.\\n",
    )
    object: Literal["chat.completion.chunk"] = Field(
        ..., description="The object type, which is always `chat.completion.chunk`."
    )
    usage: CompletionUsage | None = Field(
        None,
        description=(
            "An optional field that will only be present when you set"
            '\\n`stream_options: {"include_usage": true}` in your request. When present, it'
            "\\ncontains a null value **except for the last chunk** which contains the"
            "\\ntoken usage statistics for the entire request.\\n\\n**NOTE:** If the stream is interrupted or cancelled, you may not"
            "\\nreceive the final usage chunk which contains the total token usage for"
            "\\nthe request.\\n"
        ),
    )


class ChatCompletionList(BaseModel):
    object: Literal["list"] = Field(
        ...,
        description="The type of object being deleted. Possible values: ['list']",
    )


# Add remaining missing definitions
class UrlCitationAnnotationData(BaseModel):
    end_index: int = Field(
        ...,
        description="The index of the last character of the URL citation in the message.",
    )
    start_index: int = Field(
        ...,
        description="The index of the first character of the URL citation in the message.",
    )
    url: str = Field(..., description="The URL of the web resource.")
    title: str = Field(..., description="The title of the web resource.")


class UrlCitationAnnotation(BaseModel):
    type: str = Field(
        ..., description="The type of the URL citation. Always `url_citation`."
    )
    url_citation: UrlCitationAnnotationData = Field(
        ..., description="A URL citation when using web search."
    )


class AudioResponseData(BaseModel):
    id: str = Field(..., description="Unique identifier for this audio response.")
    expires_at: int = Field(
        ...,
        description="The Unix timestamp (in seconds) for when this audio response will\\nno longer be accessible on the server for use in multi-turn\\nconversations.\\n",
    )
    data: str = Field(
        ...,
        description="Base64 encoded audio bytes generated by the model, in the format\\nspecified in the request.\\n",
    )
    transcript: str = Field(
        ..., description="Transcript of the audio generated by the model."
    )


class TopLogprob(BaseModel):
    token: str = Field(..., description="The token.")
    logprob: float = Field(
        ...,
        description="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.",
    )
    bytes: List[int] | None = Field(
        ...,
        description="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.",
    )


class PromptTokensDetails(BaseModel):
    audio_tokens: int | None = Field(
        0, description="Audio input tokens present in the prompt."
    )
    cached_tokens: int | None = Field(
        0, description="Cached tokens present in the prompt."
    )


class ChatCompletionStreamResponseDelta(BaseModel):
    content: str | None = Field(None, description="The contents of the chunk message.")
    function_call: FunctionCallChunk | None = Field(
        None,
        description="Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model.",
    )
    tool_calls: List[ChatCompletionMessageToolCallChunk] | None = None
    role: str | None = Field(
        None,
        description="The role of the author of this message."
        " Possible values: ['developer', 'function', 'system', 'tool', 'user', 'assistant']",
    )
    refusal: str | None = Field(
        None, description="The refusal message generated by the model."
    )


class CompletionTokensDetails(BaseModel):
    accepted_prediction_tokens: int | None = Field(
        0,
        description="The number of tokens accepted from the prediction. This is the number of tokens that were generated by the model and accepted by the system as part of the prediction process.",
    )

    rejected_prediction_tokens: int | None = Field(
        0,
        description="The number of tokens rejected from the prediction. This is the number of tokens that were generated by the model but rejected by the system as part of the prediction process. This can happen due to various reasons such as content filters, token limits, or other constraints.",
    )


class Logprobs(BaseModel):
    content: List["ChatCompletionTokenLogprob"] | None = Field(  # Made optional
        None, description="Log probability information for the choice."
    )


# Insert missing ChatCompletionResponseMessage definition
class ChatCompletionResponseMessage(BaseModel):
    content: Optional[str] = Field(None, description="The contents of the message.")
    refusal: Optional[str] = Field(
        None, description="The refusal message generated by the model."
    )
    tool_calls: Optional[ChatCompletionMessageToolCalls] = None
    annotations: Optional[List[UrlCitationAnnotation]] = Field(
        None,
        description="Annotations for the message, when applicable, as when using the\\\\n[web search tool](/docs/guides/tools-web-search?api-mode=chat).\\\\n",
    )
    role: Literal["assistant"] = Field(
        ..., description="The role of the author of this message."
    )
    function_call: Optional[ResponseFunctionCall] = Field(
        None,
        description="Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model.",
    )
    audio: Optional[AudioResponseData] = Field(
        None,
        description="If the audio output modality is requested, this object contains data\\\\\\\\nabout the audio response from the model. [Learn more](/docs/guides/audio).\\\\\\\\n",
    )


# Insert missing ChatCompletionTokenLogprob definition
class ChatCompletionTokenLogprob(BaseModel):
    token: str = Field(..., description="The token.")
    logprob: float = Field(
        ...,
        description="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.",
    )
    bytes: List[int] | None = Field(
        ...,
        description="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.",
    )
    top_logprobs: List["TopLogprob"] = Field(
        ...,
        description="List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested `top_logprobs` returned.",
    )
