Model Metadata

What LLM4S knows about a model - its context window, output limit, prices and capabilities - and how to look it up or supply your own.

Table of contents

  1. Overview
  2. Where the data comes from
    1. Embedded overrides
    2. Refreshing the snapshot
  3. Looking a model up
    1. Estimating a cost
    2. Listing and searching
  4. Your own metadata
    1. Keys that change what is sent
  5. Configuration
  6. API summary
  7. Running the example
  8. See also

Overview

ModelRegistryService (in llm4s-core, package org.llm4s.model) is an immutable snapshot of model metadata. The provider clients use it to find a model’s context window and output limit, the request rules a model needs (which reasoning levels it takes, which parameters it rejects) and its prices, which give Completion.estimatedCost.

LLMConnect.getClient takes the registry as a using parameter, so an application builds one at its edge and passes it down:

1
2
3
4
5
6
7
8
9
10
import org.llm4s.config.Llm4sConfig
import org.llm4s.llmconnect.LLMConnect
import org.llm4s.model.ModelRegistryService

for {
  providerConfig <- Llm4sConfig.defaultProvider()
  registry       <- Llm4sConfig.modelRegistryService()
  given ModelRegistryService = registry
  client <- LLMConnect.getClient(providerConfig)
} yield client

Llm4sConfig.modelRegistryService() reads the llm4s.modelRegistry block (see Configuration). ModelRegistryService.default() returns the bundled catalogue without reading any configuration, for code that builds its provider config from values.

Where the data comes from

The bundled catalogue is a vendored copy of LiteLLM’s model metadata, modules/core/src/main/resources/modeldata/litellm_model_metadata.json, refreshed from upstream periodically. It covers OpenAI, Anthropic, Gemini, Azure, Bedrock, Mistral, DeepSeek, xAI, Ollama and many hosted models, with context windows, prices per token and capability flags.

Embedded overrides

Upstream occasionally drops or mis-shapes entries llm4s relies on (a chat model regressing to an embedding row, or a canonical id being removed, so a lookup of it fails). So that the vendored snapshot stays a clean, refreshable copy, llm4s layers a small curated corrections file over it: modules/core/src/main/resources/modeldata/llm4s_model_overrides.json. Its entries take precedence over the snapshot and survive refreshes. The overlay is applied only to the bundled default resource; a file, URL or other resource you configure is loaded as it is. A missing or unparseable overrides file is not fatal: the snapshot is used alone.

An override entry replaces the snapshot’s entry of the same id whole, so a correction can drop a key the snapshot should not have. An entry with "llm4s_patch": true instead sets only the keys it lists and keeps the rest of the snapshot’s entry, prices included, so a flag LiteLLM does not carry can be added without freezing the entry against future refreshes. A patch for an id the snapshot does not have is skipped with a warning. This is how supports_budget_thinking: false (ModelCapabilities.supportsBudgetThinking) marks the models that reject a manual thinking budget (RFC 0008):

1
2
3
4
"claude-opus-4-7": {
    "llm4s_patch": true,
    "supports_budget_thinking": false
}

The overrides patch every Claude model that rejects a budget: Opus 4.7 and 4.8 and the Claude 5 models, on Anthropic’s API, Bedrock, Vertex AI and Azure AI. A test fails when a refreshed snapshot has a member of those families without its patch.

An override can also carry a whole entry for a current model the snapshot predates, copied from LiteLLM’s upstream file and checked against the vendor’s pricing page; the next refresh of the snapshot makes it redundant. Two whole entries remain because upstream no longer lists those ids at all: gemini/gemini-1.5-flash and claude-3-7-sonnet-latest, so that a lookup of either finds the vendor’s own row rather than a substring match on another host’s.

Refreshing the snapshot

The snapshot is refreshed from upstream as a step of every release (Release Process):

  1. Replace litellm_model_metadata.json with upstream’s file, byte for byte: curl -sSfL -o modules/core/src/main/resources/modeldata/litellm_model_metadata.json https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json. Never edit it by hand; a correction goes in the overrides.
  2. List the ids the new file drops and search the repository for each one llm4s code, tests, docs or samples use, and for a provider/model id its bare model too, which a host-inferred lookup adds the prefix to. An id a test only passes as a string needs nothing; a lookup that now misses gets an override, or the test or guide moves to a current id.
  3. Compare every override with upstream’s new entry: delete a whole entry upstream now carries unchanged, and a patch whose keys upstream now sets the same way or whose id upstream dropped (it would only be skipped with a warning). A new id in a family a patch covers (another Bedrock region, a point release) gets the same patch, so the family stays consistent; ModelRegistryServiceSpec fails on an unpatched member.
  4. Run the tests of the modules that read the registry (core, capabilities, the provider modules, java-api and config-policy): some pin a window or a capability flag from the bundled data.

