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
merge: bring main into litellm_migrate_tests_p3
yuneng1659dec4beb6
diff --cc tests/unit/conftest.pyindex d47f71b21a8,017e63ed1b8..6b6f7c43760--- a/tests/unit/conftest.py+++ b/tests/unit/conftest.py@@@ -1,13 -1,11 +1,16 @@@+ import os+from collections.abc import Iteratorfrom typing import Finalimport pytestfrom pytest_socket import enable_socket, socket_allow_hosts- import litellm- import litellm.router as litellm_router_module- import litellm.utils as litellm_utils_module+ os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"+++import litellm # noqa: E402 # litellm reads LITELLM_LOCAL_MODEL_COST_MAP at import++import litellm.router as litellm_router_module # noqa: E402 # same import-time dependency++import litellm.utils as litellm_utils_module # noqa: E402 # same import-time dependency+LOOPBACK_HOSTS: Final = ["127.0.0.1", "::1"]@@@ -27,28 -21,5 +26,32 @@@ def pytest_runtest_setup() -> None_allow_loopback_only()[email protected](autouse=True)+def isolate_router_model_cost_state() -> Iterator[None]:+ original_live_routers: Final = frozenset(litellm_router_module._live_routers)+ original_runtime_registered_model_cost: Final = {+ model_key: dict(model_value)+ for model_key, model_value in litellm_utils_module._runtime_registered_model_cost.items()+ }+ yield+ for router in tuple(litellm_router_module._live_routers):+ litellm_router_module._live_routers.discard(router)+ for router in original_live_routers:+ litellm_router_module._live_routers.add(router)+ litellm_utils_module._runtime_registered_model_cost.clear()+ litellm_utils_module._runtime_registered_model_cost.update(original_runtime_registered_model_cost)+ litellm_utils_module._invalidate_model_cost_lowercase_map()+ litellm.get_model_info.cache_clear()+++def local_model_cost_map(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:+ monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")+ monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url=""))+ litellm.get_model_info.cache_clear()+ yield+ litellm.get_model_info.cache_clear()+++++ def pytest_sessionfinish() -> None:+ enable_socket()