Verified Commit 0ca91d07 authored by Nathan Weinshenker's avatar Nathan Weinshenker Committed by GitLab
Browse files

feat(model-selection): add Claude Fable 5.2

parent 5d5e10b4
Loading
Loading
Loading
Loading
+25 −1
Changes for ai_gateway/model_selection/models.py: 25 added lines, 1 removed line.
Original line number Diff line number Diff line
from enum import StrEnum
from typing import Iterable, Mapping, Optional
from typing import Iterable, Literal, Mapping, Optional

from pydantic import BaseModel, ConfigDict, Field, model_validator

__all__ = [
    "AnthropicBlockBindingParams",
    "AnthropicThinkingParams",
    "AnthropicWorkloadIdentityParams",
    "BaseModelParams",
    "ChatAmazonQParams",
@@ -142,9 +144,31 @@ class AnthropicWorkloadIdentityParams(BaseModel):
    """The `aud` claim requested on the identity token; must match the rule's `match.audience`."""


class AnthropicBlockBindingParams(BaseModel):
    """What Anthropic does with a replayed thinking block whose earlier conversation changed ("preserved thinking").

    `error` returns a 400; `drop_block` drops that block and every later one, then answers the request.
    """

    model_config = ConfigDict(extra="forbid", frozen=True)

    prefix_mismatch_behavior: Literal["error", "drop_block"]


class AnthropicThinkingParams(BaseModel):
    model_config = ConfigDict(extra="forbid", frozen=True)

    type: Literal["adaptive"] = "adaptive"
    block_binding: AnthropicBlockBindingParams | None = None


class ChatAnthropicParams(BaseModelParams):
    default_headers: Mapping[str, str] | None = None

    # Set per model in models.yml, e.g. `thinking.block_binding` with the matching `anthropic-beta` value in `betas`.
    thinking: AnthropicThinkingParams | None = None
    betas: list[str] | None = None

    # This allows us to override the API key per model via `AIGW_MODEL_SELECTION__MODEL_PARAMS`, which enable us to
    # switch between Anthropic organizations/workspaces when needed.
    api_key: str | None = None
+25
Changes for ai_gateway/model_selection/models.yml: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -303,6 +303,31 @@ models:
      model: "claude-fable-5-1"
      max_tokens: 128_000

  - name: "Claude Fable 5.2"
    provider: "Anthropic"
    gitlab_identifier: "claude_fable_5_2"
    description: "Anthropic's most capable generally available model for autonomous knowledge work and coding."
    cost_indicator: "$$$$"
    max_context_tokens: 1_000_000
    proxy_provider: anthropic
    model_class_provider: anthropic
    uses_cache_breakpoints: true
    family:
      - claude
    params:
      model: "claude-fable-5-2"
      max_tokens: 128_000
      # Fable 5.2 enforces preserved thinking, and DWS edits history (model switch, trim, compaction).
      # Drop stale thinking blocks instead of failing the turn with a 400.
      thinking:
        type: "adaptive"
        block_binding:
          prefix_mismatch_behavior: "drop_block"
      # Replaces the container's default betas, so keep context-1m-2025-08-07 listed.
      betas:
        - "context-1m-2025-08-07"
        - "thinking-binding-controls-2026-08-01"

  - name: "Claude Mythos 5.1"
    provider: "Anthropic"
    gitlab_identifier: "claude_mythos_5_1"
+3
Changes for ai_gateway/model_selection/unit_primitives.yml: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -251,6 +251,7 @@ configurable_unit_primitives:
      - "claude_fable_5_1"
      - "claude_fable_5_1_vertex"
      - "claude_fable_5_1_bedrock"
      - "claude_fable_5_2"
      - "gemini_3_5_flash_vertex"
      - "gemini_3_7_flash_vertex"
      - "gemini_3_7_flash_medium_vertex"
@@ -338,6 +339,7 @@ configurable_unit_primitives:
      - "claude_fable_5_1"
      - "claude_fable_5_1_vertex"
      - "claude_fable_5_1_bedrock"
      - "claude_fable_5_2"
      - "gemini_3_5_flash_vertex"
      - "gemini_3_7_flash_vertex"
      - "gemini_3_7_flash_medium_vertex"
@@ -445,6 +447,7 @@ configurable_unit_primitives:
      - "claude_fable_5_1"
      - "claude_fable_5_1_vertex"
      - "claude_fable_5_1_bedrock"
      - "claude_fable_5_2"
      - "gemini_3_5_flash_vertex"
      - "gemini_3_7_flash_vertex"
      - "gemini_3_8_flash_vertex"
+34
Changes for tests/model_selection/test_models.py: 34 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -174,6 +174,40 @@ class TestChatAnthropicParams:
                model="claude-fable-5-1", api_key="sk-ant-x", workload_identity=self.WIF
            )

    def test_block_binding_dumps_to_the_api_request_shape(self):
        params = ChatAnthropicParams(
            thinking={
                "type": "adaptive",
                "block_binding": {"prefix_mismatch_behavior": "drop_block"},
            },
            betas=["thinking-binding-controls-2026-08-01"],
        )

        dumped = params.model_dump(exclude_none=True)

        assert dumped["thinking"] == {
            "type": "adaptive",
            "block_binding": {"prefix_mismatch_behavior": "drop_block"},
        }
        assert dumped["betas"] == ["thinking-binding-controls-2026-08-01"]

    @pytest.mark.parametrize(
        "thinking",
        [
            {"type": "disabled"},
            {"type": "adaptive", "budget_tokens": 1024},
            {
                "type": "adaptive",
                "block_binding": {"prefix_mismatch_behavior": "ignore"},
            },
        ],
    )
    def test_thinking_rejects_unsupported_shapes(self, thinking):
        with pytest.raises(ValidationError):
            ChatAnthropicParams(
                thinking=thinking, betas=["thinking-binding-controls-2026-08-01"]
            )


# Each params class with the fields it requires besides max_retries.
_PARAMS_CLASSES = [