Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/my-website/docs/proxy/config_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,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 15
Expand Down
2 changes: 2 additions & 0 deletions litellm/proxy/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@
ProxyUpdateSpend,
_cache_user_row,
_get_docs_url,
_get_openapi_url,
_get_projected_spend_over_limit,
_get_redoc_url,
_is_projected_spend_over_limit,
Expand Down Expand Up @@ -1000,6 +1001,7 @@
app = FastAPI(
docs_url=_get_docs_url(),
redoc_url=_get_redoc_url(),
openapi_url=_get_openapi_url(),
title=_title,
description=_description,
version=version,
Expand Down
13 changes: 13 additions & 0 deletions litellm/proxy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5243,6 +5243,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"
Comment on lines +5246 to +5256

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 No custom URL support unlike sibling functions

_get_docs_url and _get_redoc_url both accept a DOCS_URL / REDOC_URL env var that lets operators relocate the endpoint rather than only suppressing it. _get_openapi_url only supports suppression (NO_OPENAPI); there is no way to change the schema URL to a non-default path. This may be intentional, but for consistency consider adding an OPENAPI_URL env var check (same pattern as the existing helpers).



def _get_redoc_url() -> Optional[str]:
"""
Get the Redoc URL from the environment variables.
Expand Down
22 changes: 22 additions & 0 deletions tests/test_litellm/proxy/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest

from litellm.proxy.utils import _get_openapi_url


@pytest.mark.parametrize(
"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
Loading