Skip to content

add NO_OPENAPI env var to disable /openapi.json endpoint - #25547

Merged
krrish-berri-2 merged 1 commit into
BerriAI:litellm_oss_staging_04_13_2026_p1from
jonemo:feature/no-openapi-env-var
Apr 14, 2026
Merged

add NO_OPENAPI env var to disable /openapi.json endpoint#25547
krrish-berri-2 merged 1 commit into
BerriAI:litellm_oss_staging_04_13_2026_p1from
jonemo:feature/no-openapi-env-var

Conversation

@jonemo

@jonemo jonemo commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes 25538

Pre-Submission checklist

Note: I was a bit confused about where to put the tests. The checklist says tests belong in tests/test_litellm, but all test coverage for similar features is in tests/proxy_unit_tests/test_proxy_utils.py.

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🆕 New Feature

Changes

Adds a NO_OPENAPI environment variable (or similar) that sets openapi_url=None on the FastAPI app constructor, disabling the /openapi.json endpoint.

@vercel

vercel Bot commented Apr 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Apr 11, 2026 6:08am

Request Review

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed-hq

codspeed-hq Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing jonemo:feature/no-openapi-env-var (fae3a46) with main (4e12d3c)

Open in CodSpeed

@codecov

codecov Bot commented Apr 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@@ -493,6 +493,7 @@
ProxyUpdateSpend,
_cache_user_row,
_get_docs_url,
_get_openapi_url,
@greptile-apps

greptile-apps Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds a NO_OPENAPI environment variable that sets openapi_url=None on the FastAPI app constructor, disabling the /openapi.json schema endpoint — mirroring the existing NO_DOCS / NO_REDOC flags. The implementation, tests, and docs are clean and consistent with the existing sibling helpers.

Confidence Score: 5/5

Safe to merge — straightforward, isolated feature following established patterns with no correctness issues.

All four changed files are clean: the utility function mirrors _get_docs_url/_get_redoc_url exactly, the FastAPI wiring is correct, tests use monkeypatch properly, and docs are updated. No P0 or P1 findings remain.

No files require special attention.

Important Files Changed

Filename Overview
litellm/proxy/utils.py Adds _get_openapi_url() following the exact same pattern as _get_docs_url and _get_redoc_url; no issues.
litellm/proxy/proxy_server.py Imports and wires _get_openapi_url() into the FastAPI constructor alongside the existing docs_url and redoc_url hooks; correct module-level placement.
tests/test_litellm/proxy/test_utils.py New test file using monkeypatch correctly; covers default and disabled cases.
docs/my-website/docs/proxy/config_settings.md Adds NO_OPENAPI entry in the environment variable table in alphabetical order; accurate description.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[FastAPI app init] --> B["_get_openapi_url()"]
    B --> C{NO_OPENAPI env var set\nand truthy?}
    C -- Yes --> D["return None\n→ /openapi.json returns 404"]
    C -- No --> E["return '/openapi.json'\n→ schema served normally"]
    D --> F["FastAPI: openapi_url=None"]
    E --> G["FastAPI: openapi_url='/openapi.json'"]
Loading

Reviews (2): Last reviewed commit: "add NO_OPENAPI env var to disable /opena..." | Re-trigger Greptile

Comment thread tests/test_litellm/proxy/test_utils.py Outdated
Comment on lines +15 to +24
def test_get_openapi_url(env_vars, expected_url):
# Clear relevant environment variables
os.environ.pop("NO_OPENAPI", None)

# Set test environment variables
for key, value in env_vars.items():
os.environ[key] = value

result = _get_openapi_url()
assert result == expected_url

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.

P1 Missing env var teardown causes test pollution

The test sets NO_OPENAPI=True in os.environ but never cleans it up after the parametrized case completes. Any subsequent test in the same pytest process that reads NO_OPENAPI will see the stale value. Use monkeypatch (pytest's built-in fixture) so the env var is automatically restored after each test.

Suggested change
def test_get_openapi_url(env_vars, expected_url):
# Clear relevant environment variables
os.environ.pop("NO_OPENAPI", None)
# Set test environment variables
for key, value in env_vars.items():
os.environ[key] = value
result = _get_openapi_url()
assert result == expected_url
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

Comment thread litellm/proxy/utils.py
Comment on lines +5246 to +5256
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"

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).

@jonemo
jonemo force-pushed the feature/no-openapi-env-var branch from c4b53cd to fae3a46 Compare April 11, 2026 06:07
@krrish-berri-2
krrish-berri-2 changed the base branch from main to litellm_oss_staging_04_13_2026_p1 April 14, 2026 02:29
@krrish-berri-2
krrish-berri-2 merged commit 6723e7d into BerriAI:litellm_oss_staging_04_13_2026_p1 Apr 14, 2026
48 of 51 checks passed
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants