#26022·mlflow

[FR] Let the AI Gateway time out faster when a provider is slow to start responding

Author: pgorazdaCreated Sep 20, 2026Updated Sep 29, 2026
Labelsenhancementneeds author feedbackdomain/genaiarea/gateway

[!WARNING] Before submitting a PR, please make sure that:

  • A maintainer has triaged this issue and applied the ready label
  • This issue has no assignee
  • No duplicate PR exists

PRs not meeting these requirements may be automatically closed.

Willingness to contribute

Yes. I can contribute this feature independently.

Proposal Summary

Add an optional per-endpoint idle-read timeout to the AI Gateway's OpenAI provider, so a backend that hasn't sent back any data yet can be detected and aborted quickly — without affecting requests that are simply slow to finish a long, healthy response.

Motivation

What is the use case for this feature?

The AI Gateway has only one timeout setting: MLFLOW_GATEWAY_ROUTE_TIMEOUT_SECONDS (300 seconds by default). It covers the whole request, from start to finish, so it can't distinguish "backend hasn't sent a single byte yet" from "backend is healthy and still generating a long answer" — the only way to catch the first case today is to wait out the full timeout.

We send LLM traffic through the AI Gateway to RunPod serverless endpoints. When those are idle, they can take 300+ seconds to cold-start. We'd like to detect that within about 5 seconds and automatically fall back to a backup provider — a feature the Gateway already has (FALLBACK linkage) — without cutting off a normal request that's simply taking a while to complete.

Why is this use case valuable to support for MLflow users in general?

Anyone routing Gateway traffic to an autoscaling or scale-to-zero backend (serverless GPU providers, KEDA-scaled deployments, etc.) hits the same problem: cold starts and healthy long-running generations both look identical to a single full-response timeout. A time-to-first-token style timeout is a standard resilience pattern — LiteLLM's stream_timeout, for example, times out if too long passes between reads in a streaming response — and the Gateway doesn't currently offer anything equivalent.

Why is this use case valuable to support for your project(s) or organization?

Without it, a cold RunPod endpoint means every client request waits out the full timeout with no fallback, even though the Gateway's native FALLBACK linkage could otherwise recover transparently. This directly affects response latency for our users during cold starts.

Why is it currently difficult to achieve this use case?

MLFLOW_GATEWAY_ROUTE_TIMEOUT_SECONDS (default 300s) is applied as aiohttp.ClientTimeout(total=...) in mlflow/gateway/providers/utils.py, which bounds the entire response, not the gap between reads. There's no per-endpoint or per-model timeout field on any provider config today, so there's no way to configure a shorter "time to first byte" trigger without also truncating slow-but-healthy streamed generations.

Details

The fix is a timeout that only watches the gap between chunks of data, not the total request time. Python's aiohttp library already supports this — ClientTimeout(sock_read=...) times out if too much time passes between reads, no matter how long the overall response takes.

Proposed change: add a new optional setting, timeout_seconds, to the OpenAI provider's config. When set, it's passed to aiohttp as sock_read, alongside the existing total limit. If left unset, nothing changes — existing setups keep working exactly as they do today.

Already tested: we've run this change in production for about two months, pointed at real RunPod endpoints:

  • Local test: a backend that sends nothing for 120 seconds, with the new timeout set to 2 seconds, gets cut off in about 2.3 seconds.
  • Local test: a backend that responds slowly but steadily (a chunk every 0.8 seconds, ~4 seconds total) is NOT cut off, even though the whole request took longer than the 2-second setting — because no single gap was too long.
  • Live test: a real cold RunPod endpoint gets cut off and the request correctly retries with the backup provider.

While testing, we also found and fixed a separate, smaller bug: the "streaming passthrough" code path didn't actually retry with the backup provider on failure, because of how it builds its response. We can include that fix here or file it separately, whichever you'd prefer.

Open question — OpenAI-only, or all providers? The underlying single-timeout limitation isn't unique to the OpenAI provider — it's shared code used by almost every provider in the Gateway (Anthropic, Cohere, Bedrock, Gemini, Mistral, and the whole OpenAI-compatible family: Groq, DeepSeek, Ollama, OpenRouter, Portkey, SAP AI Core, XAI). The change we're proposing only adds the new setting to the OpenAI provider, since that's what we've tested. Open to either keeping it OpenAI-only for now (smaller, matches what we've verified), or adding it to the shared code so any provider could opt in later — happy to go with whichever you'd prefer.

We have the code change ready (5 files) plus tests, and would like to open a PR once the approach looks good to you.

What machine learning domain(s) is this feature request about?

  • domain/genai: LLMs, Agents, and other GenAI-related use cases
  • domain/classical-ml: Traditional machine learning, such as linear regression.
  • domain/deep-learning: Deep learning and neural networks.
  • domain/platform: MLflow platform foundation, not specific to a particular machine learning domain.

What area(s) of MLflow is this feature request about?

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/scoring: MLflow model serving, deployment tools, Spark UDFs
  • area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows
  • area/prompt: MLflow prompt engineering features, prompt templates, and prompt management
  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality
  • area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations
  • area/projects: MLproject format, project running backends
  • area/uiux: Front-end, user experience, plotting
  • area/docs: MLflow documentation pages