Skip to content

LLM Registry API Reference

LLM model cost estimation and provider registry for 50+ models.

from axion.llm_registry import LLMRegistry

LLMRegistry

axion.llm_registry.LLMRegistry

LLMRegistry(provider: Optional[str] = None, **credentials)

A factory and registry for LLM and embedding model providers.

This class provides a unified interface for creating LLM and embedding clients from different providers using simple string identifiers or global settings.

Initializes the registry. If a provider is specified, it configures for that provider. Otherwise, it remains flexible to serve requests based on global settings.

Parameters:

  • provider (Optional[str], default: None ) –

    The name of the provider to lock this registry instance to.

  • **credentials

    Credentials required by the provider, such as 'api_key'.

default_llm_model_name property

default_llm_model_name: str

Default LLM model name

default_embedding_model_name property

default_embedding_model_name: str

Default Embedding model name

register classmethod

register(name: str)

A class method decorator to register a new provider.

display classmethod

display()

Display the LLM provider registry.

get_llm

get_llm(model_name: Optional[str] = None, provider: Optional[str] = None, **kwargs) -> Any

Gets a language model instance from a provider.

Uses the instance's locked provider if set, otherwise falls back to the globally configured settings.llm_provider.

Parameters:

  • model_name (Optional[str], default: None ) –

    The model name to use. Defaults to settings.model_name.

  • provider (Optional[str], default: None ) –

    Override the provider for this specific call.

  • **kwargs

    Additional parameters for the LLM's constructor.

Returns:

  • Any

    An instance of a language model client.

get_embedding_model

get_embedding_model(model_name: Optional[str] = None, provider: Optional[str] = None, **kwargs) -> Any

Gets an embedding model instance from a provider.

Uses the instance's locked provider if set, otherwise falls back to the globally configured settings.embedding_provider.

Parameters:

  • model_name (Optional[str], default: None ) –

    The model name to use. Defaults to settings.embedding_model.

  • provider (Optional[str], default: None ) –

    Override the provider for this specific call.

  • **kwargs

    Additional parameters for the embedding model's constructor.

Returns:

  • Any

    An instance of an embedding model client.

estimate_cost

estimate_cost(prompt_tokens: int, completion_tokens: int, model_name: Optional[str] = None, provider: Optional[str] = None) -> float

Estimates the cost of an LLM call based on token usage.

The method determines the correct provider and model based on the same precedence rules as get_llm (direct arguments > locked instance > global settings).

Parameters:

  • prompt_tokens (int) –

    The number of tokens in the prompt.

  • completion_tokens (int) –

    The number of tokens in the completion.

  • model_name (Optional[str], default: None ) –

    The model name to use for pricing. Defaults to settings.model_name.

  • provider (Optional[str], default: None ) –

    Override the provider for this specific call.

Returns:

  • float ( float ) –

    The estimated cost in USD.