Commit graph

17245 commits

Author SHA1 Message Date
AaronHowell
2cd28b97f1 fix(responses): align credential boundary resolution 2026-09-08 18:02:31 +08:00
mateo
61e664088c test: make the explicit stagger offset assertion independent of the wall clock
Some checks failed
LiteLLM Rust / rust-lint (push) Waiting to run
LiteLLM Rust / rust-test (push) Waiting to run
Terraform Provider / gofmt, vet, build, test (push) Has been cancelled
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Has been cancelled
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-08 09:51:09 +00:00
mateo
ebf6ef642e Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_deflake_20260905 2026-09-08 09:19:21 +00:00
AaronHowell
d5cf5640b0 fix(responses): preserve provider affinity
Co-authored-by: Bytechoreographer <Bytechoreographer@users.noreply.github.com>
2026-09-08 16:30:29 +08:00
Yuneng Jiang
0c519b162f
fix: preserve MongoDB deadlines and secure remote sidecar transport 2026-09-07 23:43:21 -07:00
tin-berri
1af7a403c6
feat(mcp): start the named server's OAuth directly for a resource-scoped gateway flow (#39933)
An aggregate gateway DCR authorize whose RFC 8707 resource resolves to exactly one
gateway-managed oauth2 server sealed that server into the flow and then sent the browser to
the generic connect grid anyway, so the user had to find the server the client had already
named and click Connect.

