LLMDB.Model (LLM DB v2026.2.1)

Copy Markdown View Source

Model struct with Zoi schema validation.

Represents an LLM model with complete metadata including identity, provider, dates, limits, costs, pricing, modalities, capabilities, tags, lifecycle status, and aliases.

Pricing Fields

Models have two pricing-related fields:

  • :cost - Legacy simple pricing (per-million-token rates for input/output/cache/reasoning)
  • :pricing - Flexible component-based pricing with support for tokens, tools, images, storage

The :cost field is automatically converted to :pricing.components at load time for backward compatibility. See LLMDB.Pricing and the Pricing and Billing guide.

Summary

Functions

Creates a new Model struct from a map, validating with Zoi schema.

Creates a new Model struct from a map, raising on validation errors.

Returns the Zoi schema for Model

Formats a model as a spec string in the given format.

Types

t()

@type t() :: %LLMDB.Model{
  aliases: [binary()],
  base_url: nil | binary(),
  capabilities:
    nil
    | %{
        :tools => %{
          optional(:enabled) => nil | boolean(),
          optional(:strict) => nil | boolean(),
          optional(:parallel) => nil | boolean(),
          optional(:streaming) => nil | boolean(),
          optional(:forced_choice) => nil | boolean()
        },
        :json => %{
          optional(:native) => nil | boolean(),
          optional(:strict) => nil | boolean(),
          optional(:schema) => nil | boolean()
        },
        :reasoning => %{
          optional(:enabled) => nil | boolean(),
          optional(:token_budget) => nil | integer()
        },
        :streaming => %{
          optional(:text) => nil | boolean(),
          optional(:tool_calls) => nil | boolean()
        },
        :chat => boolean(),
        :embeddings =>
          boolean()
          | %{
              optional(:min_dimensions) => nil | integer(),
              optional(:max_dimensions) => nil | integer(),
              optional(:default_dimensions) => nil | integer()
            },
        optional(:caching) => nil | %{optional(:type) => nil | binary()}
      },
  cost:
    nil
    | %{
        optional(:input) => nil | number(),
        optional(:output) => nil | number(),
        optional(:request) => nil | number(),
        optional(:image) => nil | number(),
        optional(:cache_read) => nil | number(),
        optional(:cache_write) => nil | number(),
        optional(:training) => nil | number(),
        optional(:reasoning) => nil | number(),
        optional(:audio) => nil | number(),
        optional(:input_audio) => nil | number(),
        optional(:output_audio) => nil | number(),
        optional(:input_video) => nil | number(),
        optional(:output_video) => nil | number()
      },
  deprecated: boolean(),
  extra: nil | map(),
  family: nil | binary(),
  id: binary(),
  knowledge: nil | binary(),
  last_updated: nil | binary(),
  lifecycle:
    nil
    | %{
        optional(:status) => nil | binary(),
        optional(:replacement) => nil | binary(),
        optional(:deprecated_at) => nil | binary(),
        optional(:retires_at) => nil | binary()
      },
  limits:
    nil
    | %{
        optional(:output) => nil | integer(),
        optional(:context) => nil | integer()
      },
  modalities:
    nil
    | %{optional(:input) => nil | [atom()], optional(:output) => nil | [atom()]},
  model: nil | binary(),
  name: nil | binary(),
  pricing:
    nil
    | %{
        :merge => binary(),
        optional(:currency) => nil | binary(),
        components: [
          %{
            :id => binary(),
            optional(:unit) => nil | binary(),
            optional(:kind) => nil | binary(),
            optional(:tool) => nil | atom() | binary(),
            optional(:per) => nil | integer(),
            optional(:rate) => nil | number(),
            optional(:meter) => nil | binary(),
            optional(:size_class) => nil | binary(),
            optional(:notes) => nil | binary()
          }
        ]
      },
  provider: atom(),
  provider_model_id: nil | binary(),
  release_date: nil | binary(),
  tags: nil | [binary()]
}

Functions

new(attrs)

@spec new(map()) :: {:ok, t()} | {:error, term()}

Creates a new Model struct from a map, validating with Zoi schema.

Examples

iex> LLMDB.Model.new(%{id: "gpt-4", provider: :openai})
{:ok, %LLMDB.Model{id: "gpt-4", model: "gpt-4", provider: :openai}}

iex> LLMDB.Model.new(%{})
{:error, _validation_errors}

new!(attrs)

@spec new!(map()) :: t()

Creates a new Model struct from a map, raising on validation errors.

Examples

iex> LLMDB.Model.new!(%{id: "gpt-4", provider: :openai})
%LLMDB.Model{id: "gpt-4", model: "gpt-4", provider: :openai}

schema()

Returns the Zoi schema for Model

spec(model, format \\ nil)

@spec spec(t(), atom() | nil) :: String.t()

Formats a model as a spec string in the given format.

Delegates to LLMDB.Spec.format_spec/2 with the model's provider and ID. If no format is specified, uses the application config :llm_db, :model_spec_format (default: :provider_colon_model).

Parameters

  • model - The model struct
  • format - Optional format override (:provider_colon_model, :model_at_provider, :filename_safe)

Examples

iex> model = %LLMDB.Model{provider: :openai, id: "gpt-4"}
iex> LLMDB.Model.spec(model)
"openai:gpt-4"

iex> LLMDB.Model.spec(model, :model_at_provider)
"gpt-4@openai"

iex> LLMDB.Model.spec(model, :filename_safe)
"gpt-4@openai"