The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
chore(ci): sync main into internal staging
Yuneng Jiang09323fcc4a16
diff --cc tests/e2e/proxy_client.pyindex 2627bdb8038,b3fc8538322..5050b6fce68--- a/tests/e2e/proxy_client.py+++ b/tests/e2e/proxy_client.py@@@ -76,6 -75,120 +76,117 @@@ from transport import HttpTransport, SpRowsPredicate = Callable[[list[SpendLogRow]], bool]-# After /model/new, the control-plane writer reloads itself immediately, but every-# other gateway worker (and peer pod) only picks the model up on its add_deployment-# job. That job runs every proxy_config_reload_interval_seconds (product default 30).-# A single /v1/models hit can land on a hot worker while the next /chat hits a cold-# one ("Invalid model name"). Wait for first listing within MODEL_SERVABLE_TIMEOUT,-# then require continuous listing for MODEL_SERVABLE_DB_SYNC_SECONDS (the default-# reload interval) so every worker has had a chance to sync from the DB.++# After /model/new, poll data-plane /v1/models until the model is listed (or fail).++# Bound by MODEL_SERVABLE_TIMEOUT so a stuck reload does not burn the spend++# poll_timeout (120s). Return on first listing; settle_propagation owns the separate++# wait that lets every worker and replica reload before the caller uses the model.+ MODEL_SERVABLE_TIMEOUT = 40.0-MODEL_SERVABLE_DB_SYNC_SECONDS = 30.0++MODEL_SERVABLE_DB_SYNC_SECONDS = 0.0+ MODEL_SERVABLE_INTERVAL = 2.0+ # Cap each /v1/models poll so one slow request cannot outlast the remaining budget.+ MODEL_SERVABLE_REQUEST_TIMEOUT = 5.0+++ @dataclass(frozen=True, slots=True)+ class Servable:+ """The data plane listed the model within the deadline."""+++ @dataclass(frozen=True, slots=True)+ class NotServable:+ """The deadline passed without the data plane listing the model.++ `last_result` is the final /v1/models read, so the caller can tell "the proxy+ answered but omitted the model" (propagation) from "the read itself failed"+ (network/auth) when reporting."""++ last_result: Result[ModelsListResponse] | None+++ ServableOutcome = Servable | NotServable+++ def await_servable(+ list_models: Callable[[float], Result[ModelsListResponse]],+ *,+ model_name: str,+ timeout: float,+ interval: float,+ request_timeout: float,+ db_sync_seconds: float,+ now: Callable[[], float],+ sleep: Callable[[float], None],+ ) -> ServableOutcome:+ """Poll until `model_name` is listed long enough for every worker to DB-sync.++ First listing must happen within `timeout`. After that, the model must stay+ listed continuously for `db_sync_seconds` (any miss resets the continuous+ window). `db_sync_seconds=0` returns on the first listing. Each poll's request+ timeout is clamped to the remaining budget. Sleeps only min(interval, time left)+ so a final deadline-clamped poll is never skipped just because a full interval+ does not fit. Clock and sleep are injected."""+ started = now()+ first_seen_at: float | None = None+ last_result: Result[ModelsListResponse] | None = None+ while True:+ t = now()+ phase_deadline = (+ started + timeout if first_seen_at is None else first_seen_at + db_sync_seconds+ )+ remaining = phase_deadline - t+ if remaining <= 0:+ if (+ last_result is not None+ and first_seen_at is not None+ and (db_sync_seconds <= 0 or t - first_seen_at >= db_sync_seconds)+ ):+ return Servable()+ return NotServable(last_result=last_result)++ poll_timeout = min(request_timeout, remaining)+ last_result = list_models(poll_timeout)+ listed = isinstance(last_result, Success) and any(+ entry.id == model_name for entry in last_result.data.data+ )+ t = now()+ if not listed:+ first_seen_at = None+ elif first_seen_at is None:+ if t > started + timeout:+ return NotServable(last_result=last_result)+ first_seen_at = t+ if db_sync_seconds <= 0:+ return Servable()+ elif t - first_seen_at >= db_sync_seconds:+ return Servable()++ phase_deadline = (+ started + timeout if first_seen_at is None else first_seen_at + db_sync_seconds+ )+ wait = min(interval, phase_deadline - now())+ if wait > 0:+ sleep(wait)+++ def servable_timeout_message(+ *,+ model_name: str,+ timeout: float,+ db_sync_seconds: float,+ last_result: Result[ModelsListResponse] | None,+ ) -> str:+ last_error = (+ f"; last /v1/models poll did not succeed: {last_result}"+ if last_result is not None and not isinstance(last_result, Success)+ else ""+ )+ return (+ f"model {model_name!r} was created but never became servable on the data "+ f"plane within {timeout}s of first listing (plus {db_sync_seconds}s continuous "+ f"DB sync) after /model/new (control/data-plane propagation or "+ f"STORE_MODEL_IN_DB reload issue){last_error}"+ )+@dataclass(frozen=True, slots=True)class ProxyClient:@@@ -192,13 -307,12 +307,9 @@@return model_iddef _await_model_servable(self, model_name: str) -> None:- """Block until the data plane lists `model_name`, or fail loudly if it does- not within poll_timeout (a real propagation/config problem, surfaced here- instead of as a downstream "Invalid model name passed")."""- deadline = time.monotonic() + self.poll_timeout- last_result: Result[ModelsListResponse] | None = None- while time.monotonic() < deadline:- last_result = self.transport.get(- """Block until the data plane lists `model_name` long enough for DB sync.-- Fails if first listing misses model_servable_timeout, or if continuous listing- for model_servable_db_sync_seconds never holds (multi-worker / peer reload)."""++ """Block until the data plane lists `model_name`, or fail at model_servable_timeout."""+ outcome = await_servable(+ lambda poll_timeout: self.transport.get("/v1/models",headers=self.transport.master,params=NoBody(),