Looking a model up

lookup(modelId) and lookup(provider, modelName) return a Result[ModelMetadata]. An id that is not an exact key is matched without case, then without a provider/ prefix; an unknown model is a Left.

1
2
3
4
5
6
7
8
9
10
11
12
13
import org.llm4s.model.ModelRegistryService
import org.llm4s.types.ProviderModelTypes.ModelName

def describe(registry: ModelRegistryService): Unit =
  registry.lookup(ModelName("gpt-5.6-terra")) match {
    case Right(metadata) =>
      println(s"Context window: ${metadata.contextWindow.getOrElse("unknown")}")
      println(s"Output limit: ${metadata.reserveCompletion.getOrElse("unknown")}")
      println(s"Supports vision: ${metadata.supports("vision")}")
      println(metadata.description)
    case Left(error) =>
      println(s"Model not found: ${error.message}")
  }

ModelMetadata carries modelId, provider, mode (a ModelMode: Chat, Embedding, Completion, ImageGeneration, AudioTranscription, AudioSpeech, Moderation, Rerank, Search or Unknown), maxInputTokens, maxOutputTokens, capabilities, pricing and deprecationDate, and derives:

Member Meaning
contextWindow: Option[Int] maxInputTokens, else maxOutputTokens
reserveCompletion: Option[Int] maxOutputTokens
supports(capability: String): Boolean A capability flag; see below
isDeprecated: Boolean / isDeprecatedOn(date) deprecationDate (a LocalDate) is today, or the given date, or earlier
description: String One line: id, provider, context window and capabilities

supports takes function_calling (or tools), parallel_function_calling, vision (or images), prompt_caching (or caching), reasoning, response_schema (or structured), system_messages, pdf_input (or pdf), audio_input, audio_output, web_search, computer_use, assistant_prefill (or prefill), tool_choice and native_streaming (or streaming). A flag the metadata does not set counts as false, except streaming, which counts as true; any other name is false.

Estimating a cost

1
2
3
4
5
import org.llm4s.model.ModelRegistryService
import org.llm4s.types.ProviderModelTypes.ModelName

def estimate(registry: ModelRegistryService): Option[Double] =
  registry.lookup(ModelName("gpt-5.6-terra")).toOption.flatMap(_.pricing.estimateCost(inputTokens = 10000, outputTokens = 2000))

estimateCost multiplies by pricing.inputCostPerToken and pricing.outputCostPerToken, and is None when either is unknown. ModelPricing also carries the cache write and read prices, batch and priority prices, the reasoning-token price and the audio and image prices the metadata gives.

Listing and searching

1
2
3
4
5
6
7
8
9
10
import org.llm4s.model.{ ModelMode, ModelRegistryService }
import org.llm4s.types.ProviderModelTypes.ProviderId

def survey(registry: ModelRegistryService): Unit = {
  registry.findByCapability("vision").foreach(models => println(s"${models.size} vision models"))
  registry.listByProvider(ProviderId("openai")).foreach(models => models.take(5).foreach(m => println(m.modelId)))
  registry.listByMode(ModelMode.Embedding).foreach(models => println(s"${models.size} embedding models"))
  println(registry.listProviders().mkString(", "))
  registry.search("sonnet").foreach(m => println(m.modelId))
}

lookup matches an exact id, ignoring case and a provider/ prefix, and never a model whose id only contains the text; search returns every model whose id contains it, for a picker or a “did you mean”.

Your own metadata

A registry is a snapshot: nothing is registered into it after it is built. To use metadata of your own, build the registry from it.

From configuration, at the application edge, point llm4s.modelRegistry at a file, a URL or a classpath resource in LiteLLM’s format (see Configuration); Llm4sConfig.modelRegistryService() then loads it once at startup. The source replaces the bundled catalogue, so it must contain every model your providers use.

In code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import org.llm4s.model.{ ModelCapabilities, ModelMetadata, ModelMode, ModelPricing, ModelRegistryService }
import org.llm4s.types.Result
import org.llm4s.types.ProviderModelTypes.{ ModelName, ProviderId }

// a closed set of models, for example in tests
val inHouse = ModelMetadata(
  modelId = ModelName("my-custom-llm"),
  provider = ProviderId("custom"),
  mode = ModelMode.Chat,
  maxInputTokens = Some(32000),
  maxOutputTokens = Some(8000),
  capabilities = ModelCapabilities(supportsFunctionCalling = Some(true)),
  pricing = ModelPricing(inputCostPerToken = Some(1e-6), outputCostPerToken = Some(3e-6)),
  deprecationDate = None
)
val closed: ModelRegistryService = ModelRegistryService.fromModels(Seq(inHouse))

