Skip to content

OpenAIModelConfig

Base classes

Name Children Inherits
BaseModelConfig
llmling_models_config.configs
Base for model configurations.

â‹” Inheritance diagram

graph TD
  2777737789["configs.OpenAIModelConfig"]
  3497727833["configs.BaseModelConfig"]
  330168112["schema.Schema"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  3497727833 --> 2777737789
  330168112 --> 3497727833
  3879467795 --> 330168112
  2751680898 --> 3879467795

🛈 DocStrings

Bases: BaseModelConfig

Configuration for OpenAI models.

Source code in src/llmling_models_config/configs.py
class OpenAIModelConfig(BaseModelConfig):
    """Configuration for OpenAI models."""

    model_config = ConfigDict(json_schema_extra={"x-doc-title": "OpenAI model"})

    type: Literal["openai"] = Field(default="openai", init=False)
    """Type identifier for OpenAI model."""

    identifier: OpenaiModelName | str = Field(
        examples=["gpt-4", "gpt-4-turbo"],
        title="Model identifier",
    )
    """String identifier for the model."""

    max_tokens: int | None = Field(
        default=None,
        ge=1,
        examples=[1024, 2048, 4096],
        title="Maximum tokens",
    )
    """The maximum number of tokens to generate before stopping."""

    temperature: float | None = Field(
        default=None,
        ge=0.0,
        examples=[0.0, 0.7, 1.0, 2.0],
        title="Temperature",
    )
    """Amount of randomness injected into the response."""

    top_p: float | None = Field(
        default=None,
        ge=0.0,
        le=1.0,
        examples=[0.1, 0.9, 1.0],
        title="Top-p (nucleus sampling)",
    )
    """An alternative to sampling with temperature, called nucleus sampling."""

    timeout: float | None = Field(
        default=None,
        examples=[30.0, 60.0, 120.0],
        title="Request timeout",
    )
    """Override the client-level default timeout for a request, in seconds."""

    parallel_tool_calls: bool | None = Field(
        default=None,
        title="Allow parallel tool calls",
    )
    """Whether to allow parallel tool calls."""

    seed: int | None = Field(
        default=None,
        examples=[42, 123, 999],
        title="Random seed",
    )
    """The random seed to use for the model, theoretically allowing for deterministic results."""

    presence_penalty: float | None = Field(
        default=None,
        ge=-2.0,
        le=2.0,
        examples=[-1.0, 0.0, 0.5, 1.0],
        title="Presence penalty",
    )
    """Penalize new tokens based on whether they have appeared in the text so far."""

    frequency_penalty: float | None = Field(
        default=None,
        ge=-2.0,
        le=2.0,
        examples=[-1.0, 0.0, 0.5, 1.0],
        title="Frequency penalty",
    )
    """Penalize new tokens based on their existing frequency in the text so far."""

    logit_bias: dict[str, int] | None = Field(
        default=None,
        title="Logit bias",
        examples=[{"5678": -100}, {"1234": 100}],
    )
    """Modify the likelihood of specified tokens appearing in the completion."""

    stop_sequences: list[str] | None = Field(
        default=None,
        examples=[["STOP", "END"], ["\n\n"]],
        title="Stop sequences",
    )
    """Sequences that will cause the model to stop generating."""

    extra_headers: dict[str, str] | None = Field(
        default=None,
        examples=[{"Custom-Header": "value"}],
        title="Extra headers",
    )
    """Extra headers to send to the model."""

    extra_body: Any | None = Field(
        default=None,
        title="Extra body",
    )
    """Extra body to send to the model."""

    reasoning_effort: Literal["none", "minimal", "low", "medium", "high", "xhigh"] | None = Field(
        default=None,
        title="Reasoning effort",
    )
    """Constrains effort on reasoning for reasoning models."""

    logprobs: bool | None = Field(
        default=None,
        title="Include log probabilities",
    )
    """Include log probabilities in the response."""

    top_logprobs: int | None = Field(
        default=None,
        ge=0,
        le=20,
        title="Top log probabilities",
    )
    """Include log probabilities of the top n tokens in the response."""

    user: str | None = Field(
        default=None,
        title="User identifier",
    )
    """A unique identifier representing the end-user."""

    service_tier: Literal["auto", "default", "flex", "priority"] | None = Field(
        default=None,
        title="Service tier",
    )
    """The service tier to use for the model request."""

    prompt_cache_key: str | None = Field(
        default=None,
        title="Prompt cache key",
    )
    """Used by OpenAI to cache responses for similar requests to optimize your cache hit rates.

    See the [OpenAI Prompt Caching documentation](https://platform.openai.com/docs/guides/prompt-caching#how-it-works) for more information.
    """  # noqa: E501

    prompt_cache_retention: Literal["in-memory", "24h"] | None = Field(
        default=None,
        title="Prompt cache retention",
    )
    """The retention policy for the prompt cache. Set to 24h to enable extended prompt caching, which keeps cached prefixes active for longer, up to a maximum of 24 hours.

    See the [OpenAI Prompt Caching documentation](https://platform.openai.com/docs/guides/prompt-caching#how-it-works) for more information.
    """  # noqa: E501

    prediction: dict[str, Any] | None = Field(
        default=None,
        title="Predicted output",
        examples=[{"type": "content", "content": "predicted response text"}],
    )
    """Predicted output for the model to use as a starting point.

    Can be a simple string content or structured with text parts:
    - Simple: {"type": "content", "content": "predicted text"}
    - Parts: {"type": "content", "content": [{"type": "text", "text": "predicted"}]}
    """

    # Responses API specific settings
    builtin_tools: list[dict[str, Any]] | None = Field(
        default=None,
        title="Built-in tools",
    )
    """The provided OpenAI built-in tools to use (file_search, web_search, computer).

    See [OpenAI's built-in tools](https://platform.openai.com/docs/guides/tools?api-mode=responses)
    for more details.
    """

    reasoning_summary: Literal["detailed", "concise", "auto"] | None = Field(
        default=None,
        title="Reasoning summary",
    )
    """A summary of the reasoning performed by the model.

    This can be useful for debugging and understanding the model's reasoning process.
    One of `concise`, `detailed`, or `auto`.
    """

    send_reasoning_ids: bool | None = Field(
        default=None,
        title="Send reasoning IDs",
    )
    """Whether to send the unique IDs of reasoning, text, and function call parts from the message
    history to the model.

    Enabled by default for reasoning models. Disable if you get errors about items not matching.
    """

    truncation: Literal["disabled", "auto"] | None = Field(
        default=None,
        title="Truncation strategy",
    )
    """The truncation strategy to use for the model response.

    - `disabled` (default): Request fails if response exceeds context window.
    - `auto`: Model truncates by dropping input items in the middle of the conversation.
    """

    text_verbosity: Literal["low", "medium", "high"] | None = Field(
        default=None,
        title="Text verbosity",
    )
    """Constrains the verbosity of the model's text response.

    Lower values will result in more concise responses, while higher values will
    result in more verbose responses.
    """

    previous_response_id: Literal["auto"] | str | None = Field(  # noqa: PYI051
        default=None,
        title="Previous response ID",
    )
    """The ID of a previous response to use as the starting point for a continued conversation.

    When set to `'auto'`, the request automatically uses the most recent provider_response_id.
    """

    include_code_execution_outputs: bool | None = Field(
        default=None,
        title="Include code execution outputs",
    )
    """Whether to include the code execution results in the response."""

    include_web_search_sources: bool | None = Field(
        default=None,
        title="Include web search sources",
    )
    """Whether to include the web search results in the response."""

    include_file_search_results: bool | None = Field(
        default=None,
        title="Include file search results",
    )
    """Whether to include the file search results in the response."""

    def get_model_settings(self) -> OpenAIResponsesModelSettings:
        """Get model settings in pydantic-ai format."""
        from pydantic_ai.models.openai import OpenAIResponsesModelSettings

        settings = {
            # Base model settings
            "max_tokens": self.max_tokens,
            "temperature": self.temperature,
            "top_p": self.top_p,
            "timeout": self.timeout,
            "parallel_tool_calls": self.parallel_tool_calls,
            "seed": self.seed,
            "presence_penalty": self.presence_penalty,
            "frequency_penalty": self.frequency_penalty,
            "logit_bias": self.logit_bias,
            "stop_sequences": self.stop_sequences,
            "extra_headers": self.extra_headers,
            "extra_body": self.extra_body,
            # OpenAI Chat settings
            "openai_reasoning_effort": self.reasoning_effort,
            "openai_logprobs": self.logprobs,
            "openai_top_logprobs": self.top_logprobs,
            "openai_user": self.user,
            "openai_service_tier": self.service_tier,
            "openai_prompt_cache_key": self.prompt_cache_key,
            "openai_prompt_cache_retention": self.prompt_cache_retention,
            "openai_prediction": self.prediction,
            # Responses API specific settings
            "openai_builtin_tools": self.builtin_tools,
            "openai_reasoning_summary": self.reasoning_summary,
            "openai_send_reasoning_ids": self.send_reasoning_ids,
            "openai_truncation": self.truncation,
            "openai_text_verbosity": self.text_verbosity,
            "openai_previous_response_id": self.previous_response_id,
            "openai_include_code_execution_outputs": self.include_code_execution_outputs,
            "openai_include_web_search_sources": self.include_web_search_sources,
            "openai_include_file_search_results": self.include_file_search_results,
        }
        return OpenAIResponsesModelSettings(**{k: v for k, v in settings.items() if v is not None})  # type: ignore[typeddict-item, no-any-return]

    def get_model(self) -> Any:
        from llmling_models import infer_model

        return infer_model("openai:" + self.identifier)

builtin_tools class-attribute instance-attribute

builtin_tools: list[dict[str, Any]] | None = Field(default=None, title='Built-in tools')

The provided OpenAI built-in tools to use (file_search, web_search, computer).

See OpenAI's built-in tools for more details.

extra_body class-attribute instance-attribute

extra_body: Any | None = Field(default=None, title='Extra body')

Extra body to send to the model.

extra_headers class-attribute instance-attribute

extra_headers: dict[str, str] | None = Field(
    default=None, examples=[{"Custom-Header": "value"}], title="Extra headers"
)

Extra headers to send to the model.

frequency_penalty class-attribute instance-attribute

frequency_penalty: float | None = Field(
    default=None, ge=-2.0, le=2.0, examples=[-1.0, 0.0, 0.5, 1.0], title="Frequency penalty"
)

Penalize new tokens based on their existing frequency in the text so far.

identifier class-attribute instance-attribute

identifier: OpenaiModelName | str = Field(
    examples=["gpt-4", "gpt-4-turbo"], title="Model identifier"
)

String identifier for the model.

include_code_execution_outputs class-attribute instance-attribute

include_code_execution_outputs: bool | None = Field(
    default=None, title="Include code execution outputs"
)

Whether to include the code execution results in the response.

include_file_search_results class-attribute instance-attribute

include_file_search_results: bool | None = Field(default=None, title='Include file search results')

Whether to include the file search results in the response.

include_web_search_sources class-attribute instance-attribute

include_web_search_sources: bool | None = Field(default=None, title='Include web search sources')

Whether to include the web search results in the response.

logit_bias class-attribute instance-attribute

logit_bias: dict[str, int] | None = Field(
    default=None, title="Logit bias", examples=[{"5678": -100}, {"1234": 100}]
)

Modify the likelihood of specified tokens appearing in the completion.

logprobs class-attribute instance-attribute

logprobs: bool | None = Field(default=None, title='Include log probabilities')

Include log probabilities in the response.

max_tokens class-attribute instance-attribute

max_tokens: int | None = Field(
    default=None, ge=1, examples=[1024, 2048, 4096], title="Maximum tokens"
)

The maximum number of tokens to generate before stopping.

parallel_tool_calls class-attribute instance-attribute

parallel_tool_calls: bool | None = Field(default=None, title='Allow parallel tool calls')

Whether to allow parallel tool calls.

prediction class-attribute instance-attribute

prediction: dict[str, Any] | None = Field(
    default=None,
    title="Predicted output",
    examples=[{"type": "content", "content": "predicted response text"}],
)

Predicted output for the model to use as a starting point.

Can be a simple string content or structured with text parts: - Simple: {"type": "content", "content": "predicted text"} - Parts: {"type": "content", "content": [{"type": "text", "text": "predicted"}]}

presence_penalty class-attribute instance-attribute

presence_penalty: float | None = Field(
    default=None, ge=-2.0, le=2.0, examples=[-1.0, 0.0, 0.5, 1.0], title="Presence penalty"
)

Penalize new tokens based on whether they have appeared in the text so far.

previous_response_id class-attribute instance-attribute

previous_response_id: Literal["auto"] | str | None = Field(
    default=None, title="Previous response ID"
)

The ID of a previous response to use as the starting point for a continued conversation.

When set to 'auto', the request automatically uses the most recent provider_response_id.

prompt_cache_key class-attribute instance-attribute

prompt_cache_key: str | None = Field(default=None, title='Prompt cache key')

Used by OpenAI to cache responses for similar requests to optimize your cache hit rates.

See the OpenAI Prompt Caching documentation for more information.

prompt_cache_retention class-attribute instance-attribute

prompt_cache_retention: Literal["in-memory", "24h"] | None = Field(
    default=None, title="Prompt cache retention"
)

The retention policy for the prompt cache. Set to 24h to enable extended prompt caching, which keeps cached prefixes active for longer, up to a maximum of 24 hours.

See the OpenAI Prompt Caching documentation for more information.

reasoning_effort class-attribute instance-attribute

reasoning_effort: Literal["none", "minimal", "low", "medium", "high", "xhigh"] | None = Field(
    default=None, title="Reasoning effort"
)

Constrains effort on reasoning for reasoning models.

reasoning_summary class-attribute instance-attribute

reasoning_summary: Literal["detailed", "concise", "auto"] | None = Field(
    default=None, title="Reasoning summary"
)

A summary of the reasoning performed by the model.

This can be useful for debugging and understanding the model's reasoning process. One of concise, detailed, or auto.

seed class-attribute instance-attribute

seed: int | None = Field(default=None, examples=[42, 123, 999], title='Random seed')

The random seed to use for the model, theoretically allowing for deterministic results.

send_reasoning_ids class-attribute instance-attribute

send_reasoning_ids: bool | None = Field(default=None, title='Send reasoning IDs')

Whether to send the unique IDs of reasoning, text, and function call parts from the message history to the model.

Enabled by default for reasoning models. Disable if you get errors about items not matching.

service_tier class-attribute instance-attribute

service_tier: Literal["auto", "default", "flex", "priority"] | None = Field(
    default=None, title="Service tier"
)

The service tier to use for the model request.

stop_sequences class-attribute instance-attribute

stop_sequences: list[str] | None = Field(
    default=None, examples=[["STOP", "END"], ["\n\n"]], title="Stop sequences"
)

Sequences that will cause the model to stop generating.

temperature class-attribute instance-attribute

temperature: float | None = Field(
    default=None, ge=0.0, examples=[0.0, 0.7, 1.0, 2.0], title="Temperature"
)

Amount of randomness injected into the response.

text_verbosity class-attribute instance-attribute

text_verbosity: Literal["low", "medium", "high"] | None = Field(
    default=None, title="Text verbosity"
)

Constrains the verbosity of the model's text response.

Lower values will result in more concise responses, while higher values will result in more verbose responses.

timeout class-attribute instance-attribute

timeout: float | None = Field(default=None, examples=[30.0, 60.0, 120.0], title='Request timeout')

Override the client-level default timeout for a request, in seconds.

top_logprobs class-attribute instance-attribute

top_logprobs: int | None = Field(default=None, ge=0, le=20, title='Top log probabilities')

Include log probabilities of the top n tokens in the response.

top_p class-attribute instance-attribute

top_p: float | None = Field(
    default=None, ge=0.0, le=1.0, examples=[0.1, 0.9, 1.0], title="Top-p (nucleus sampling)"
)

An alternative to sampling with temperature, called nucleus sampling.

truncation class-attribute instance-attribute

truncation: Literal['disabled', 'auto'] | None = Field(default=None, title='Truncation strategy')

The truncation strategy to use for the model response.

  • disabled (default): Request fails if response exceeds context window.
  • auto: Model truncates by dropping input items in the middle of the conversation.

type class-attribute instance-attribute

type: Literal['openai'] = Field(default='openai', init=False)

Type identifier for OpenAI model.

user class-attribute instance-attribute

user: str | None = Field(default=None, title='User identifier')

A unique identifier representing the end-user.

get_model_settings

get_model_settings() -> OpenAIResponsesModelSettings

Get model settings in pydantic-ai format.

Source code in src/llmling_models_config/configs.py
def get_model_settings(self) -> OpenAIResponsesModelSettings:
    """Get model settings in pydantic-ai format."""
    from pydantic_ai.models.openai import OpenAIResponsesModelSettings

    settings = {
        # Base model settings
        "max_tokens": self.max_tokens,
        "temperature": self.temperature,
        "top_p": self.top_p,
        "timeout": self.timeout,
        "parallel_tool_calls": self.parallel_tool_calls,
        "seed": self.seed,
        "presence_penalty": self.presence_penalty,
        "frequency_penalty": self.frequency_penalty,
        "logit_bias": self.logit_bias,
        "stop_sequences": self.stop_sequences,
        "extra_headers": self.extra_headers,
        "extra_body": self.extra_body,
        # OpenAI Chat settings
        "openai_reasoning_effort": self.reasoning_effort,
        "openai_logprobs": self.logprobs,
        "openai_top_logprobs": self.top_logprobs,
        "openai_user": self.user,
        "openai_service_tier": self.service_tier,
        "openai_prompt_cache_key": self.prompt_cache_key,
        "openai_prompt_cache_retention": self.prompt_cache_retention,
        "openai_prediction": self.prediction,
        # Responses API specific settings
        "openai_builtin_tools": self.builtin_tools,
        "openai_reasoning_summary": self.reasoning_summary,
        "openai_send_reasoning_ids": self.send_reasoning_ids,
        "openai_truncation": self.truncation,
        "openai_text_verbosity": self.text_verbosity,
        "openai_previous_response_id": self.previous_response_id,
        "openai_include_code_execution_outputs": self.include_code_execution_outputs,
        "openai_include_web_search_sources": self.include_web_search_sources,
        "openai_include_file_search_results": self.include_file_search_results,
    }
    return OpenAIResponsesModelSettings(**{k: v for k, v in settings.items() if v is not None})  # type: ignore[typeddict-item, no-any-return]

:fa-brands-github: Show source on GitHub