rohitg00/ai-engineering-from-scratch · error · ValueError

LLM_MODEL= is not in the pricing registry (known: )

Error message

LLM_MODEL={override!r} is not in the pricing registry (known: {known})

What it means

Module-import-time guard in resolve_primary_model: the LLM_MODEL env var was set and non-empty, but its value matches no ModelName enum entry, so no pricing row exists for it. The raise fires at import (while binding PRIMARY_MODEL), before any request is served.

Solutions

  1. Unset LLM_MODEL to fall back to the default claude-sonnet-5
  2. Set LLM_MODEL to a known enum value: claude-sonnet-5, gpt-4o, or gpt-4o-mini
  3. Add the model to the ModelName enum and its pricing entry before selecting it
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phases/11-llm-engineering/13-production-app/code/production_app.py:31 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/192af8a2bb9df20b. Report an issue: GitHub.

Appendix: source

Thrown at phases/11-llm-engineering/13-production-app/code/production_app.py:31

from enum import Enum
from typing import AsyncGenerator


class ModelName(Enum):
    CLAUDE_SONNET = "claude-sonnet-5"
    GPT_4O = "gpt-4o"
    GPT_4O_MINI = "gpt-4o-mini"


def resolve_primary_model() -> ModelName:
    override = (os.environ.get("LLM_MODEL") or "").strip()
    if not override:
        return ModelName.CLAUDE_SONNET
    for model in ModelName:
        if model.value == override:
            return model
    known = ", ".join(m.value for m in ModelName)
    raise ValueError(f"LLM_MODEL={override!r} is not in the pricing registry (known: {known})")


PRIMARY_MODEL = resolve_primary_model()


MODEL_PRICING = {
    ModelName.CLAUDE_SONNET: {"input": 3.00, "output": 15.00},
    ModelName.GPT_4O: {"input": 2.50, "output": 10.00},
    ModelName.GPT_4O_MINI: {"input": 0.15, "output": 0.60},
}

FALLBACK_CHAIN = [PRIMARY_MODEL] + [m for m in ModelName if m is not PRIMARY_MODEL]


@dataclass
class RequestLog:
    request_id: str
    user_id: str

View on GitHub (pinned to 39ea8a1c6d)