model_capabilities

model_capabilities.py — Provider capability registry for LLM model dispatch.

Replaces the fragile "gemini" in model.lower() substring checks in openrouter_client with an explicit pattern-matched registry.

Usage:

from model_capabilities import get_capabilities

caps = get_capabilities(model)
if caps.provider == "google":
    ...  # inject reasoning field, apply Gemini-specific sanitization
if caps.requires_reasoning_field:
    ...
class model_capabilities.ModelCapabilities(provider='openrouter', requires_reasoning_field=False, supports_multimodal=True, supports_system_role=True, supports_tool_calls=True)[source]

Bases: object

Immutable capability record for a matched model pattern.

A frozen dataclass describing what an LLM endpoint supports, so callers can branch on provider quirks instead of repeating brittle substring checks. The flags drive provider-specific request shaping in the OpenRouter client – for example whether to inject a separate reasoning / thinking field, whether a system role is accepted, and whether multimodal parts or tool calls are allowed.

Instances are constructed in this module’s _REGISTRY (one per glob pattern) and the _DEFAULT fallback, and are returned by get_capabilities. Being frozen, a single instance is shared by every model that matches a given pattern, so it must never be mutated by callers.

Parameters:
  • provider (str)

  • requires_reasoning_field (bool)

  • supports_multimodal (bool)

  • supports_system_role (bool)

  • supports_tool_calls (bool)

provider: str = 'openrouter'

‘google’, ‘anthropic’, ‘openai’, ‘deepseek’, ‘openrouter’.

Type:

Canonical provider name

requires_reasoning_field: bool = False

True when the API requires a separate reasoning / thinking JSON field.

supports_multimodal: bool = True

True when the model accepts image/audio/video content parts.

supports_system_role: bool = True

True when the model accepts a system role message.

supports_tool_calls: bool = True

True when the model supports function/tool calling.

model_capabilities.get_capabilities(model)[source]

Return the ModelCapabilities for model.

Matches the model identifier against _REGISTRY using fnmatch.fnmatch() (case-insensitive). Falls back to legacy substring heuristics for unregistered models that still contain well-known provider keywords, then returns safe defaults.

Parameters:

model (str) – The model identifier string (e.g. "gemini-2.5-pro").

Return type:

ModelCapabilities

Returns:

ModelCapabilities instance; never raises.