from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, cast

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..models.llm_chat_openai_config_modalities_type_0_item import LlmChatOpenaiConfigModalitiesType0Item
from ..models.llm_chat_openai_config_model_type_0 import LlmChatOpenaiConfigModelType0
from ..models.llm_chat_openai_config_model_type_1 import LlmChatOpenaiConfigModelType1
from ..models.llm_chat_openai_config_prompt_cache_retention_type_0 import LlmChatOpenaiConfigPromptCacheRetentionType0
from ..models.llm_chat_openai_config_provider import LlmChatOpenaiConfigProvider
from ..models.llm_chat_openai_config_reasoning_effort_type_0 import LlmChatOpenaiConfigReasoningEffortType0
from ..models.llm_chat_openai_config_service_tier_type_0 import LlmChatOpenaiConfigServiceTierType0
from ..models.llm_chat_openai_config_tool_choice_type_0 import LlmChatOpenaiConfigToolChoiceType0
from ..models.llm_chat_openai_config_verbosity_type_0 import LlmChatOpenaiConfigVerbosityType0
from ..models.output_type import OutputType
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.chat_completion_allowed_tool_choice_param import ChatCompletionAllowedToolChoiceParam
    from ..models.chat_completion_assistant_message_param import ChatCompletionAssistantMessageParam
    from ..models.chat_completion_audio_param import ChatCompletionAudioParam
    from ..models.chat_completion_developer_message_param import ChatCompletionDeveloperMessageParam
    from ..models.chat_completion_function_message_param import ChatCompletionFunctionMessageParam
    from ..models.chat_completion_function_tool_param import ChatCompletionFunctionToolParam
    from ..models.chat_completion_named_tool_choice_custom_param import ChatCompletionNamedToolChoiceCustomParam
    from ..models.chat_completion_named_tool_choice_param import ChatCompletionNamedToolChoiceParam
    from ..models.chat_completion_prediction_content_param import ChatCompletionPredictionContentParam
    from ..models.chat_completion_stream_options_param import ChatCompletionStreamOptionsParam
    from ..models.chat_completion_system_message_param import ChatCompletionSystemMessageParam
    from ..models.chat_completion_tool_message_param import ChatCompletionToolMessageParam
    from ..models.chat_completion_user_message_param import ChatCompletionUserMessageParam
    from ..models.llm_chat_openai_config_extra_headers_type_0 import LlmChatOpenaiConfigExtraHeadersType0
    from ..models.llm_chat_openai_config_extra_query_type_0 import LlmChatOpenaiConfigExtraQueryType0
    from ..models.llm_chat_openai_config_json_schema_type_0 import LlmChatOpenaiConfigJsonSchemaType0
    from ..models.llm_chat_openai_config_logit_bias_type_0 import LlmChatOpenaiConfigLogitBiasType0
    from ..models.llm_chat_openai_config_metadata_type_0 import LlmChatOpenaiConfigMetadataType0
    from ..models.llm_chat_openai_config_response_schema_type_1 import LlmChatOpenaiConfigResponseSchemaType1
    from ..models.response_format_json_object import ResponseFormatJSONObject
    from ..models.response_format_json_schema import ResponseFormatJSONSchema
    from ..models.response_format_text import ResponseFormatText
    from ..models.structured_output_schema import StructuredOutputSchema
    from ..models.web_search_options import WebSearchOptions


T = TypeVar("T", bound="LlmChatOpenaiConfig")


