mlflow/mlflow · error · ValueError
Invalid route type {route_type}
Error message
Invalid route type {route_type} What it means
OpenAIProvider.get_endpoint_url maps a gateway route type string ('llm/v1/chat', 'llm/v1/completions', 'llm/v1/embeddings') to an OpenAI path. Any other route_type value raises a plain ValueError. It is an internal invariant error, normally not caused by user API calls but by a mis-registered route.
Source
Thrown at mlflow/gateway/providers/openai.py:268
result_headers.pop("authorization", None)
result_headers.pop("api-key", None)
result_headers = client_headers | result_headers
return result_headers
@property
def adapter_class(self):
return OpenAIAdapter
def get_endpoint_url(self, route_type: str) -> str:
if route_type == "llm/v1/chat":
route_path = "chat/completions"
elif route_type == "llm/v1/completions":
route_path = "completions"
elif route_type == "llm/v1/embeddings":
route_path = "embeddings"
else:
raise ValueError(f"Invalid route type {route_type}")
# Append the route path to the base URL. Note that we cannot simply append the route path
# at the end of the base URL because it has query parameters for the Azure OpenAI case.
parsed_base_url = urlparse(self.base_url)
return urlunparse(parsed_base_url._replace(path=f"{parsed_base_url.path}/{route_path}"))
async def _chat_stream(
self, payload: chat.RequestPayload
) -> AsyncIterable[chat.StreamResponsePayload]:
from fastapi.encoders import jsonable_encoder
payload = jsonable_encoder(payload, exclude_none=True)
self.check_for_model_field(payload)
# Inject stream_options.include_usage=true to get usage in final chunk
if payload.get("stream_options") is None:
payload["stream_options"] = {"include_usage": True}
elif "include_usage" not in payload["stream_options"]:View on GitHub (pinned to 6a27f2decc)
Solutions
- Use exactly one of the route type strings 'llm/v1/chat', 'llm/v1/completions', or 'llm/v1/embeddings'.
- If passing an EndpointType enum, convert it to its string value (str(endpoint_type)) before calling get_endpoint_url.
- Create routes via mlflow.gateway.start_server / MlflowException-facing public APIs rather than calling get_endpoint_url directly.
- Check the MLflow version; route type naming changed historically, so align code examples with your installed version.
Example fix
// before provider.get_endpoint_url(EndpointType.LLM_V1_CHAT) // after provider.get_endpoint_url(str(EndpointType.LLM_V1_CHAT)) # 'llm/v1/chat'
Defensive patterns
Strategy: type-guard
Validate before calling
VALID = {"llm/v1/chat", "llm/v1/completions", "llm/v1/embeddings"}
assert route_type in VALID, f"unsupported route type: {route_type}" Type guard
def is_valid_route_type(rt) -> bool:
return isinstance(rt, str) and rt in {"llm/v1/chat", "llm/v1/completions", "llm/v1/embeddings"} Try / catch
try:
url = provider.get_endpoint_url(route_type)
except ValueError as e:
logging.error("Invalid route type: %s", e)
raise Prevention
- Use EndpointType constants converted with str() instead of hand-written strings
- Register routes via mlflow.gateway public APIs, not provider internals
- Pin MLflow docs/examples to your installed version
When it happens
Trigger: Registering or invoking a gateway route whose route_type string is not one of 'llm/v1/chat', 'llm/v1/completions', 'llm/v1/embeddings' (e.g. 'llm/v1/embedding', 'chat', or an EndpointType enum not converted to its string form).
Common situations: Programmatic route registration with a mistyped route type, custom code calling get_endpoint_url directly with an enum instead of its string value, or older/newer MLflow route type names mixed across versions.
Related errors
- Invalid route type {route_type}
- Unsupported route_type '{route_type}' for Databricks provide
- Invalid route type {route_type}
- Endpoint {name!r} is not a chat endpoint.
- Endpoint {name!r} is not a completions endpoint.
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/475b335679da9aee.
Report an issue: GitHub.