mlflow/mlflow · error · ValueError

Invalid route type {route_type}

Error message

Invalid route type {route_type}

What it means

CohereProvider.get_endpoint_url maps a gateway route_type to a Cohere REST path (chat/generate/embed) and raises ValueError for any route_type outside the three supported llm/v1 types. It guards against constructing requests to unknown Cohere endpoints.

Source

Thrown at mlflow/gateway/providers/cohere.py:360

        return {"Authorization": f"Bearer {self.cohere_config.cohere_api_key}"}

    @property
    def base_url(self) -> str:
        return "https://api.cohere.ai/v1"

    @property
    def adapter_class(self) -> type[ProviderAdapter]:
        return CohereAdapter

    def get_endpoint_url(self, route_type: str) -> str:
        if route_type == "llm/v1/chat":
            return f"{self.base_url}/chat"
        elif route_type == "llm/v1/completions":
            return f"{self.base_url}/generate"
        elif route_type == "llm/v1/embeddings":
            return f"{self.base_url}/embed"
        else:
            raise ValueError(f"Invalid route type {route_type}")

    async def _request(self, path: str, payload: dict[str, Any]) -> dict[str, Any]:
        return await send_request(
            headers=self.headers,
            base_url=self.base_url,
            path=path,
            payload=payload,
        )

    def _stream_request(self, path: str, payload: dict[str, Any]) -> AsyncGenerator[bytes, None]:
        return send_stream_request(
            headers=self.headers,
            base_url=self.base_url,
            path=path,
            payload=payload,
        )

    async def _chat_stream(

View on GitHub (pinned to 6a27f2decc)

Solutions

  1. Use one of the exact route types: 'llm/v1/chat', 'llm/v1/completions', or 'llm/v1/embeddings'.
  2. Fix typos in the endpoint's endpoint_type config value.
  3. If a custom route is needed, implement it in a custom provider rather than reusing CohereProvider.get_endpoint_url.

Example fix

// before
url = provider.get_endpoint_url("llm/v1/embedding")  # ValueError
// after
url = provider.get_endpoint_url("llm/v1/embeddings")
Defensive patterns

Strategy: validation

Validate before calling

COHERE_ROUTE_TYPES = {"llm/v1/chat", "llm/v1/completions", "llm/v1/embeddings"}

def validate_route_type(route_type: str):
    if route_type not in COHERE_ROUTE_TYPES:
        raise ValueError(f"Cohere supports only {sorted(COHERE_ROUTE_TYPES)}, got {route_type!r}")

Type guard

from typing import Literal
CohereRouteType = Literal["llm/v1/chat", "llm/v1/completions", "llm/v1/embeddings"]

def is_cohere_route_type(route_type: str) -> bool:
    return route_type in {"llm/v1/chat", "llm/v1/completions", "llm/v1/embeddings"}

Try / catch

try:
    url = provider.get_endpoint_url(route_type)
except ValueError as e:
    logger.error("Bad route_type for Cohere provider: %s", e)
    raise

Prevention

When it happens

Trigger: Invoking get_endpoint_url with a route_type such as 'llm/v1/foo', 'mistral/v1/chat', or a typo like 'llm/v1/embedding' (singular) that matches none of the if/elif branches.

Common situations: Typos in the endpoint_type field of gateway config; registering custom route types and assuming the Cohere provider supports them; programmatic provider use with a hand-written route type string.

Related errors


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