// a catalogue in LiteLLM's JSON format, from a string, a file or a URL
val fromJson: Result[ModelRegistryService] = ModelRegistryService.fromJsonString(
  """{ "my-model": { "litellm_provider": "custom", "mode": "chat", "max_input_tokens": 16000,
    |  "max_output_tokens": 4000, "supports_function_calling": true } }""".stripMargin
)
val fromFile: Result[ModelRegistryService] = ModelRegistryService.fromFile("/etc/llm4s/models.json")

fromFile, fromUrl and fromJsonString apply no overrides; entries that cannot be read are logged and skipped. For duplicate ids in fromModels the last one wins.

Keys that change what is sent

Most capability keys only describe a model. These decide what a client sends, and each change is reported on Completion.adjustments:

Key ModelCapabilities Effect
supports_sampling_params: false supportsSamplingParams The model takes no temperature, top_p or top_k (Claude Opus 4.7 and later, the Claude 5 models, some Gemini 3 models). The Anthropic, Bedrock, OpenAI, Gemini, Vertex AI and OpenAI-compatible clients send none, and one you set is reported Dropped. The bundled snapshot carries it; absent means unknown, and the parameters are sent as set.
disallowed_params: ["temperature", ...] disallowedParams The same for the parameters listed (temperature, top_p, presence_penalty, frequency_penalty). No entry of the bundled snapshot has this key: it is for an entry of your own, such as a deployment name the snapshot does not know.
temperature_constraint: [min, max] temperatureConstraint A temperature outside the range is moved to min, reported Adjusted.
supports_budget_thinking: false supportsBudgetThinking The model rejects a manual thinking budget; see Embedded overrides. An llm4s key, set only in the overrides.
thinking_always_on: true, supports_none_reasoning_effort: false supportsThinkingOff = Some(false) The model cannot be asked not to think: Thinking.Off is not sent, reported Adjusted.

llm4s-anthropic and llm4s-bedrock also know the Claude models by name, for an id no entry describes; what an entry states wins over the name.

To correct one model’s context window without replacing the catalogue, set it on the provider section instead: contextWindow and reserveCompletion are keys of the generic openai-compatible and Perplexity sections, among others (see Providers).

The JSON format is LiteLLM’s:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "model-id": {
    "litellm_provider": "provider-name",
    "mode": "chat",
    "max_input_tokens": 128000,
    "max_output_tokens": 16384,
    "input_cost_per_token": 2.5e-6,
    "output_cost_per_token": 1e-5,
    "supports_function_calling": true,
    "supports_vision": true,
    "supports_prompt_caching": true
  }
}

Configuration

Exactly one source is used; set one key, or none for the bundled catalogue.

Key / Variable Description Example
llm4s.modelRegistry.resourcePath / LLM4S_MODEL_REGISTRY_RESOURCE Classpath resource containing model metadata /modeldata/litellm_model_metadata.json
llm4s.modelRegistry.filePath / LLM4S_MODEL_REGISTRY_FILE Path to a model metadata file loaded at boot /path/to/models.json
llm4s.modelRegistry.url / LLM4S_MODEL_REGISTRY_URL URL of a model metadata file loaded at boot https://example.com/models.json

Llm4sConfig.modelRegistryConfig() returns the ModelRegistryConfig these keys describe, and ModelRegistryService.fromConfig(config) builds a registry from one built in code.

API summary

ModelRegistryService Description
lookup(modelId: ModelName): Result[ModelMetadata] A model by id
lookup(provider: ProviderId, modelName: ModelName): Result[ModelMetadata] A model by provider and name
listByProvider(provider: ProviderId): Result[List[ModelMetadata]] Every model of a provider
listByMode(mode: ModelMode): Result[List[ModelMetadata]] Every model of a mode
findByCapability(capability: String): Result[List[ModelMetadata]] Every model with a capability
listProviders(): List[ProviderId] The providers present
search(query: String): List[ModelMetadata] Every model whose id contains query
ModelRegistryService companion Description
default(): Result[ModelRegistryService] The bundled catalogue with overrides, no configuration read
fromConfig(config: ModelRegistryConfig) Exactly one of resource, file or URL
fromResource(path) / fromFile(path) / fromUrl(url) / fromJsonString(json) One source, as a Result
fromModels(models: Iterable[ModelMetadata]): ModelRegistryService A snapshot of the given values

Running the example

1
sbt "samples/runMain org.llm4s.samples.model.ModelMetadataExample"

It looks models up, checks capabilities, estimates costs and lists providers.

See also

  • Providers: where each provider takes its context window from
  • Cost controls: reasoning levels, prompt caching and service tiers, which use these flags
  • Tests: org.llm4s.model.ModelRegistryServiceSpec, org.llm4s.model.ModelRegistryLookupSpec, org.llm4s.model.ModelMetadataSpec