Commit graph

39980 commits

Author SHA1 Message Date
shivam
e72eac9176
Fix add_model_file_id_mappings when router returns single deployment dict
When model_info.id equals model_name (common for batch models), the router
resolves via has_model_id and returns one deployment dict instead of a list.
The dict branch incorrectly iterated deployment keys (model_name,
litellm_params, model_info), producing non-string values that broke
LiteLLM_ManagedFileTable validation on managed file upload.

Normalize list vs dict by wrapping single deployments and extracting
model_info.id for each response pair.

Add regression tests including the batch model id == model_name case.

Made-with: Cursor
2026-04-30 18:04:47 -07:00
mateo-berri
722a1a9f8f Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_vcr-cassette-llm-tests-af37
# Conflicts:
#	litellm/llms/custom_httpx/llm_http_handler.py
2026-04-30 17:56:02 -07:00
mateo-berri
8bdc46ea74 fix(responses): omit empty JSON body on DELETE response API requests
Azure OpenAI's responses-API DELETE endpoint rejects requests that carry
a JSON body with: "Unexpected body with size 2. This API method does
not accept a request body.". The default LiteLLMAiohttpTransport silently
elides empty-dict bodies on DELETE so this was masked, but the pure-httpx
transport (used when DISABLE_AIOHTTP_TRANSPORT=True or under vcrpy/respx
patching) sends literal '{}' (2 bytes), which Azure rejects.

Only attach json= when the provider's transform actually returned a
non-empty dict; otherwise issue a bodyless DELETE.
2026-04-30 17:55:27 -07:00
Michael-RZ-Berri
e4fb325a3a
Merge pull request #26914 from BerriAI/litellm_googleGenContentHooks
Run pre_call_hook on Google generateContent endpoints
2026-04-30 17:53:38 -07:00
Michael Riad Zaky
4e26835098 Reorder counter invalidation to run after DB write 2026-04-30 17:50:58 -07:00
Michael Riad Zaky
ff2a938847 Match docstring style on async_increment_cache 2026-04-30 17:50:58 -07:00
Michael Riad Zaky
fed5f36a3d Invalidate spend counters on budget reset 2026-04-30 17:50:58 -07:00
Michael Riad Zaky
9f08db91f9 Refresh Redis TTL on counter writes and skip stale in-memory on Redis miss 2026-04-30 17:50:58 -07:00
ryan-crabbe-berri
76e43b7bb2
Merge pull request #26949 from BerriAI/litellm_/condescending-hawking-19bdeb
[Fix] Responses API: Omit Empty Body On DELETE
2026-04-30 17:49:30 -07:00
mateo-berri
265a94cd60 tests(vcr): force pure-httpx transport when VCR is active
litellm's default LiteLLMAiohttpTransport routes requests through aiohttp,
which sits below httpx and is invisible to vcrpy's httpx-stub interception.
Under vcrpy + aiohttp, requests reach the real network but responses come
back through the stubbed httpx transport as empty 200s, surfacing as
'Unable to get json response - Expecting value: line 1 column 1 (char 0)'
in providers like Anthropic, Gemini, and any other path that exercises the
aiohttp transport.

Disabling the aiohttp transport when the VCR persister is registered
forces all calls through pure httpx, which vcrpy can record and replay
correctly.
2026-04-30 17:42:17 -07:00
Yuneng Jiang
bd638245e8
[Fix] Responses API: Omit Empty Body On DELETE
The async/sync delete_response_api_handler always passed json=data into
httpx.delete, where data is {} from the transformer. httpx serializes that
to a 2-byte body. The Azure Responses DELETE endpoint now rejects any
request body with code: unexpected_body, breaking
test_basic_openai_responses_delete_endpoint on the llm_responses_api_testing
job. Build the kwargs dict and only set json= when data is truthy.

Add unit tests that patch httpx.delete and assert json/data are not in the
captured kwargs for the Azure DELETE path (sync and async).
2026-04-30 17:39:55 -07:00
user
694fadd175 fix budget reservation review findings 2026-04-30 17:38:18 -07:00
user
2c852ba2b1 fix(sso): tighten oauth_state cookie — Secure flag + PKCE-only set
Two Greptile review findings addressed:

