ModelRegistry

org.llm4s.model.ModelRegistry
object ModelRegistry

Central registry for LLM model metadata.

This provides a singleton lookup service for model capabilities, pricing, and constraints. It loads data from the embedded litellm metadata file and supports runtime updates from external sources.

Example usage:

 val metadata = ModelRegistry.lookup("gpt-4o")
 metadata.foreach { m =>
   println(s"Context window: $${m.contextWindow}")
   println(s"Supports vision: $${m.supports("vision")}")
 }

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def findByCapability(capability: String): Result[List[ModelMetadata]]

Find models that support a specific capability.

Find models that support a specific capability.

Value parameters

capability

The capability name (e.g., "vision", "function_calling")

Attributes

Returns

List of models supporting that capability

def initialize(customMetadataPath: Option[String]): Result[Unit]

Initialize the registry by loading embedded metadata. This is called automatically on first access, but can be called explicitly.

Initialize the registry by loading embedded metadata. This is called automatically on first access, but can be called explicitly.

Value parameters

customMetadataPath

Optional path to a custom metadata JSON file to load after the embedded metadata.

Attributes

Returns

Result indicating success or failure

Get all models of a specific mode (chat, embedding, etc.).

Get all models of a specific mode (chat, embedding, etc.).

Value parameters

mode

The model mode

Attributes

Returns

List of models for that mode

def listByProvider(provider: String): Result[List[ModelMetadata]]

Get all models for a specific provider.

Get all models for a specific provider.

Value parameters

provider

The provider name

Attributes

Returns

List of models for that provider

def listProviders(): Result[List[String]]

Get all available providers.

Get all available providers.

Attributes

Returns

List of unique provider names

def loadCustomMetadata(filePath: String): Result[Unit]

Load custom model metadata from a file. Custom metadata takes precedence over embedded metadata.

Load custom model metadata from a file. Custom metadata takes precedence over embedded metadata.

Value parameters

filePath

Path to the custom metadata JSON file

Attributes

Returns

Result indicating success or failure

def loadCustomMetadataFromString(jsonContent: String): Result[Unit]

Load custom metadata from a JSON string.

Load custom metadata from a JSON string.

Value parameters

jsonContent

JSON string containing model metadata

Attributes

Returns

Result indicating success or failure

def lookup(modelId: String): Result[ModelMetadata]

Lookup model metadata by model identifier.

Lookup model metadata by model identifier.

The lookup supports several formats:

  • Exact match: "gpt-4o", "claude-3-7-sonnet-latest"
  • Provider/model: "openai/gpt-4o", "anthropic/claude-3-7-sonnet-latest"
  • Fuzzy match: partial model names

Value parameters

modelId

The model identifier to lookup

Attributes

Returns

Model metadata if found

def lookup(provider: String, modelName: String): Result[ModelMetadata]

Lookup model metadata by provider and model name.

Lookup model metadata by provider and model name.

Value parameters

modelName

The model name (e.g., "gpt-4o")

provider

The provider name (e.g., "openai", "anthropic")

Attributes

Returns

Model metadata if found

def register(metadata: ModelMetadata): Unit

Register custom model metadata. This allows adding or overriding individual models.

Register custom model metadata. This allows adding or overriding individual models.

Value parameters

metadata

The model metadata to register

Attributes

def registerAll(models: List[ModelMetadata]): Unit

Register multiple custom models.

Register multiple custom models.

Value parameters

models

List of model metadata to register

Attributes

def reset(): Unit

Clear all metadata and reset the registry. Mainly useful for testing.

Clear all metadata and reset the registry. Mainly useful for testing.

Attributes

def statistics(): Map[String, Any]

Get statistics about the loaded metadata.

Get statistics about the loaded metadata.

Attributes

Returns

Map of statistics

def updateFromUrl(url: String): Result[Unit]

Update the registry with fresh metadata from an external source.

Update the registry with fresh metadata from an external source.

Value parameters

url

URL to fetch metadata from (defaults to litellm GitHub)

Attributes

Returns

Result indicating success or failure