The connect URL now carries only the flow handle. GET /authorize/flow classifies the sealed
flow as unscoped, interactive, M2M, or stale, and returns the matching state to the page.
Interactive flows require a live per-user vendor credential before minting and do not burn the
flow on an early submit. M2M flows use the gateway's configured service credential and finish
without an interactive OAuth trip. Stale flows fail closed instead of becoming unscoped.
The existing explicit Finish action and a new Cancel path preserve deliberate user intent.
2026-09-07 23:40:02 -07:00
tin-berri
1a6aa98230
fix(spend): compare auto-router targets by deployment identity (#40206)
Preserve deployment identity through savings calculation, with canonical model fallback only when either ID is absent. Cover negotiated rates, unchanged deployments, alias/base-model cache accounting and missing IDs.

Fixes #38811. Based on the deployment-identity approach proposed by @QuantumBreakz in #38834.

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-09-07 23:29:42 -07:00
Yuneng Jiang
5c037299f4
feat: move MongoDB vector search to an optional sidecar 2026-09-07 23:02:27 -07:00
Maximilian Roos
ffa08e16d6
test(http_handler): parametrize the anchor tests over every streaming send
post was the only method the mock-transport tests reached, leaving the anchor
in async delete and in sync patch/put/delete uncovered in the tree Codecov
measures. Parametrizing also means a method added later is covered here rather
than being the one that forgets to anchor.
2026-09-07 23:02:02 -07:00
mateo-berri
13db79da46 fix(azure_ai): price streamed Responses relays from their terminal event
A streamed Responses API relay handed the success handler a bare ResponsesAPIResponse, which the streaming assembly step drops, so the relay never reached the spend callbacks. Hand it the terminal response.completed event instead, which the assembly step already converts, and cover the whole flush path with a regression test that fails on the previous tip.
2026-09-07 22:38:41 -07:00
Maximilian Roos
6e6ab5c0eb
test(http_handler): cover the anchor in the tree Codecov measures
tests/local_testing runs on CircleCI, which does not feed the patch-coverage
check, so the anchor read as half-uncovered. These three drive it over a mock
transport, which is enough for the lifetime contract even though it cannot
reproduce the teardown the loopback tests exist for.
2026-09-07 22:38:32 -07:00
mateo-berri
3cadf2f8f7 test(azure_ai): charge the router fee over cached prompt tokens too 2026-09-07 22:35:19 -07:00
mateo-berri
5706952588 fix(azure_ai): drop gpt-chat-latest effort levels, test prices via calculator
litellm's azure_ai config rejects reasoning_effort for gpt-chat-latest and Azure documents a fixed reasoning level for it, so the entry no longer advertises reasoning_effort_levels. The catalog metadata tests compare cost_per_token and the whisper transcription cost with the entry the calculator read instead of with list-price literals, the pattern #40195 removed
2026-09-07 22:22:51 -07:00
mateo-berri
d202885f8b fix(proxy): run prompt caching counts and custom tokenizer loads off the event loop 2026-09-07 22:21:45 -07:00
mateo-berri
704013dbb6 fix(init): keep non-flag LITELLM_DROP_PARAMS values on with a warning
The merge base read the variable by truthiness, so any non-empty value
turned the global flag on. Parsing it as a flag made a value such as
temperature or enabled silently turn it off, and the only docs for the
variable describe it as a list of parameter names, so keep those values
on and log a warning that asks for true or false. A blank value stays off
without a warning
2026-09-07 22:13:23 -07:00
mateo-berri
9fcc64fbf9 fix(files): only proxy admin keys may delete raw cloud storage file ids
Some checks failed
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
Terraform Modules / fmt, validate, test (aws) (push) Has been cancelled
Terraform Modules / fmt, validate, test (gcp) (push) Has been cancelled
Terraform Provider / gofmt, vet, build, test (push) Has been cancelled
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Has been cancelled
A key allowed to call a Bedrock model could delete any object under the
deployment's buckets through DELETE /bedrock/v1/files/{s3 id}?model=...
because the managed-file ownership check only runs for unified ids. Raw
cloud storage ids now answer 403 on every delete route unless the caller
is a proxy admin; managed ids and require_managed_files are unchanged
2026-09-07 22:09:44 -07:00
Maximilian Roos
5972227b6d
fix(http_handler): keep a handler alive while a response it issued is still reading
_handler_may_close_client withholds the finalizer's close from a client that
someone else references. A streaming response is not one of those referrers: it
holds the connection it reads from, never the client, so the refcount says
"sole referrer" for exactly the client that is busiest, and __del__ tears the
pool down mid-body. Both handlers, both transports, and it is the shape #24929
reports: a provider's streaming call returns the response and drops the
handler, and get_async_httpx_client lets a cached handler go after an hour.

A streaming send now anchors the handler to the response it returns, so the
handler is finalized once the caller is done with the body and the ordinary
close applies with nothing in flight. The anchor is a weakref.finalize, which
holds the handler in its own registry rather than on the response. That keeps
the handler out of the response's reference cycle, so it is finalized by
refcount and can still schedule an async close, rather than inside a cyclic
collection that reaps its aiohttp session in the same pass; and a handler
serving several streams is released only once all of them are done, because
each anchor holds it separately.

Only a streaming send anchors. A non-streaming response has been read in full
by the time the method returns, so pinning the handler to it would delay every
client close behind whatever the caller does with the response.

The alternative was to ask the connection pool whether a request was in flight,
reusing EvictedClientCloser's check. It reads client._transport, so it answers
"idle" for any client with a proxy configured, where httpx routes through
client._mounts; and having found the client busy it can only poll, which never
terminates for a response the caller abandons unread, since httpx leaves that
connection checked out. The response's own lifetime is the condition both were
approximating.
2026-09-07 22:07:12 -07:00
mateo-berri
9666a21cf0 Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_lit_7022_azure_ai_passthrough_config 2026-09-07 21:57:00 -07:00
mateo-berri
52e9cfe254 fix(azure): price streamed Responses relays and keep a full-URL api_base from doubling the native path 2026-09-07 21:57:00 -07:00
mateo-berri
1de369a1a4 fix(passthrough): bound azure relays to the key's model group and reject foreign deployment segments 2026-09-07 21:54:37 -07:00
mateo-berri
08b60c409a refactor(guardrails): drop the unused rewrites_streamed_output hook
Nothing calls it since the streaming pipeline detects rewrites at run time
through the stream observer, so the base method and the content filter's
override were dead code with dead tests
2026-09-07 21:53:26 -07:00
mateo-berri
d08a177bc7 fix(policy_engine): keep a policy-added guardrail's other stages when a pipeline steps it
A policy that both adds a guardrail and steps it in a post_call pipeline
used to drop the guardrail from the request's guardrail list outright, so
its pre_call stage never ran. The per-hook loops already skip guardrails
by pipeline mode, so the mode-agnostic subtraction only lost coverage
2026-09-07 21:51:34 -07:00
mateo-berri
91fc1b2010 fix(policy_engine): record a streaming pipeline step once and in the applied guardrails header
CustomGuardrail.__init_subclass__ wrapped _StreamRewriteObserver.apply_guardrail in log_guardrail_information, so every streaming step recorded a second standard_logging_guardrail_information entry and span next to the inner guardrail's own. The observer's method now carries the marker that skips the wrapper. The step also adds the guardrail to the applied guardrails header the way the non-streaming unified path does, so streamed spend rows name the guardrail that scanned them
2026-09-07 21:48:19 -07:00
mateo-berri
69d2ac1edb fix(policy_engine): run iterator-hook guardrails whose post_call pipeline cannot stream
The streaming loop skipped every guardrail stepped by a post_call pipeline, even when the pipeline was dropped from the stream for lacking the unified apply_guardrail interface, so a default_on guardrail that only implements async_post_call_streaming_iterator_hook stopped governing streams it governed on the merge base. The skip set now comes from the pipelines that will gate the stream
2026-09-07 21:46:00 -07:00
mateo-berri
55c10c1983 fix(azure_ai): charge the router fee once for any router name and price grok-4-20 cache reads
Direct litellm.cost_per_token callers that name a Model Router deployment as
the model get the routing fee again, as they did before this branch, and the
fee is still charged exactly once on every completion_cost path. The
grok-4-20 entries bill cached prompt tokens at the input rate, since Azure has
no cached-input meter for them, and the model_router twin carries the same
limits and retirement date as model-router. The catalog test now exercises
the cost calculator and map relations instead of pinning map fields.
2026-09-07 21:34:34 -07:00
mateo-berri
83d500bac9 fix(router): count deployment itpm reservations off the event loop 2026-09-07 21:29:26 -07:00
Maximilian Roos
aa759ef750
Merge upstream/main into bugfix/http-handler-del-closes-streaming-client
http_handler.py resolved to main. This branch deleted both __del__ methods;
main has since kept them and guarded them (#35981 refcount + ownership, #36670
loop-aware aiohttp session disposal), and added tests that assert a collected
handler does close an exclusively owned client. Taking this branch's deletion
would remove all of that, so the deletion is dropped here and the case main's
guard still misses -- a response in flight -- is fixed in the next commit.
2026-09-07 21:23:46 -07:00
mateo-berri
5f4d667365 fix(files): keep the SDK listing a list and build the OpenAI page at the proxy route 2026-09-07 21:17:37 -07:00
mateo-berri
c02f2dc0fe fix(azure_ai): keep the request_model keyword on cost_per_token
Restores the public keyword removed at 415bdbfd8f. A direct caller that
names the Model Router as the request model gets the routing fee folded
into the prompt cost once; completion_cost never passes it and charges
the fee through the additional-costs hook as before
2026-09-07 21:10:54 -07:00
mateo-berri
d594b9385e fix(drop_params): warn when a deployment or env drop_params value is not a flag
A deployment drop_params string that is not a flag value (a typo like ture) stayed silently off. The router now logs one warning per deployment. LITELLM_DROP_PARAMS and litellm_settings.drop_params share the same helper, so a non-flag value there warns as well instead of flipping silently from on to off
2026-09-07 21:05:01 -07:00
mateo-berri
91391c1360 fix(files): page every provider listing, answer deleted true for managed ids, and skip S3 walks for purposes Bedrock never stores
GET /v1/files through a provider config now returns the OpenAI page shape
(object list, data, first_id, last_id, has_more) instead of a bare array, and
DELETE /v1/files/{id} on a managed id answers the OpenAI FileDeleted shape with
deleted true instead of an empty body

Bedrock listing asks S3 for max-keys=0 when the purpose is one Bedrock never
stores under LiteLLM's prefixes, and batch_output listing no longer requires an
input bucket when only s3_output_bucket_name is configured. The mock request
behind the 400 for a foreign file id uses the same https://litellm.ai URL the
exception module uses
2026-09-07 20:48:38 -07:00
mateo-berri
415bdbfd8f fix(azure_ai): charge the Model Router fee once and correct catalog limits
The router fee was folded into azure_ai.cost_per_token and then added again
by the additional_costs hook, so every routed request paid it twice. The hook
now owns the fee, the entry named by the deployment supplies the price, and a
response priced as the router entry itself is not charged again

model-router, gpt-chat-latest and cohere-command-a carry the limits from the
Foundry models page, and model-router and grok-4-20-* carry their retirement
dates. The router tests now run at the completion_cost level with a Logging
object, which is the path the proxy takes, and fail at the merge base
2026-09-07 20:46:39 -07:00
Mateo Wang
9dbfb060bd
Merge pull request #39668 from BerriAI/litellm_lit6899_vertex_batch_tuned_endpoints
fix(vertex_ai): support fine-tuned Gemini endpoints in managed batches
2026-09-07 20:28:02 -07:00
mateo
adcfe8cb7f test: pin redirected xai slugs to the target's tier field set
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-08 02:44:52 +00:00
mateo
dc035cba62 test: preserve live xai pricing invariant
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-08 02:33:04 +00:00
mateo
5cfe20a68d test: collapse blank lines left by removed tests
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-08 02:21:55 +00:00
mateo
ac573fd66e test: remove remaining static cost assertions
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-08 02:20:39 +00:00
mateo
3023497590 test: drop static cost-map value assertions
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-08 02:19:32 +00:00
mateo-berri
dcd38ab9f0 fix(proxy): count failure and rate-limit input tokens off the event loop
The failure hook's usage estimate and the project ITPM reservation both
called litellm.token_counter inline on the event loop, so a large request
that failed or hit the limiter stalled the gateway the same way the
count_tokens endpoints did. Both now run through asyncify. The loop-lag
probe the existing tests used moves into a shared helper that warms the
tokenizer first, and two new tests fail when either count runs inline
2026-09-07 19:15:36 -07:00
mateo-berri
02b18b4fc6 fix(passthrough): match image URL schemes case-insensitively when counting relayed prompt tokens 2026-09-07 19:10:06 -07:00
mateo-berri
b7c2decb7d fix(drop_params): honor string values in litellm_params and the LITELLM_DROP_PARAMS env var
get_litellm_params normalizes drop_params once, so a client-body string and
router_settings.default_litellm_params reach the anthropic, bedrock, and
azure_ai gates as a bool. LITELLM_DROP_PARAMS=false now means off. A value
that is neither a flag nor a string logs one warning and counts as unset,
both in the deployment validator and in litellm_settings.
2026-09-07 19:00:47 -07:00
mateo-berri
a601c00afd fix(bedrock): pass litellm_params into the Bedrock embedding call so drop_params reaches Marengo 3.0 2026-09-07 18:47:25 -07:00
yujonglee
13df85cceb
test: add Rust extension pytest contract (#40181)
* test: add Rust extension pytest contract

* test: prove native OCR execution

* test: isolate Rust extension pytest collection

* ci: register Rust extension test coverage

* test: prove native OCR at wire boundary
2026-09-07 18:46:29 -07:00
mateo-berri
9c980b96d6 fix(budget_reservation): exempt vertex and bedrock count-tokens routes from budget reservation
Some checks failed
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
Terraform Modules / fmt, validate, test (aws) (push) Has been cancelled
Terraform Modules / fmt, validate, test (gcp) (push) Has been cancelled
Terraform Provider / gofmt, vet, build, test (push) Has been cancelled
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Has been cancelled
2026-09-07 18:44:04 -07:00
mateo-berri
80fea089b6 fix(bedrock): reject Marengo 2.7-only and misplaced media params on 3.0 unless drop_params
Marengo 3.0 requests now get a 400 naming any textTruncate, lengthSec,
useFixedLengthSec, or minClipSec parameter, and any video or audio option
sent with a text, image, text_image, or multi_input request, instead of
silently dropping them. drop_params (global, per deployment, or per
request) drops them instead. Pydantic validation errors name the field
and the reason, and the 3.0 marker is the exact "marengo-embed-3-" model
id segment.
2026-09-07 18:40:31 -07:00
mateo-berri
d238e60220 fix(bedrock): answer 400 for a file id outside the configured bucket and keep S3 error bodies 2026-09-07 18:38:25 -07:00
ryan-crabbe-berri
ba91588b15 fix(proxy): price one cost estimate at one moment
The totals, the per-token-type lines and the reported rates each resolved off-peak pricing on their own clock read, so a quote taken as a window opened could bill on one side of the boundary and report rates from the other. /cost/estimate now pins a billing moment for the whole quote, and every rate lookup answers for the pinned moment instead of reading the clock again

Claude-Session: https://claude.ai/code/session_011Tn3657NkV6ojLqewL64Kb
2026-09-07 18:38:12 -07:00
mateo-berri
12d9413860 refactor(passthrough): share the relay shape table and price FLUX 2 provider relays 2026-09-07 18:37:58 -07:00
mateo-berri
95402ccb71 test(azure_ai): move the Foundry catalog metadata test into the mapped azure_ai directory
The new metadata test sat at the top of tests/test_litellm. The azure_ai metadata tests live in tests/test_litellm/llms/azure_ai next to the cost calculator test, so this moves it there and bumps its repo-root lookup by the two extra directory levels. No test changes.
2026-09-07 18:36:40 -07:00
mateo-berri
0d89873daf test(token_counter): type the parametrized cap test arguments 2026-09-07 18:36:09 -07:00