1. (P1, security) The ``litellm_oauth_state`` cookie is the sole
   guard against Login-CSRF in the PKCE flow but was set without the
   ``Secure`` attribute, so a network observer on plain HTTP could
   read and replay it — bypassing the protection this PR adds.

   Thread the originating ``Request`` down through
   ``get_sso_login_redirect`` and ``get_generic_sso_redirect_response``
   and set ``Secure`` based on ``request.url.scheme == "https"``.
   When no request is supplied (programmatic callers / tests) default
   to ``Secure=True`` — production-safe.  Local HTTP dev still works
   because the request scheme is observed at runtime.

2. (P2) The cookie was set unconditionally, but the callback only
   validates it inside the PKCE branch.  Two concurrent SSO sessions
   (one PKCE, one plain) could overwrite each other's state cookie
   and produce spurious 400s for the plain-flow user.

   Move the ``set_cookie`` call inside the existing
   ``if code_verifier and "state" in redirect_params`` block so the
   cookie is only written when PKCE is active and the validation
   will actually fire.

Tests cover both paths: PKCE-on (cookie set with Secure default),
PKCE-off (cookie not set), and HTTP dev request (Secure dropped so
the browser will actually attach the cookie on the callback hop).
2026-05-01 00:36:51 +00:00
yuneng-jiang
326bcd6cec
Merge pull request #26941 from BerriAI/litellm_/stoic-jemison-cbb6cf
[Test] Proxy E2E: Opt In To Client Mock Response For Model Access Tests
2026-04-30 17:35:16 -07:00
harish-berri
896e102464 fix linting
Some checks failed
Unit Tests: Caching (Redis) / caching-redis (push) Has been cancelled
Unit Tests: Proxy DB Operations / assert-shard-coverage (push) Has been cancelled
Unit Tests: Security / security (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-utils (push) Has been cancelled
Unit Tests: Proxy DB Operations / auth-checks (push) Has been cancelled
Unit Tests: Proxy DB Operations / budgets (push) Has been cancelled
Unit Tests: Proxy DB Operations / custom-logging (push) Has been cancelled
Unit Tests: Proxy DB Operations / db-and-spend (push) Has been cancelled
Unit Tests: Proxy DB Operations / endpoints-and-responses (push) Has been cancelled
Unit Tests: Proxy DB Operations / guardrails-hooks (push) Has been cancelled
Unit Tests: Proxy DB Operations / jwt-and-keys (push) Has been cancelled
Unit Tests: Proxy DB Operations / key-generation (push) Has been cancelled
Unit Tests: Proxy DB Operations / logging-misc (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-runtime (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-server-core (push) Has been cancelled
Unit Tests: Proxy DB Operations / schema-migration (push) Has been cancelled
2026-05-01 00:32:10 +00:00
user
fc580ae1ec fix(videos): encode the variant query param
``variant`` is user-controlled (passed through from
``litellm.video_content(variant=...)``) and was interpolated raw into
the URL query string.  A value like ``thumbnail&extra=1`` would inject
additional query parameters into the upstream request — the same
class of issue this PR's path-segment encoding addresses.  Wrap the
value in ``quote(value, safe="")`` so ``&`` / ``=`` / ``#`` cannot
terminate the ``variant`` value or open a new parameter.

Adds a regression test asserting that a malicious ``thumbnail&extra=1``
ends up percent-encoded in the URL, and that the legitimate
``thumbnail`` value still round-trips cleanly.
2026-05-01 00:32:02 +00:00
harish-berri
8671ec636b fix import error 2026-05-01 00:29:13 +00:00
user
06502d19a7 test(vector stores): allow primitive rag depth boundary 2026-04-30 17:28:02 -07:00
harish-berri
7c8fe86fd9
Merge branch 'litellm_internal_staging' into litellm_token_verification_query_opt 2026-04-30 17:25:12 -07:00
mateo-berri
68db1c5e9e tests(vcr): switch to record_mode=new_episodes to avoid partial-cassette poisoning
record_mode='once' refused to add new requests once any cassette
existed in Redis. Combined with filter_non_2xx_response (which drops
non-2xx responses from the saved cassette) and a 24h shared-Redis TTL,
a single transient API failure mid-test left the cassette stuck with
only the leading non-API requests (e.g. the model_prices fetch from
raw.githubusercontent.com), and every subsequent run for the next 24h
errored with 'Can't overwrite existing cassette'.

new_episodes records anything not already present, so partially
populated cassettes recover on the next run instead of poisoning the
suite for a full TTL window.
2026-04-30 17:22:21 -07:00
user
00442e653c chore(sso): bind generic SSO state to a session cookie
The Generic SSO PKCE flow used the URL ``state`` parameter as the
cache key for the PKCE ``code_verifier`` without binding the state
to the caller's browser.  An attacker who pre-minted a state and
cached a verifier under it could hand the resulting login link to a
victim; the victim's auth code would then be exchanged with the
attacker's verifier on the callback, producing an access token
under the attacker's control (Login CSRF / token theft).

The non-PKCE branch is unaffected because it delegates to
fastapi-sso's ``verify_and_process``, which performs its own
session-cookie check.  The PKCE branch bypasses that helper, which
is exactly the gap this commit closes.

Two-part fix in ``ui_sso.py``:

- ``get_generic_sso_redirect_response`` now sets a
  ``litellm_oauth_state`` cookie (HttpOnly, SameSite=Lax, 10-min TTL)
  carrying the state value used in the redirect URL.  The cookie is
  set on the redirect response just like the existing
  ``litellm_cp_return_to`` cookie a few lines earlier in the file.
- ``get_generic_sso_response`` validates ``request.cookies.get(
  "litellm_oauth_state")`` against ``request.query_params.get(
  "state")`` via ``secrets.compare_digest`` before invoking the
  PKCE token exchange.  Mismatch (or either being missing) raises a
  ``ProxyException`` with HTTP 400.

The pre-existing TODO above the redirect logic ("state should be a
random string and added to the user session with cookie") is now
addressed and removed.

Tests cover the redirect-side cookie set, the missing-cookie reject
shape, the URL/cookie-mismatch reject shape, and the matching-cookie
happy path.
2026-05-01 00:19:13 +00:00
user
9db8ecac12 update budget reservation auth test expectation 2026-04-30 17:13:49 -07:00
yuneng-jiang
bdcc23853c
Merge pull request #26835 from stuxf/codex/cli-sso-flow-binding
chore(cli): tighten CLI SSO session flow
2026-04-30 17:10:27 -07:00
yuneng-jiang
15b7386859
Merge pull request #26815 from stuxf/fix/get-image-lfi-ssrf
chore(proxy): contain UI_LOGO_PATH / LITELLM_FAVICON_URL on unauthenticated asset endpoints
2026-04-30 17:10:15 -07:00
user
fce86d1334 fix budget reservation greptile findings 2026-04-30 17:08:45 -07:00
yuneng-jiang
71d5015975
Merge pull request #26827 from stuxf/fix/passthrough-auth-default
chore(passthrough): default auth=True and drop enterprise gate on the safe option
2026-04-30 17:06:37 -07:00
Yuneng Jiang
be0e9914dc
[Test] Proxy E2E: Opt In To Client Mock Response For Model Access Tests
The proxy's ingress hardening (commit 842eea0131) now strips client-supplied
`mock_response` from the request body unless the calling key or team has the
`allow_client_mock_response: true` admin-metadata flag set. The e2e model
access tests rely on `mock_response` to short-circuit the LLM call, so without
the flag they hit real backends — the bedrock wildcard route fakes out to a
shared example endpoint that now 404s on unsupported paths, causing
`test_model_access_patterns[key_models2-bedrock/anthropic.claude-3-True]`
(and the bedrock/anthropic.* row that pytest -x never reaches) to fail.

Set `allow_client_mock_response: true` on every key and team this test file
provisions so `mock_response` is preserved end-to-end.
2026-04-30 17:05:31 -07:00
mateo-berri
f6a37a6a15 style: reformat to pass ci 2026-04-30 17:01:44 -07:00
user
2922da9b64 test(vector stores): cover azure passthrough guard 2026-04-30 17:00:43 -07:00
user
f8d187785d finalize invalidated budget reservations 2026-04-30 16:52:09 -07:00
Michael Riad Zaky
053e040171 run pre_call_hook on Google generateContent endpoints 2026-04-30 16:43:42 -07:00
Michael-RZ-Berri
e810d8735d
Merge pull request #26934 from BerriAI/litellm_lazyStartupTestFix
[Fix] Replace subprocess startup-import diff with static source scan
2026-04-30 16:42:52 -07:00
user
32272908d3 test(vector stores): isolate provider-native guard case 2026-04-30 16:41:13 -07:00
mateo-berri
468b849072
tests(vcr): drop YAML/cassettes-directory metaphor from Redis keys 2026-04-30 23:37:17 +00:00
user
49ccb3369c test(vector stores): pin rag scan depth boundary 2026-04-30 16:33:42 -07:00
user
e034935b53 fix budget reservation window fallback races 2026-04-30 16:26:43 -07:00
user
1201a0ba5c test(vector stores): pin no-db registry fallback case 2026-04-30 16:16:37 -07:00
Michael Riad Zaky
47b2832d6f test: replace subprocess startup-import diff with static source scan 2026-04-30 16:15:46 -07:00
user
1373ae1021 fix budget tag spend counter reconciliation 2026-04-30 16:09:38 -07:00
user
ce0c557012 chore(vector stores): address access review followups 2026-04-30 16:09:26 -07:00
mateo-berri
f55a710e92
tests(vcr): accept REDIS_URL / REDIS_SSL_URL for managed Redis with TLS 2026-04-30 23:08:01 +00:00
mateo-berri
efdeff89d8
fix(llm_request_utils): handle None proxy_server_request without AttributeError 2026-04-30 23:01:10 +00:00
mateo-berri
59d5901766
tests(vcr): allow playback repeats so duplicate intra-test requests serve from cache 2026-04-30 22:57:21 +00:00
mateo-berri
73594262ee
tests(vcr): drop redundant num_retries=3 layer for vcr-marked tests
Provider SDKs already retry transient 5xx/429 with exponential backoff
(default max_retries=2), and pytest.mark.flaky covers test-level
retries on top of that. Setting litellm.num_retries=3 here just
multiplied the existing layers — worst case 6 (flaky) x 3 (this) x
2 (CI rerunfailures) = 36 attempts on a single test.

Removing it keeps SDK-level network-blip protection intact and
shortens worst-case latency on cache-miss runs.
2026-04-30 22:42:30 +00:00
harish-berri
6fb1de9763 refactor: replace DualCache with UserApiKeyCache in multiple modules
This commit updates the codebase to replace instances of DualCache with UserApiKeyCache in various files, including utils, expired_ui_session_key_cleanup_manager, and team_member_permission_checks. Additionally, it enhances the UserApiKeyCache class with new methods for cache management, improving type safety and consistency across the application.
2026-04-30 22:40:52 +00:00
harish-berri
3bff192c2f fix linting 2026-04-30 22:35:23 +00:00
user
aef71ae2d5 chore(proxy): stabilize lazy openapi snapshot 2026-04-30 15:17:20 -07:00
user
363c0de6f7 chore(vector stores): address tenant guard followups 2026-04-30 15:13:24 -07:00
harish-berri
76fb9d3c96 refactor: remove AuthMetrics and related combined_view query metrics
This commit deletes the AuthMetrics class and its associated methods, which were responsible for tracking combined_view SQL query metrics. The PrometheusLogger integration has been updated to remove references to these metrics, streamlining the codebase. Additionally, minor whitespace adjustments were made in the cache coordinator for consistency.
2026-04-30 22:13:11 +00:00
harish-berri
1f72ae5442 fix: add type hint ignore for user_api_key_cache and update docstring for EventDrivenCacheCoordinator 2026-04-30 22:06:33 +00:00