Skip to content

AnthropicModelConfig

Base classes

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

â‹” Inheritance diagram

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

🛈 DocStrings

Bases: BaseModelConfig

Configuration for Anthropic models.

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

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

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

    identifier: AnthropicModelName | str = Field(
        examples=["claude-3-opus", "claude-3-sonnet"],
        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."""

    metadata: dict[str, Any] | None = Field(
        default=None,
        title="Request metadata",
    )
    """An object describing metadata about the request."""

    cache_tool_definitions: bool | Literal["5m", "1h"] | None = Field(
        default=None,
        title="Cache tool definitions",
    )
    """Whether to add cache_control to the last tool definition."""

    cache_instructions: bool | Literal["5m", "1h"] | None = Field(
        default=None,
        title="Cache instructions",
    )
    """Whether to add cache_control to the last system prompt block."""

    cache_messages: bool | Literal["5m", "1h"] | None = Field(
        default=None,
        title="Cache messages",
    )
    """Convenience setting to enable caching for the last user message."""

    thinking_budget: int | None = Field(
        default=None,
        ge=1024,
        examples=[10000, 50000, 100000],
        title="Thinking budget tokens",
    )
    """Budget tokens for extended thinking mode.

    When set, enables Claude's extended thinking capability, allowing the model
    to reason through complex problems before responding. Higher values allow
    for more thorough reasoning but increase latency and cost.
    """

    container: dict[str, Any] | Literal[False] | None = Field(
        default=None,
        title="Container sandbox",
        examples=[
            {"id": "container-123"},
            {"id": "my-container", "skills": [{"skill_id": "computer", "type": "anthropic"}]},
            False,
        ],
    )
    """Container sandbox configuration for Claude.

    Enables running Claude in a sandboxed container environment with optional skills.
    Set to False to explicitly disable container mode, or provide config dict:
    - id: Container identifier
    - skills: List of skills with skill_id, type ('anthropic' or 'custom'), and version
    """

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

        settings: dict[str, Any] = {
            "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,
            "anthropic_metadata": self.metadata,
            "anthropic_cache_tool_definitions": self.cache_tool_definitions,
            "anthropic_cache_instructions": self.cache_instructions,
            "anthropic_cache_messages": self.cache_messages,
        }
        # Add thinking config if budget is set
        if self.thinking_budget is not None:
            settings["anthropic_thinking"] = {
                "type": "enabled",
                "budget_tokens": self.thinking_budget,
            }
        # Add container config if set (can be dict or False)
        if self.container is not None:
            settings["anthropic_container"] = self.container
        return AnthropicModelSettings(**{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("anthropic:" + self.identifier)

cache_instructions class-attribute instance-attribute

cache_instructions: bool | Literal["5m", "1h"] | None = Field(
    default=None, title="Cache instructions"
)

Whether to add cache_control to the last system prompt block.

cache_messages class-attribute instance-attribute

cache_messages: bool | Literal['5m', '1h'] | None = Field(default=None, title='Cache messages')

Convenience setting to enable caching for the last user message.

cache_tool_definitions class-attribute instance-attribute

cache_tool_definitions: bool | Literal["5m", "1h"] | None = Field(
    default=None, title="Cache tool definitions"
)

Whether to add cache_control to the last tool definition.

container class-attribute instance-attribute

container: dict[str, Any] | Literal[False] | None = Field(
    default=None,
    title="Container sandbox",
    examples=[
        {"id": "container-123"},
        {"id": "my-container", "skills": [{"skill_id": "computer", "type": "anthropic"}]},
        False,
    ],
)

Container sandbox configuration for Claude.

Enables running Claude in a sandboxed container environment with optional skills. Set to False to explicitly disable container mode, or provide config dict: - id: Container identifier - skills: List of skills with skill_id, type ('anthropic' or 'custom'), and version

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: AnthropicModelName | str = Field(
    examples=["claude-3-opus", "claude-3-sonnet"], title="Model identifier"
)

String identifier for the model.

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.

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.

metadata class-attribute instance-attribute

metadata: dict[str, Any] | None = Field(default=None, title='Request metadata')

An object describing metadata about the request.

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.

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.

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.

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.

thinking_budget class-attribute instance-attribute

thinking_budget: int | None = Field(
    default=None, ge=1024, examples=[10000, 50000, 100000], title="Thinking budget tokens"
)

Budget tokens for extended thinking mode.

When set, enables Claude's extended thinking capability, allowing the model to reason through complex problems before responding. Higher values allow for more thorough reasoning but increase latency and cost.

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_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.

type class-attribute instance-attribute

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

Type identifier for Anthropic model.

get_model_settings

get_model_settings() -> AnthropicModelSettings

Get model settings in pydantic-ai format.

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

    settings: dict[str, Any] = {
        "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,
        "anthropic_metadata": self.metadata,
        "anthropic_cache_tool_definitions": self.cache_tool_definitions,
        "anthropic_cache_instructions": self.cache_instructions,
        "anthropic_cache_messages": self.cache_messages,
    }
    # Add thinking config if budget is set
    if self.thinking_budget is not None:
        settings["anthropic_thinking"] = {
            "type": "enabled",
            "budget_tokens": self.thinking_budget,
        }
    # Add container config if set (can be dict or False)
    if self.container is not None:
        settings["anthropic_container"] = self.container
    return AnthropicModelSettings(**{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