Alloy.ModelMetadata (alloy v0.13.0)

Copy Markdown View Source

Built-in model metadata catalog used for context budgeting.

This is the default implementation of the Alloy.ModelCatalog behaviour. It covers the native-provider families (Claude, GPT-5 and GPT-6, Gemini 2.5 and 3.x, and Grok) at the input limit each vendor documents. Anything else, including models served through Alloy.Provider.OpenAICompat such as Kimi, Qwen, GLM, Mistral or Gemma, and retired model ids, gets default_context_window/0 (200,000 tokens).

For other models, implement Alloy.ModelCatalog (a static map, your own service, or an adapter over llm_db) and pass the module via the :model_catalog option. Per-run tweaks that don't warrant a catalog module belong in :model_metadata_overrides; overrides always win over any catalog.

Summary

Functions

Returns the known context window limit for a model name (Alloy.ModelCatalog callback).

Returns the known context window limit for a model name, consulting overrides ahead of the built-in catalog.

Returns the default fallback context window for unknown models.

Returns the context window for model_name from overrides alone, ignoring the built-in catalog.

Types

override_entry()

@type override_entry() ::
  pos_integer()
  | %{
      :limit => pos_integer(),
      optional(:suffix_patterns) => [String.t() | Regex.t()]
    }

overrides()

@type overrides() ::
  %{optional(String.t()) => override_entry()} | [{String.t(), override_entry()}]

Functions

context_window(model_name)

@spec context_window(String.t()) :: pos_integer() | nil

Returns the known context window limit for a model name (Alloy.ModelCatalog callback).

Returns nil when the model is not in the built-in catalog.

context_window(model_name, overrides)

@spec context_window(String.t(), overrides()) :: pos_integer() | nil

Returns the known context window limit for a model name, consulting overrides ahead of the built-in catalog.

overrides may provide exact-model or family overrides as either:

  • %{"model-name" => 1_000_000}
  • %{"model-name" => %{limit: 1_000_000, suffix_patterns: ["", ~r/^-+$/]}}

An override without :suffix_patterns on a model the catalog knows also covers that model's dated snapshots (a suffix starting with a four-digit stamp, such as -2026-03-05 or -20251001); on an unknown model it is exact-match only.

Returns nil when the model is not in the current catalog or overrides.

default_context_window()

@spec default_context_window() :: pos_integer()

Returns the default fallback context window for unknown models.

override_window(model_name, overrides)

@spec override_window(String.t(), overrides()) :: pos_integer() | nil

Returns the context window for model_name from overrides alone, ignoring the built-in catalog.

Used to apply :model_metadata_overrides ahead of any Alloy.ModelCatalog implementation. Returns nil when no override matches.