@_attrs_define
class LlmChatOpenaiConfig:
    """
    Attributes:
        messages (list[ChatCompletionAssistantMessageParam | ChatCompletionDeveloperMessageParam |
            ChatCompletionFunctionMessageParam | ChatCompletionSystemMessageParam | ChatCompletionToolMessageParam |
            ChatCompletionUserMessageParam]):
        provider (LlmChatOpenaiConfigProvider):
        model (LlmChatOpenaiConfigModelType0 | LlmChatOpenaiConfigModelType1 | str | Unset):  Default:
            LlmChatOpenaiConfigModelType0.GPT_4_1_MINI.
        audio (ChatCompletionAudioParam | None | Unset):
        frequency_penalty (float | None | Unset):
        logit_bias (LlmChatOpenaiConfigLogitBiasType0 | None | Unset):
        logprobs (bool | None | Unset):
        max_completion_tokens (int | None | Unset):
        max_tokens (int | None | Unset):
        metadata (LlmChatOpenaiConfigMetadataType0 | None | Unset):
        modalities (list[LlmChatOpenaiConfigModalitiesType0Item] | None | Unset):
        n (int | None | Unset):  Default: 1.
        parallel_tool_calls (bool | None | Unset):
        prediction (ChatCompletionPredictionContentParam | None | Unset):
        presence_penalty (float | None | Unset):
        prompt_cache_key (None | str | Unset):
        prompt_cache_retention (LlmChatOpenaiConfigPromptCacheRetentionType0 | None | Unset):
        reasoning_effort (LlmChatOpenaiConfigReasoningEffortType0 | None | Unset):
        response_format (None | ResponseFormatJSONObject | ResponseFormatJSONSchema | ResponseFormatText | Unset):
        safety_identifier (None | str | Unset):
        seed (int | None | Unset):
        service_tier (LlmChatOpenaiConfigServiceTierType0 | None | Unset):
        stop (list[str] | None | str | Unset):
        store (bool | None | Unset):
        stream (bool | None | Unset):  Default: False.
        stream_options (ChatCompletionStreamOptionsParam | None | Unset):
        temperature (float | None | Unset):
        tool_choice (ChatCompletionAllowedToolChoiceParam | ChatCompletionNamedToolChoiceCustomParam |
            ChatCompletionNamedToolChoiceParam | LlmChatOpenaiConfigToolChoiceType0 | None | Unset):
        tools (list[ChatCompletionFunctionToolParam | str] | None | Unset):
        top_logprobs (int | None | Unset):
        top_p (float | None | Unset):
        user (None | str | Unset):
        verbosity (LlmChatOpenaiConfigVerbosityType0 | None | Unset):
        web_search_options (None | Unset | WebSearchOptions):
        output_type (None | OutputType | Unset):
        json_schema (LlmChatOpenaiConfigJsonSchemaType0 | None | Unset):
        response_schema (LlmChatOpenaiConfigResponseSchemaType1 | None | StructuredOutputSchema | Unset):
        extra_headers (LlmChatOpenaiConfigExtraHeadersType0 | None | Unset):
        extra_query (LlmChatOpenaiConfigExtraQueryType0 | None | Unset):
        extra_body (Any | None | Unset):
        timeout (float | None | Unset):  Default: 900.0.
        tool_output_text_to_file_char_limit (int | None | Unset):  Default: 75000.
    """

    messages: list[
        ChatCompletionAssistantMessageParam
        | ChatCompletionDeveloperMessageParam
        | ChatCompletionFunctionMessageParam
        | ChatCompletionSystemMessageParam
        | ChatCompletionToolMessageParam
        | ChatCompletionUserMessageParam
    ]
    provider: LlmChatOpenaiConfigProvider
    model: LlmChatOpenaiConfigModelType0 | LlmChatOpenaiConfigModelType1 | str | Unset = (
        LlmChatOpenaiConfigModelType0.GPT_4_1_MINI
    )
    audio: ChatCompletionAudioParam | None | Unset = UNSET
    frequency_penalty: float | None | Unset = UNSET
    logit_bias: LlmChatOpenaiConfigLogitBiasType0 | None | Unset = UNSET
    logprobs: bool | None | Unset = UNSET
    max_completion_tokens: int | None | Unset = UNSET
    max_tokens: int | None | Unset = UNSET
    metadata: LlmChatOpenaiConfigMetadataType0 | None | Unset = UNSET
    modalities: list[LlmChatOpenaiConfigModalitiesType0Item] | None | Unset = UNSET
    n: int | None | Unset = 1
    parallel_tool_calls: bool | None | Unset = UNSET
    prediction: ChatCompletionPredictionContentParam | None | Unset = UNSET
    presence_penalty: float | None | Unset = UNSET
    prompt_cache_key: None | str | Unset = UNSET
    prompt_cache_retention: LlmChatOpenaiConfigPromptCacheRetentionType0 | None | Unset = UNSET
    reasoning_effort: LlmChatOpenaiConfigReasoningEffortType0 | None | Unset = UNSET
    response_format: None | ResponseFormatJSONObject | ResponseFormatJSONSchema | ResponseFormatText | Unset = UNSET
    safety_identifier: None | str | Unset = UNSET
    seed: int | None | Unset = UNSET
    service_tier: LlmChatOpenaiConfigServiceTierType0 | None | Unset = UNSET
    stop: list[str] | None | str | Unset = UNSET
    store: bool | None | Unset = UNSET
    stream: bool | None | Unset = False
    stream_options: ChatCompletionStreamOptionsParam | None | Unset = UNSET
    temperature: float | None | Unset = UNSET
    tool_choice: (
        ChatCompletionAllowedToolChoiceParam
        | ChatCompletionNamedToolChoiceCustomParam
        | ChatCompletionNamedToolChoiceParam
        | LlmChatOpenaiConfigToolChoiceType0
        | None
        | Unset
    ) = UNSET
    tools: list[ChatCompletionFunctionToolParam | str] | None | Unset = UNSET
    top_logprobs: int | None | Unset = UNSET
    top_p: float | None | Unset = UNSET
    user: None | str | Unset = UNSET
    verbosity: LlmChatOpenaiConfigVerbosityType0 | None | Unset = UNSET
    web_search_options: None | Unset | WebSearchOptions = UNSET
    output_type: None | OutputType | Unset = UNSET
    json_schema: LlmChatOpenaiConfigJsonSchemaType0 | None | Unset = UNSET
    response_schema: LlmChatOpenaiConfigResponseSchemaType1 | None | StructuredOutputSchema | Unset = UNSET
    extra_headers: LlmChatOpenaiConfigExtraHeadersType0 | None | Unset = UNSET
    extra_query: LlmChatOpenaiConfigExtraQueryType0 | None | Unset = UNSET
    extra_body: Any | None | Unset = UNSET
    timeout: float | None | Unset = 900.0
    tool_output_text_to_file_char_limit: int | None | Unset = 75000
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        from ..models.chat_completion_allowed_tool_choice_param import ChatCompletionAllowedToolChoiceParam
        from ..models.chat_completion_assistant_message_param import ChatCompletionAssistantMessageParam
        from ..models.chat_completion_audio_param import ChatCompletionAudioParam
        from ..models.chat_completion_developer_message_param import ChatCompletionDeveloperMessageParam
        from ..models.chat_completion_function_tool_param import ChatCompletionFunctionToolParam
        from ..models.chat_completion_named_tool_choice_custom_param import ChatCompletionNamedToolChoiceCustomParam
        from ..models.chat_completion_named_tool_choice_param import ChatCompletionNamedToolChoiceParam
        from ..models.chat_completion_prediction_content_param import ChatCompletionPredictionContentParam
        from ..models.chat_completion_stream_options_param import ChatCompletionStreamOptionsParam
        from ..models.chat_completion_system_message_param import ChatCompletionSystemMessageParam
        from ..models.chat_completion_tool_message_param import ChatCompletionToolMessageParam
        from ..models.chat_completion_user_message_param import ChatCompletionUserMessageParam
        from ..models.llm_chat_openai_config_extra_headers_type_0 import LlmChatOpenaiConfigExtraHeadersType0
        from ..models.llm_chat_openai_config_extra_query_type_0 import LlmChatOpenaiConfigExtraQueryType0
        from ..models.llm_chat_openai_config_json_schema_type_0 import LlmChatOpenaiConfigJsonSchemaType0
        from ..models.llm_chat_openai_config_logit_bias_type_0 import LlmChatOpenaiConfigLogitBiasType0
        from ..models.llm_chat_openai_config_metadata_type_0 import LlmChatOpenaiConfigMetadataType0
        from ..models.llm_chat_openai_config_response_schema_type_1 import LlmChatOpenaiConfigResponseSchemaType1
        from ..models.response_format_json_object import ResponseFormatJSONObject
        from ..models.response_format_json_schema import ResponseFormatJSONSchema
        from ..models.response_format_text import ResponseFormatText
        from ..models.structured_output_schema import StructuredOutputSchema
        from ..models.web_search_options import WebSearchOptions

        messages = []
        for messages_item_data in self.messages:
            messages_item: dict[str, Any]
            if isinstance(messages_item_data, ChatCompletionDeveloperMessageParam):
                messages_item = messages_item_data.to_dict()
            elif isinstance(messages_item_data, ChatCompletionSystemMessageParam):
                messages_item = messages_item_data.to_dict()
            elif isinstance(messages_item_data, ChatCompletionUserMessageParam):
                messages_item = messages_item_data.to_dict()
            elif isinstance(messages_item_data, ChatCompletionAssistantMessageParam):
                messages_item = messages_item_data.to_dict()
            elif isinstance(messages_item_data, ChatCompletionToolMessageParam):
                messages_item = messages_item_data.to_dict()
            else:
                messages_item = messages_item_data.to_dict()

            messages.append(messages_item)

        provider = self.provider.value

        model: str | Unset
        if isinstance(self.model, Unset):
            model = UNSET
        elif isinstance(self.model, LlmChatOpenaiConfigModelType0):
            model = self.model.value
        elif isinstance(self.model, LlmChatOpenaiConfigModelType1):
            model = self.model.value
        else:
            model = self.model

        audio: dict[str, Any] | None | Unset
        if isinstance(self.audio, Unset):
            audio = UNSET
        elif isinstance(self.audio, ChatCompletionAudioParam):
            audio = self.audio.to_dict()
        else:
            audio = self.audio

        frequency_penalty: float | None | Unset
        if isinstance(self.frequency_penalty, Unset):
            frequency_penalty = UNSET
        else:
            frequency_penalty = self.frequency_penalty

        logit_bias: dict[str, Any] | None | Unset
        if isinstance(self.logit_bias, Unset):
            logit_bias = UNSET
        elif isinstance(self.logit_bias, LlmChatOpenaiConfigLogitBiasType0):
            logit_bias = self.logit_bias.to_dict()
        else:
            logit_bias = self.logit_bias

        logprobs: bool | None | Unset
        if isinstance(self.logprobs, Unset):
            logprobs = UNSET
        else:
            logprobs = self.logprobs

        max_completion_tokens: int | None | Unset
        if isinstance(self.max_completion_tokens, Unset):
            max_completion_tokens = UNSET
        else:
            max_completion_tokens = self.max_completion_tokens

        max_tokens: int | None | Unset
        if isinstance(self.max_tokens, Unset):
            max_tokens = UNSET
        else:
            max_tokens = self.max_tokens

        metadata: dict[str, Any] | None | Unset
        if isinstance(self.metadata, Unset):
            metadata = UNSET
        elif isinstance(self.metadata, LlmChatOpenaiConfigMetadataType0):
            metadata = self.metadata.to_dict()
        else:
            metadata = self.metadata

        modalities: list[str] | None | Unset
        if isinstance(self.modalities, Unset):
            modalities = UNSET
        elif isinstance(self.modalities, list):
            modalities = []
            for modalities_type_0_item_data in self.modalities:
                modalities_type_0_item = modalities_type_0_item_data.value
                modalities.append(modalities_type_0_item)

        else:
            modalities = self.modalities

        n: int | None | Unset
        if isinstance(self.n, Unset):
            n = UNSET
        else:
            n = self.n

        parallel_tool_calls: bool | None | Unset
        if isinstance(self.parallel_tool_calls, Unset):
            parallel_tool_calls = UNSET
        else:
            parallel_tool_calls = self.parallel_tool_calls

        prediction: dict[str, Any] | None | Unset
        if isinstance(self.prediction, Unset):
            prediction = UNSET
        elif isinstance(self.prediction, ChatCompletionPredictionContentParam):
            prediction = self.prediction.to_dict()
        else:
            prediction = self.prediction

        presence_penalty: float | None | Unset
        if isinstance(self.presence_penalty, Unset):
            presence_penalty = UNSET
        else:
            presence_penalty = self.presence_penalty

        prompt_cache_key: None | str | Unset
        if isinstance(self.prompt_cache_key, Unset):
            prompt_cache_key = UNSET
        else:
            prompt_cache_key = self.prompt_cache_key

        prompt_cache_retention: None | str | Unset
        if isinstance(self.prompt_cache_retention, Unset):
            prompt_cache_retention = UNSET
        elif isinstance(self.prompt_cache_retention, LlmChatOpenaiConfigPromptCacheRetentionType0):
            prompt_cache_retention = self.prompt_cache_retention.value
        else:
            prompt_cache_retention = self.prompt_cache_retention

        reasoning_effort: None | str | Unset
        if isinstance(self.reasoning_effort, Unset):
            reasoning_effort = UNSET
        elif isinstance(self.reasoning_effort, LlmChatOpenaiConfigReasoningEffortType0):
            reasoning_effort = self.reasoning_effort.value
        else:
            reasoning_effort = self.reasoning_effort

        response_format: dict[str, Any] | None | Unset
        if isinstance(self.response_format, Unset):
            response_format = UNSET
        elif isinstance(self.response_format, ResponseFormatText):
            response_format = self.response_format.to_dict()
        elif isinstance(self.response_format, ResponseFormatJSONSchema):
            response_format = self.response_format.to_dict()
        elif isinstance(self.response_format, ResponseFormatJSONObject):
            response_format = self.response_format.to_dict()
        else:
            response_format = self.response_format

        safety_identifier: None | str | Unset
        if isinstance(self.safety_identifier, Unset):
            safety_identifier = UNSET
        else:
            safety_identifier = self.safety_identifier

        seed: int | None | Unset
        if isinstance(self.seed, Unset):
            seed = UNSET
        else:
            seed = self.seed

        service_tier: None | str | Unset
        if isinstance(self.service_tier, Unset):
            service_tier = UNSET
        elif isinstance(self.service_tier, LlmChatOpenaiConfigServiceTierType0):
            service_tier = self.service_tier.value
        else:
            service_tier = self.service_tier

        stop: list[str] | None | str | Unset
        if isinstance(self.stop, Unset):
            stop = UNSET
        elif isinstance(self.stop, list):
            stop = self.stop

        else:
            stop = self.stop

        store: bool | None | Unset
        if isinstance(self.store, Unset):
            store = UNSET
        else:
            store = self.store

        stream: bool | None | Unset
        if isinstance(self.stream, Unset):
            stream = UNSET
        else:
            stream = self.stream

        stream_options: dict[str, Any] | None | Unset
        if isinstance(self.stream_options, Unset):
            stream_options = UNSET
        elif isinstance(self.stream_options, ChatCompletionStreamOptionsParam):
            stream_options = self.stream_options.to_dict()
        else:
            stream_options = self.stream_options

        temperature: float | None | Unset
        if isinstance(self.temperature, Unset):
            temperature = UNSET
        else:
            temperature = self.temperature

        tool_choice: dict[str, Any] | None | str | Unset
        if isinstance(self.tool_choice, Unset):
            tool_choice = UNSET
        elif isinstance(self.tool_choice, LlmChatOpenaiConfigToolChoiceType0):
            tool_choice = self.tool_choice.value
        elif isinstance(self.tool_choice, ChatCompletionAllowedToolChoiceParam):
            tool_choice = self.tool_choice.to_dict()
        elif isinstance(self.tool_choice, ChatCompletionNamedToolChoiceParam):
            tool_choice = self.tool_choice.to_dict()
        elif isinstance(self.tool_choice, ChatCompletionNamedToolChoiceCustomParam):
            tool_choice = self.tool_choice.to_dict()
        else:
            tool_choice = self.tool_choice

        tools: list[dict[str, Any] | str] | None | Unset
        if isinstance(self.tools, Unset):
            tools = UNSET
        elif isinstance(self.tools, list):
            tools = []
            for tools_type_0_item_data in self.tools:
                tools_type_0_item: dict[str, Any] | str
                if isinstance(tools_type_0_item_data, ChatCompletionFunctionToolParam):
                    tools_type_0_item = tools_type_0_item_data.to_dict()
                else:
                    tools_type_0_item = tools_type_0_item_data
                tools.append(tools_type_0_item)

        else:
            tools = self.tools

        top_logprobs: int | None | Unset
        if isinstance(self.top_logprobs, Unset):
            top_logprobs = UNSET
        else:
            top_logprobs = self.top_logprobs

        top_p: float | None | Unset
        if isinstance(self.top_p, Unset):
            top_p = UNSET
        else:
            top_p = self.top_p

        user: None | str | Unset
        if isinstance(self.user, Unset):
            user = UNSET
        else:
            user = self.user

        verbosity: None | str | Unset
        if isinstance(self.verbosity, Unset):
            verbosity = UNSET
        elif isinstance(self.verbosity, LlmChatOpenaiConfigVerbosityType0):
            verbosity = self.verbosity.value
        else:
            verbosity = self.verbosity

        web_search_options: dict[str, Any] | None | Unset
        if isinstance(self.web_search_options, Unset):
            web_search_options = UNSET
        elif isinstance(self.web_search_options, WebSearchOptions):
            web_search_options = self.web_search_options.to_dict()
        else:
            web_search_options = self.web_search_options

        output_type: None | str | Unset
        if isinstance(self.output_type, Unset):
            output_type = UNSET
        elif isinstance(self.output_type, OutputType):
            output_type = self.output_type.value
        else:
            output_type = self.output_type

        json_schema: dict[str, Any] | None | Unset
        if isinstance(self.json_schema, Unset):
            json_schema = UNSET
        elif isinstance(self.json_schema, LlmChatOpenaiConfigJsonSchemaType0):
            json_schema = self.json_schema.to_dict()
        else:
            json_schema = self.json_schema

        response_schema: dict[str, Any] | None | Unset
        if isinstance(self.response_schema, Unset):
            response_schema = UNSET
        elif isinstance(self.response_schema, StructuredOutputSchema):
            response_schema = self.response_schema.to_dict()
        elif isinstance(self.response_schema, LlmChatOpenaiConfigResponseSchemaType1):
            response_schema = self.response_schema.to_dict()
        else:
            response_schema = self.response_schema

        extra_headers: dict[str, Any] | None | Unset
        if isinstance(self.extra_headers, Unset):
            extra_headers = UNSET
        elif isinstance(self.extra_headers, LlmChatOpenaiConfigExtraHeadersType0):
            extra_headers = self.extra_headers.to_dict()
        else:
            extra_headers = self.extra_headers

        extra_query: dict[str, Any] | None | Unset
        if isinstance(self.extra_query, Unset):
            extra_query = UNSET
        elif isinstance(self.extra_query, LlmChatOpenaiConfigExtraQueryType0):
            extra_query = self.extra_query.to_dict()
        else:
            extra_query = self.extra_query

        extra_body: Any | None | Unset
        if isinstance(self.extra_body, Unset):
            extra_body = UNSET
        else:
            extra_body = self.extra_body

        timeout: float | None | Unset
        if isinstance(self.timeout, Unset):
            timeout = UNSET
        else:
            timeout = self.timeout

        tool_output_text_to_file_char_limit: int | None | Unset
        if isinstance(self.tool_output_text_to_file_char_limit, Unset):
            tool_output_text_to_file_char_limit = UNSET
        else:
            tool_output_text_to_file_char_limit = self.tool_output_text_to_file_char_limit

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "messages": messages,
                "provider": provider,
            }
        )
        if model is not UNSET:
            field_dict["model"] = model
        if audio is not UNSET:
            field_dict["audio"] = audio
        if frequency_penalty is not UNSET:
            field_dict["frequency_penalty"] = frequency_penalty
        if logit_bias is not UNSET:
            field_dict["logit_bias"] = logit_bias
        if logprobs is not UNSET:
            field_dict["logprobs"] = logprobs
        if max_completion_tokens is not UNSET:
            field_dict["max_completion_tokens"] = max_completion_tokens
        if max_tokens is not UNSET:
            field_dict["max_tokens"] = max_tokens
        if metadata is not UNSET:
            field_dict["metadata"] = metadata
        if modalities is not UNSET:
            field_dict["modalities"] = modalities
        if n is not UNSET:
            field_dict["n"] = n
        if parallel_tool_calls is not UNSET:
            field_dict["parallel_tool_calls"] = parallel_tool_calls
        if prediction is not UNSET:
            field_dict["prediction"] = prediction
        if presence_penalty is not UNSET:
            field_dict["presence_penalty"] = presence_penalty
        if prompt_cache_key is not UNSET:
            field_dict["prompt_cache_key"] = prompt_cache_key
        if prompt_cache_retention is not UNSET:
            field_dict["prompt_cache_retention"] = prompt_cache_retention
        if reasoning_effort is not UNSET:
            field_dict["reasoning_effort"] = reasoning_effort
        if response_format is not UNSET:
            field_dict["response_format"] = response_format
        if safety_identifier is not UNSET:
            field_dict["safety_identifier"] = safety_identifier
        if seed is not UNSET:
            field_dict["seed"] = seed
        if service_tier is not UNSET:
            field_dict["service_tier"] = service_tier
        if stop is not UNSET:
            field_dict["stop"] = stop
        if store is not UNSET:
            field_dict["store"] = store
        if stream is not UNSET:
            field_dict["stream"] = stream
        if stream_options is not UNSET:
            field_dict["stream_options"] = stream_options
        if temperature is not UNSET:
            field_dict["temperature"] = temperature
        if tool_choice is not UNSET:
            field_dict["tool_choice"] = tool_choice
        if tools is not UNSET:
            field_dict["tools"] = tools
        if top_logprobs is not UNSET:
            field_dict["top_logprobs"] = top_logprobs
        if top_p is not UNSET:
            field_dict["top_p"] = top_p
        if user is not UNSET:
            field_dict["user"] = user
        if verbosity is not UNSET:
            field_dict["verbosity"] = verbosity
        if web_search_options is not UNSET:
            field_dict["web_search_options"] = web_search_options
        if output_type is not UNSET:
            field_dict["output_type"] = output_type
        if json_schema is not UNSET:
            field_dict["json_schema"] = json_schema
        if response_schema is not UNSET:
            field_dict["response_schema"] = response_schema
        if extra_headers is not UNSET:
            field_dict["extra_headers"] = extra_headers
        if extra_query is not UNSET:
            field_dict["extra_query"] = extra_query
        if extra_body is not UNSET:
            field_dict["extra_body"] = extra_body
        if timeout is not UNSET:
            field_dict["timeout"] = timeout
        if tool_output_text_to_file_char_limit is not UNSET:
            field_dict["tool_output_text_to_file_char_limit"] = tool_output_text_to_file_char_limit

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.chat_completion_allowed_tool_choice_param import ChatCompletionAllowedToolChoiceParam
        from ..models.chat_completion_assistant_message_param import ChatCompletionAssistantMessageParam
        from ..models.chat_completion_audio_param import ChatCompletionAudioParam
        from ..models.chat_completion_developer_message_param import ChatCompletionDeveloperMessageParam
        from ..models.chat_completion_function_message_param import ChatCompletionFunctionMessageParam
        from ..models.chat_completion_function_tool_param import ChatCompletionFunctionToolParam
        from ..models.chat_completion_named_tool_choice_custom_param import ChatCompletionNamedToolChoiceCustomParam
        from ..models.chat_completion_named_tool_choice_param import ChatCompletionNamedToolChoiceParam
        from ..models.chat_completion_prediction_content_param import ChatCompletionPredictionContentParam
        from ..models.chat_completion_stream_options_param import ChatCompletionStreamOptionsParam
        from ..models.chat_completion_system_message_param import ChatCompletionSystemMessageParam
        from ..models.chat_completion_tool_message_param import ChatCompletionToolMessageParam
        from ..models.chat_completion_user_message_param import ChatCompletionUserMessageParam
        from ..models.llm_chat_openai_config_extra_headers_type_0 import LlmChatOpenaiConfigExtraHeadersType0
        from ..models.llm_chat_openai_config_extra_query_type_0 import LlmChatOpenaiConfigExtraQueryType0
        from ..models.llm_chat_openai_config_json_schema_type_0 import LlmChatOpenaiConfigJsonSchemaType0
        from ..models.llm_chat_openai_config_logit_bias_type_0 import LlmChatOpenaiConfigLogitBiasType0
        from ..models.llm_chat_openai_config_metadata_type_0 import LlmChatOpenaiConfigMetadataType0
        from ..models.llm_chat_openai_config_response_schema_type_1 import LlmChatOpenaiConfigResponseSchemaType1
        from ..models.response_format_json_object import ResponseFormatJSONObject
        from ..models.response_format_json_schema import ResponseFormatJSONSchema
        from ..models.response_format_text import ResponseFormatText
        from ..models.structured_output_schema import StructuredOutputSchema
        from ..models.web_search_options import WebSearchOptions

        d = dict(src_dict)
        messages = []
        _messages = d.pop("messages")
        for messages_item_data in _messages:

            def _parse_messages_item(
                data: object,
            ) -> (
                ChatCompletionAssistantMessageParam
                | ChatCompletionDeveloperMessageParam
                | ChatCompletionFunctionMessageParam
                | ChatCompletionSystemMessageParam
                | ChatCompletionToolMessageParam
                | ChatCompletionUserMessageParam
            ):
                try:
                    if not isinstance(data, dict):
                        raise TypeError()
                    messages_item_type_0 = ChatCompletionDeveloperMessageParam.from_dict(data)

                    return messages_item_type_0
                except (TypeError, ValueError, AttributeError, KeyError):
                    pass
                try:
                    if not isinstance(data, dict):
                        raise TypeError()
                    messages_item_type_1 = ChatCompletionSystemMessageParam.from_dict(data)

                    return messages_item_type_1
                except (TypeError, ValueError, AttributeError, KeyError):
                    pass
                try:
                    if not isinstance(data, dict):
                        raise TypeError()
                    messages_item_type_2 = ChatCompletionUserMessageParam.from_dict(data)

                    return messages_item_type_2
                except (TypeError, ValueError, AttributeError, KeyError):
                    pass
                try:
                    if not isinstance(data, dict):
                        raise TypeError()
                    messages_item_type_3 = ChatCompletionAssistantMessageParam.from_dict(data)

                    return messages_item_type_3
                except (TypeError, ValueError, AttributeError, KeyError):
                    pass
                try:
                    if not isinstance(data, dict):
                        raise TypeError()
                    messages_item_type_4 = ChatCompletionToolMessageParam.from_dict(data)

                    return messages_item_type_4
                except (TypeError, ValueError, AttributeError, KeyError):
                    pass
                if not isinstance(data, dict):
                    raise TypeError()
                messages_item_type_5 = ChatCompletionFunctionMessageParam.from_dict(data)

                return messages_item_type_5

            messages_item = _parse_messages_item(messages_item_data)

            messages.append(messages_item)

        provider = LlmChatOpenaiConfigProvider(d.pop("provider"))

        def _parse_model(data: object) -> LlmChatOpenaiConfigModelType0 | LlmChatOpenaiConfigModelType1 | str | Unset:
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                model_type_0 = LlmChatOpenaiConfigModelType0(data)

                return model_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            try:
                if not isinstance(data, str):
                    raise TypeError()
                model_type_1 = LlmChatOpenaiConfigModelType1(data)

                return model_type_1
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(LlmChatOpenaiConfigModelType0 | LlmChatOpenaiConfigModelType1 | str | Unset, data)

        model = _parse_model(d.pop("model", UNSET))

        def _parse_audio(data: object) -> ChatCompletionAudioParam | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                audio_type_0 = ChatCompletionAudioParam.from_dict(data)

                return audio_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(ChatCompletionAudioParam | None | Unset, data)

        audio = _parse_audio(d.pop("audio", UNSET))

        def _parse_frequency_penalty(data: object) -> float | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(float | None | Unset, data)

        frequency_penalty = _parse_frequency_penalty(d.pop("frequency_penalty", UNSET))

        def _parse_logit_bias(data: object) -> LlmChatOpenaiConfigLogitBiasType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                logit_bias_type_0 = LlmChatOpenaiConfigLogitBiasType0.from_dict(data)

                return logit_bias_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(LlmChatOpenaiConfigLogitBiasType0 | None | Unset, data)

        logit_bias = _parse_logit_bias(d.pop("logit_bias", UNSET))

        def _parse_logprobs(data: object) -> bool | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(bool | None | Unset, data)

        logprobs = _parse_logprobs(d.pop("logprobs", UNSET))

        def _parse_max_completion_tokens(data: object) -> int | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(int | None | Unset, data)

        max_completion_tokens = _parse_max_completion_tokens(d.pop("max_completion_tokens", UNSET))

        def _parse_max_tokens(data: object) -> int | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(int | None | Unset, data)

        max_tokens = _parse_max_tokens(d.pop("max_tokens", UNSET))

        def _parse_metadata(data: object) -> LlmChatOpenaiConfigMetadataType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                metadata_type_0 = LlmChatOpenaiConfigMetadataType0.from_dict(data)

                return metadata_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(LlmChatOpenaiConfigMetadataType0 | None | Unset, data)

        metadata = _parse_metadata(d.pop("metadata", UNSET))

        def _parse_modalities(data: object) -> list[LlmChatOpenaiConfigModalitiesType0Item] | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, list):
                    raise TypeError()
                modalities_type_0 = []
                _modalities_type_0 = data
                for modalities_type_0_item_data in _modalities_type_0:
                    modalities_type_0_item = LlmChatOpenaiConfigModalitiesType0Item(modalities_type_0_item_data)

                    modalities_type_0.append(modalities_type_0_item)

                return modalities_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(list[LlmChatOpenaiConfigModalitiesType0Item] | None | Unset, data)

        modalities = _parse_modalities(d.pop("modalities", UNSET))

        def _parse_n(data: object) -> int | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(int | None | Unset, data)

        n = _parse_n(d.pop("n", UNSET))

        def _parse_parallel_tool_calls(data: object) -> bool | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(bool | None | Unset, data)

        parallel_tool_calls = _parse_parallel_tool_calls(d.pop("parallel_tool_calls", UNSET))

        def _parse_prediction(data: object) -> ChatCompletionPredictionContentParam | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                prediction_type_0 = ChatCompletionPredictionContentParam.from_dict(data)

                return prediction_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(ChatCompletionPredictionContentParam | None | Unset, data)

        prediction = _parse_prediction(d.pop("prediction", UNSET))

        def _parse_presence_penalty(data: object) -> float | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(float | None | Unset, data)

        presence_penalty = _parse_presence_penalty(d.pop("presence_penalty", UNSET))

        def _parse_prompt_cache_key(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        prompt_cache_key = _parse_prompt_cache_key(d.pop("prompt_cache_key", UNSET))

        def _parse_prompt_cache_retention(data: object) -> LlmChatOpenaiConfigPromptCacheRetentionType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                prompt_cache_retention_type_0 = LlmChatOpenaiConfigPromptCacheRetentionType0(data)

                return prompt_cache_retention_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(LlmChatOpenaiConfigPromptCacheRetentionType0 | None | Unset, data)

        prompt_cache_retention = _parse_prompt_cache_retention(d.pop("prompt_cache_retention", UNSET))

        def _parse_reasoning_effort(data: object) -> LlmChatOpenaiConfigReasoningEffortType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                reasoning_effort_type_0 = LlmChatOpenaiConfigReasoningEffortType0(data)

                return reasoning_effort_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(LlmChatOpenaiConfigReasoningEffortType0 | None | Unset, data)

        reasoning_effort = _parse_reasoning_effort(d.pop("reasoning_effort", UNSET))

        def _parse_response_format(
            data: object,
        ) -> None | ResponseFormatJSONObject | ResponseFormatJSONSchema | ResponseFormatText | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                response_format_type_0 = ResponseFormatText.from_dict(data)

                return response_format_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                response_format_type_1 = ResponseFormatJSONSchema.from_dict(data)

                return response_format_type_1
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                response_format_type_2 = ResponseFormatJSONObject.from_dict(data)

                return response_format_type_2
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(None | ResponseFormatJSONObject | ResponseFormatJSONSchema | ResponseFormatText | Unset, data)

        response_format = _parse_response_format(d.pop("response_format", UNSET))

        def _parse_safety_identifier(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        safety_identifier = _parse_safety_identifier(d.pop("safety_identifier", UNSET))

        def _parse_seed(data: object) -> int | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(int | None | Unset, data)

        seed = _parse_seed(d.pop("seed", UNSET))

        def _parse_service_tier(data: object) -> LlmChatOpenaiConfigServiceTierType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                service_tier_type_0 = LlmChatOpenaiConfigServiceTierType0(data)

                return service_tier_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(LlmChatOpenaiConfigServiceTierType0 | None | Unset, data)

        service_tier = _parse_service_tier(d.pop("service_tier", UNSET))

        def _parse_stop(data: object) -> list[str] | None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, list):
                    raise TypeError()
                stop_type_1 = cast(list[str], data)

                return stop_type_1
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(list[str] | None | str | Unset, data)

        stop = _parse_stop(d.pop("stop", UNSET))

        def _parse_store(data: object) -> bool | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(bool | None | Unset, data)

        store = _parse_store(d.pop("store", UNSET))

        def _parse_stream(data: object) -> bool | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(bool | None | Unset, data)

        stream = _parse_stream(d.pop("stream", UNSET))

        def _parse_stream_options(data: object) -> ChatCompletionStreamOptionsParam | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                stream_options_type_0 = ChatCompletionStreamOptionsParam.from_dict(data)

                return stream_options_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(ChatCompletionStreamOptionsParam | None | Unset, data)

        stream_options = _parse_stream_options(d.pop("stream_options", UNSET))

        def _parse_temperature(data: object) -> float | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(float | None | Unset, data)

        temperature = _parse_temperature(d.pop("temperature", UNSET))

        def _parse_tool_choice(
            data: object,
        ) -> (
            ChatCompletionAllowedToolChoiceParam
            | ChatCompletionNamedToolChoiceCustomParam
            | ChatCompletionNamedToolChoiceParam
            | LlmChatOpenaiConfigToolChoiceType0
            | None
            | Unset
        ):
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                tool_choice_type_0 = LlmChatOpenaiConfigToolChoiceType0(data)

                return tool_choice_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                tool_choice_type_1 = ChatCompletionAllowedToolChoiceParam.from_dict(data)

                return tool_choice_type_1
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                tool_choice_type_2 = ChatCompletionNamedToolChoiceParam.from_dict(data)

                return tool_choice_type_2
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                tool_choice_type_3 = ChatCompletionNamedToolChoiceCustomParam.from_dict(data)

                return tool_choice_type_3
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(
                ChatCompletionAllowedToolChoiceParam
                | ChatCompletionNamedToolChoiceCustomParam
                | ChatCompletionNamedToolChoiceParam
                | LlmChatOpenaiConfigToolChoiceType0
                | None
                | Unset,
                data,
            )

        tool_choice = _parse_tool_choice(d.pop("tool_choice", UNSET))

        def _parse_tools(data: object) -> list[ChatCompletionFunctionToolParam | str] | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, list):
                    raise TypeError()
                tools_type_0 = []
                _tools_type_0 = data
                for tools_type_0_item_data in _tools_type_0:

                    def _parse_tools_type_0_item(data: object) -> ChatCompletionFunctionToolParam | str:
                        try:
                            if not isinstance(data, dict):
                                raise TypeError()
                            tools_type_0_item_type_0 = ChatCompletionFunctionToolParam.from_dict(data)

                            return tools_type_0_item_type_0
                        except (TypeError, ValueError, AttributeError, KeyError):
                            pass
                        return cast(ChatCompletionFunctionToolParam | str, data)

                    tools_type_0_item = _parse_tools_type_0_item(tools_type_0_item_data)

                    tools_type_0.append(tools_type_0_item)

                return tools_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(list[ChatCompletionFunctionToolParam | str] | None | Unset, data)

        tools = _parse_tools(d.pop("tools", UNSET))

        def _parse_top_logprobs(data: object) -> int | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(int | None | Unset, data)

        top_logprobs = _parse_top_logprobs(d.pop("top_logprobs", UNSET))

        def _parse_top_p(data: object) -> float | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(float | None | Unset, data)

        top_p = _parse_top_p(d.pop("top_p", UNSET))

        def _parse_user(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        user = _parse_user(d.pop("user", UNSET))

        def _parse_verbosity(data: object) -> LlmChatOpenaiConfigVerbosityType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                verbosity_type_0 = LlmChatOpenaiConfigVerbosityType0(data)

                return verbosity_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(LlmChatOpenaiConfigVerbosityType0 | None | Unset, data)

        verbosity = _parse_verbosity(d.pop("verbosity", UNSET))

        def _parse_web_search_options(data: object) -> None | Unset | WebSearchOptions:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                web_search_options_type_0 = WebSearchOptions.from_dict(data)

                return web_search_options_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(None | Unset | WebSearchOptions, data)

        web_search_options = _parse_web_search_options(d.pop("web_search_options", UNSET))

        def _parse_output_type(data: object) -> None | OutputType | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                output_type_type_0 = OutputType(data)

                return output_type_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(None | OutputType | Unset, data)

        output_type = _parse_output_type(d.pop("output_type", UNSET))

        def _parse_json_schema(data: object) -> LlmChatOpenaiConfigJsonSchemaType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                json_schema_type_0 = LlmChatOpenaiConfigJsonSchemaType0.from_dict(data)

                return json_schema_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(LlmChatOpenaiConfigJsonSchemaType0 | None | Unset, data)

        json_schema = _parse_json_schema(d.pop("json_schema", UNSET))

        def _parse_response_schema(
            data: object,
        ) -> LlmChatOpenaiConfigResponseSchemaType1 | None | StructuredOutputSchema | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                response_schema_type_0 = StructuredOutputSchema.from_dict(data)

                return response_schema_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                response_schema_type_1 = LlmChatOpenaiConfigResponseSchemaType1.from_dict(data)

                return response_schema_type_1
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(LlmChatOpenaiConfigResponseSchemaType1 | None | StructuredOutputSchema | Unset, data)

        response_schema = _parse_response_schema(d.pop("response_schema", UNSET))

        def _parse_extra_headers(data: object) -> LlmChatOpenaiConfigExtraHeadersType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                extra_headers_type_0 = LlmChatOpenaiConfigExtraHeadersType0.from_dict(data)

                return extra_headers_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(LlmChatOpenaiConfigExtraHeadersType0 | None | Unset, data)

        extra_headers = _parse_extra_headers(d.pop("extra_headers", UNSET))

        def _parse_extra_query(data: object) -> LlmChatOpenaiConfigExtraQueryType0 | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                extra_query_type_0 = LlmChatOpenaiConfigExtraQueryType0.from_dict(data)

                return extra_query_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(LlmChatOpenaiConfigExtraQueryType0 | None | Unset, data)

        extra_query = _parse_extra_query(d.pop("extra_query", UNSET))

        def _parse_extra_body(data: object) -> Any | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(Any | None | Unset, data)

        extra_body = _parse_extra_body(d.pop("extra_body", UNSET))

        def _parse_timeout(data: object) -> float | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(float | None | Unset, data)

        timeout = _parse_timeout(d.pop("timeout", UNSET))

        def _parse_tool_output_text_to_file_char_limit(data: object) -> int | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(int | None | Unset, data)

        tool_output_text_to_file_char_limit = _parse_tool_output_text_to_file_char_limit(
            d.pop("tool_output_text_to_file_char_limit", UNSET)
        )

        llm_chat_openai_config = cls(
            messages=messages,
            provider=provider,
            model=model,
            audio=audio,
            frequency_penalty=frequency_penalty,
            logit_bias=logit_bias,
            logprobs=logprobs,
            max_completion_tokens=max_completion_tokens,
            max_tokens=max_tokens,
            metadata=metadata,
            modalities=modalities,
            n=n,
            parallel_tool_calls=parallel_tool_calls,
            prediction=prediction,
            presence_penalty=presence_penalty,
            prompt_cache_key=prompt_cache_key,
            prompt_cache_retention=prompt_cache_retention,
            reasoning_effort=reasoning_effort,
            response_format=response_format,
            safety_identifier=safety_identifier,
            seed=seed,
            service_tier=service_tier,
            stop=stop,
            store=store,
            stream=stream,
            stream_options=stream_options,
            temperature=temperature,
            tool_choice=tool_choice,
            tools=tools,
            top_logprobs=top_logprobs,
            top_p=top_p,
            user=user,
            verbosity=verbosity,
            web_search_options=web_search_options,
            output_type=output_type,
            json_schema=json_schema,
            response_schema=response_schema,
            extra_headers=extra_headers,
            extra_query=extra_query,
            extra_body=extra_body,
            timeout=timeout,
            tool_output_text_to_file_char_limit=tool_output_text_to_file_char_limit,
        )

        llm_chat_openai_config.additional_properties = d
        return llm_chat_openai_config

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
