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
add NO_OPENAPI env var to disable /openapi.json endpoint (#25547)
Jonas Neuberte724e5e07d8a
diff --git a/docs/my-website/docs/proxy/config_settings.md b/docs/my-website/docs/proxy/config_settings.mdindex fa7b73f6c45..544ace9063a 100644--- a/docs/my-website/docs/proxy/config_settings.md+++ b/docs/my-website/docs/proxy/config_settings.md@@ -914,6 +914,7 @@ router_settings:| MODEL_COST_MAP_MAX_SHRINK_RATIO | Maximum allowed shrinkage ratio when validating a fetched model cost map against the local backup. Rejects the fetched map if it is smaller than this fraction of the backup. Default is 0.5| MODEL_COST_MAP_MIN_MODEL_COUNT | Minimum number of models a fetched cost map must contain to be considered valid. Default is 50| NO_DOCS | Flag to disable Swagger UI documentation+| NO_OPENAPI | Flag to disable the /openapi.json endpoint| NO_REDOC | Flag to disable Redoc documentation| NO_PROXY | List of addresses to bypass proxy| NON_LLM_CONNECTION_TIMEOUT | Timeout in seconds for non-LLM service connections. Default is 15diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 85a12f70f58..cfc90d5fa6d 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -493,6 +493,7 @@ from litellm.proxy.utils import (ProxyUpdateSpend,_cache_user_row,_get_docs_url,+ _get_openapi_url,_get_projected_spend_over_limit,_get_redoc_url,_is_projected_spend_over_limit,@@ -1000,6 +1001,7 @@ async def proxy_startup_event(app: FastAPI): # noqa: PLR0915app = FastAPI(docs_url=_get_docs_url(),redoc_url=_get_redoc_url(),+ openapi_url=_get_openapi_url(),title=_title,description=_description,version=version,diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.pyindex e15b48577de..a6f81986a6f 100644--- a/litellm/proxy/utils.py+++ b/litellm/proxy/utils.py@@ -5321,6 +5321,19 @@ def get_error_message_str(e: Exception) -> str:return error_message+def _get_openapi_url() -> Optional[str]:+ """+ Get the OpenAPI schema URL from the environment variables.++ - If NO_OPENAPI is True, return None.+ - Otherwise, default to "/openapi.json".+ """+ if str_to_bool(os.getenv("NO_OPENAPI")) is True:+ return None++ return "/openapi.json"++def _get_redoc_url() -> Optional[str]:"""Get the Redoc URL from the environment variables.diff --git a/tests/test_litellm/proxy/test_utils.py b/tests/test_litellm/proxy/test_utils.pynew file mode 100644index 00000000000..9dfeb27f4cb--- /dev/null+++ b/tests/test_litellm/proxy/test_utils.py@@ -0,0 +1,22 @@+import pytest++from litellm.proxy.utils import _get_openapi_url+++ "env_vars, expected_url",+ [+ ({}, "/openapi.json"), # default case+ ({"NO_OPENAPI": "True"}, None), # OpenAPI disabled+ ],+)+def test_get_openapi_url(monkeypatch, env_vars, expected_url):+ # Clear relevant environment variables+ monkeypatch.delenv("NO_OPENAPI", raising=False)++ # Set test environment variables+ for key, value in env_vars.items():+ monkeypatch.setenv(key, value)++ result = _get_openapi_url()+ assert result == expected_url