Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
263 changes: 106 additions & 157 deletions packages/genkit-anthropic/src/genkit_anthropic/_model_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,197 +20,146 @@

from genkit.model import ConstrainedSupport, ModelInfo, ModelSupports

# Model definitions
CLAUDE_SONNET_4 = ModelInfo(
label='Anthropic - Claude Sonnet 4',
versions=['claude-sonnet-4-20250514'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
),
)

CLAUDE_OPUS_4 = ModelInfo(
label='Anthropic - Claude Opus 4',
versions=['claude-opus-4-20250514'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
),
)

CLAUDE_SONNET_4_5 = ModelInfo(
label='Anthropic - Claude Sonnet 4.5',
versions=['claude-sonnet-4-5-20250929'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
output=['text', 'json'],
constrained=ConstrainedSupport.ALL,
),
# Every model in the catalog takes media input, tools, a system prompt and
# multi-turn history, and supports native structured output (output_config).
_CLAUDE_SUPPORTS = ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
output=['text', 'json'],
constrained=ConstrainedSupport.ALL,
)

CLAUDE_SONNET_4_6 = ModelInfo(
label='Anthropic - Claude Sonnet 4.6',
versions=['claude-sonnet-4-6'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
output=['text', 'json'],
constrained=ConstrainedSupport.ALL,
),
CLAUDE_FABLE_5_2 = ModelInfo(
label='Anthropic - Claude Fable 5.2',
versions=['claude-fable-5-2'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_SONNET_5 = ModelInfo(
label='Anthropic - Claude Sonnet 5',
versions=['claude-sonnet-5'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
output=['text', 'json'],
constrained=ConstrainedSupport.ALL,
),
CLAUDE_FABLE_5_1 = ModelInfo(
label='Anthropic - Claude Fable 5.1',
versions=['claude-fable-5-1'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_HAIKU_4_5 = ModelInfo(
label='Anthropic - Claude Haiku 4.5',
versions=['claude-haiku-4-5-20251001'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
output=['text', 'json'],
constrained=ConstrainedSupport.ALL,
),
)

CLAUDE_OPUS_4_1 = ModelInfo(
label='Anthropic - Claude Opus 4.1',
versions=['claude-opus-4-1-20250805'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
output=['text', 'json'],
constrained=ConstrainedSupport.ALL,
),
CLAUDE_FABLE_5 = ModelInfo(
label='Anthropic - Claude Fable 5',
versions=['claude-fable-5'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_OPUS_4_5 = ModelInfo(
label='Anthropic - Claude Opus 4.5',
versions=['claude-opus-4-5-20251101'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
output=['text', 'json'],
constrained=ConstrainedSupport.ALL,
),
)

# Source: https://docs.anthropic.com/en/docs/about-claude/models
# Released: February 5, 2026. Most capable model — excels in coding, agents,
# and enterprise workflows. Supports 1M context window (beta).
CLAUDE_OPUS_4_6 = ModelInfo(
label='Anthropic - Claude Opus 4.6',
versions=['claude-opus-4-6'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
output=['text', 'json'],
constrained=ConstrainedSupport.ALL,
),
CLAUDE_OPUS_5_5 = ModelInfo(
label='Anthropic - Claude Opus 5.5',
versions=['claude-opus-5-5'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_OPUS_4_7 = ModelInfo(
label='Anthropic - Claude Opus 4.7',
versions=['claude-opus-4-7'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
output=['text', 'json'],
constrained=ConstrainedSupport.ALL,
),
CLAUDE_OPUS_5 = ModelInfo(
label='Anthropic - Claude Opus 5',
versions=['claude-opus-5'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_OPUS_4_8 = ModelInfo(
label='Anthropic - Claude Opus 4.8',
versions=['claude-opus-4-8'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
output=['text', 'json'],
constrained=ConstrainedSupport.ALL,
),
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_OPUS_4_7 = ModelInfo(
label='Anthropic - Claude Opus 4.7',
versions=['claude-opus-4-7'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_FABLE_5 = ModelInfo(
label='Anthropic - Claude Fable 5',
versions=['claude-fable-5'],
supports=ModelSupports(
multiturn=True,
media=True,
tools=True,
system_role=True,
output=['text', 'json'],
constrained=ConstrainedSupport.ALL,
),
CLAUDE_OPUS_4_6 = ModelInfo(
label='Anthropic - Claude Opus 4.6',
versions=['claude-opus-4-6'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_OPUS_4_5 = ModelInfo(
label='Anthropic - Claude Opus 4.5',
versions=['claude-opus-4-5-20251101'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_SONNET_5_5 = ModelInfo(
label='Anthropic - Claude Sonnet 5.5',
versions=['claude-sonnet-5-5'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_SONNET_5 = ModelInfo(
label='Anthropic - Claude Sonnet 5',
versions=['claude-sonnet-5'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_SONNET_4_6 = ModelInfo(
label='Anthropic - Claude Sonnet 4.6',
versions=['claude-sonnet-4-6'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_HAIKU_5_5 = ModelInfo(
label='Anthropic - Claude Haiku 5.5',
versions=['claude-haiku-5-5'],
supports=_CLAUDE_SUPPORTS,
)

CLAUDE_HAIKU_4_5 = ModelInfo(
label='Anthropic - Claude Haiku 4.5',
versions=['claude-haiku-4-5-20251001'],
supports=_CLAUDE_SUPPORTS,
)

# Mythos models are limited to verified organizations, so they are not
# advertised; their ids still resolve through get_model_info.

# Quote autocomplete needs a Literal. The catalog below is what you edit when
# a Claude ships; a test requires these members and the dict keys to be the
# same set, and the dict is typed so a new key that is not in the Literal
# does not type-check.
KnownClaude: TypeAlias = Literal[
'claude-sonnet-4',
'claude-opus-4',
'claude-sonnet-4-5',
'claude-sonnet-4-6',
'claude-fable-5-2',
'claude-fable-5-1',
'claude-fable-5',
'claude-opus-5-5',
'claude-opus-5',
'claude-opus-4-8',
'claude-opus-4-7',
'claude-opus-4-6',
'claude-opus-4-5',
'claude-sonnet-5-5',
'claude-sonnet-5',
'claude-sonnet-4-6',
'claude-haiku-5-5',
'claude-haiku-4-5',
'claude-opus-4-1',
'claude-opus-4-5',
'claude-opus-4-6',
'claude-opus-4-7',
'claude-opus-4-8',
'claude-fable-5',
]

SUPPORTED_ANTHROPIC_MODELS: dict[KnownClaude, ModelInfo] = {
'claude-sonnet-4': CLAUDE_SONNET_4,
'claude-opus-4': CLAUDE_OPUS_4,
'claude-sonnet-4-5': CLAUDE_SONNET_4_5,
'claude-sonnet-4-6': CLAUDE_SONNET_4_6,
'claude-fable-5-2': CLAUDE_FABLE_5_2,
'claude-fable-5-1': CLAUDE_FABLE_5_1,
'claude-fable-5': CLAUDE_FABLE_5,
'claude-opus-5-5': CLAUDE_OPUS_5_5,
'claude-opus-5': CLAUDE_OPUS_5,
'claude-opus-4-8': CLAUDE_OPUS_4_8,
'claude-opus-4-7': CLAUDE_OPUS_4_7,
'claude-opus-4-6': CLAUDE_OPUS_4_6,
'claude-opus-4-5': CLAUDE_OPUS_4_5,
'claude-sonnet-5-5': CLAUDE_SONNET_5_5,
'claude-sonnet-5': CLAUDE_SONNET_5,
'claude-sonnet-4-6': CLAUDE_SONNET_4_6,
'claude-haiku-5-5': CLAUDE_HAIKU_5_5,
'claude-haiku-4-5': CLAUDE_HAIKU_4_5,
'claude-opus-4-1': CLAUDE_OPUS_4_1,
'claude-opus-4-5': CLAUDE_OPUS_4_5,
'claude-opus-4-6': CLAUDE_OPUS_4_6,
'claude-opus-4-7': CLAUDE_OPUS_4_7,
'claude-opus-4-8': CLAUDE_OPUS_4_8,
'claude-fable-5': CLAUDE_FABLE_5,
}

# Fallback for ids that are not in the catalog, such as Mythos ids, dated ids
# and Vertex snapshot ids (`<model>@<date>`). Native structured output can't be
# assumed for them: a model without it rejects output_config, so the request
# would fail instead of using prompt-based JSON.
DEFAULT_SUPPORTS = ModelSupports(
multiturn=True,
media=True,
Expand Down
2 changes: 1 addition & 1 deletion packages/genkit-anthropic/src/genkit_anthropic/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Anthropic(Plugin):

@classmethod
def claude(cls, name: KnownClaude | str, *, config: AnthropicConfig | None = None) -> ModelRef[AnthropicConfig]:
"""Typed ref for a Claude model, e.g. ``Anthropic.claude('claude-sonnet-4-5')``.
"""Typed ref for a Claude model, e.g. ``Anthropic.claude('claude-sonnet-4-6')``.

Unknown ids are allowed so new Claude releases work before this
plugin learns their names; every Anthropic generate model takes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _model_failing_with(error: Exception) -> AnthropicModel:
"""Create a model whose non-streaming request raises an error."""
client = MagicMock()
client.messages.create = AsyncMock(side_effect=error)
return AnthropicModel(model_name='claude-sonnet-4', client=client)
return AnthropicModel(model_name='claude-sonnet-4-6', client=client)


@pytest.mark.asyncio
Expand Down Expand Up @@ -277,7 +277,7 @@ async def test_generate_maps_streaming_anthropic_errors() -> None:
api_error = _status_error(503, retry_after='1')
client = MagicMock()
client.messages.stream.return_value = _FailingStreamManager(api_error)
model = AnthropicModel(model_name='claude-sonnet-4', client=client)
model = AnthropicModel(model_name='claude-sonnet-4-6', client=client)
ctx = MagicMock()
ctx.is_streaming = True

Expand Down Expand Up @@ -397,7 +397,7 @@ async def test_streaming_in_band_error_event_with_unknown_type_is_unknown() -> N
def _model_never_called() -> tuple[AnthropicModel, MagicMock]:
client = MagicMock()
client.messages.create = AsyncMock()
return AnthropicModel(model_name='claude-sonnet-4', client=client), client
return AnthropicModel(model_name='claude-sonnet-4-6', client=client), client


@pytest.mark.asyncio
Expand Down
Loading
Loading