mlflow/mlflow · error · TypeError

Unexpected config type {config.model.config}

Error message

Unexpected config type {config.model.config}

What it means

The MosaicML provider's constructor requires config.model.config to be a MosaicMLConfig instance; if it is None or another type a TypeError is raised at provider instantiation time. This is a programmer/config-shape guard: the provider cannot build its request headers (API key) without the typed config.

Source

Thrown at mlflow/gateway/providers/mosaicml.py:26

from mlflow.gateway.exceptions import AIGatewayException
from mlflow.gateway.providers.base import BaseProvider
from mlflow.gateway.providers.utils import rename_payload_keys, send_request
from mlflow.gateway.schemas import chat, completions, embeddings


class MosaicMLProvider(BaseProvider):
    DISPLAY_NAME = "MosaicML"
    CONFIG_TYPE = MosaicMLConfig

    def __init__(self, config: EndpointConfig, enable_tracing: bool = False) -> None:
        super().__init__(config, enable_tracing=enable_tracing)
        warnings.warn(
            "MosaicML provider is deprecated and will be removed in a future MLflow version.",
            category=FutureWarning,
            stacklevel=2,
        )
        if config.model.config is None or not isinstance(config.model.config, MosaicMLConfig):
            raise TypeError(f"Unexpected config type {config.model.config}")
        self.mosaicml_config: MosaicMLConfig = config.model.config

    async def _request(self, model: str, payload: dict[str, Any]) -> dict[str, Any]:
        headers = {"Authorization": f"{self.mosaicml_config.mosaicml_api_key}"}
        return await send_request(
            headers=headers,
            base_url=self.mosaicml_config.mosaicml_api_base
            or "https://models.hosted-on.mosaicml.hosting",
            path=model + "/v1/predict",
            payload=payload,
        )

    # NB: as this parser performs no blocking operations, we are intentionally not defining it
    # as async due to the overhead of spawning an additional thread if we did.
    @staticmethod
    def _parse_chat_messages_to_prompt(messages: list[chat.RequestMessage]) -> str:
        """
        This parser is based on the format described in

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Wrap the model config in MosaicMLConfig, e.g. MosaicMLConfig(mosaicml_api_key=os.environ["MOSAICML_API_KEY"]), and set it as config.model.config
  2. Validate your route config file so the endpoint's model config block matches the mosaicml schema before instantiating the provider
  3. Note the provider is deprecated (FutureWarning) — migrate the route to another provider (e.g. openai-compatible) to avoid maintaining it

Example fix

// before
config.model.config = {"mosaicml_api_key": "..."}
// after
from mlflow.gateway.config import MosaicMLConfig
config.model.config = MosaicMLConfig(mosaicml_api_key="...")
Defensive patterns

Strategy: validation

Validate before calling

from mlflow.gateway.config import MosaicMLConfig
if not isinstance(config.model.config, MosaicMLConfig):
    raise ValueError("route model.config must be a MosaicMLConfig")

Type guard

def is_mosaicml_config(cfg) -> bool:
    from mlflow.gateway.config import MosaicMLConfig
    return isinstance(cfg, MosaicMLConfig)

Prevention

When it happens

Trigger: Constructing the MosaicML provider with an EndpointConfig whose model.config is None or holds a plain dict / wrong config class instead of MosaicMLConfig.

Common situations: Hand-building provider instances in tests or custom code and forgetting to nest a MosaicMLConfig; loading a route config from YAML where the mosaicml config block is missing; passing OpenAIConfig or AnyscaleConfig to a mosaicml route.

Related errors


AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29). Data as JSON: /api/errors/d2f54b01d25bce46. Report an issue: GitHub.