Commit graph

42178 commits

Author SHA1 Message Date
mateo-berri
6ca120a674 fix(proxy): coerce and validate the sse keepalive ping interval from config 2026-08-05 17:23:39 -07:00
mateo-berri
131339d8e5 fix(proxy): send keepalive pings on anthropic messages SSE streams during upstream silence 2026-08-05 16:15:04 -07:00
Yassin Kortam
0659738b3e
fix(migrations): recover from an interrupted Prisma toolchain install (#35832)
The Prisma CLI is a Node program that installs a private Node runtime on its
first invocation. That one-time install shared the 60s budget that bounds each
migration command, so on a slow or cold machine it was killed before it could
finish. Prisma then decides whether to reinstall by testing the cache
directory for existence alone, and a killed install leaves that directory
behind, so every later attempt skipped the install and failed on a node binary
that was never written. The existing four-attempt retry loop could not help:
each attempt hit the same missing binary, which turned a slow start into a
container that never migrated again.

Migrations now prepare the toolchain as its own step under its own budget, and
a cache directory that exists without a node binary is deleted first so an
interrupted install reinstalls instead of persisting. Both budgets are
overridable, LITELLM_PRISMA_BOOTSTRAP_TIMEOUT for the install and
LITELLM_PRISMA_COMMAND_TIMEOUT for each Prisma command, and every previously
hardcoded timeout now goes through one helper rather than thirteen literals.
The per-command default stays at 60s.

An override is only honoured when it parses as a finite positive number.
Infinity and NaN parse as floats and survive a plain positivity check, and
subprocess treats either as no deadline at all, so a value like `inf` or a
fat-fingered `1e400` would have silently disabled the timeout it was meant to
configure.
2026-08-05 10:14:46 -07:00
Yassin Kortam
54fb717de1
fix(router): redact fallback tracebacks at the call site and cover the sync deferred stream (#35843)
Three follow-ups surfaced while merging current staging into this branch.

`exc_info=True` at both fallback-failure log sites handed a live exception to
the logging machinery. SecretRedactionFilter rewrites `record.exc_text`, but
`record.exc_info` stays an exception object no filter can reach, so a handler
that renders it itself (Datadog and OTel log bridges do) received the
unredacted provider key. Both sites now pass `redact_string(traceback.format_exc())`
as a `%s` arg, keeping staging's lazy-logging form. The existing test only
asserted on `exc_text`, so it passed under the bug; it now renders `exc_info`
the way a bridge handler would and covers every record the call emits.

The eager deferred-stream fetch existed only on the async path. Vertex and
Bedrock build the same `completion_stream=None` plus `make_call` wrapper on
their sync branches, so `Router.completion(stream=True)` still surfaced the
provider error on first iteration, outside `_completion`'s except block, and
never reached the fallback chain. `_completion` now calls `fetch_sync_stream()`
under the same guard `_acompletion` uses.

The first of the three header-strip passes in the proxy error path was dead:
only the custom-header update and the response-headers hook run before the
second pass re-filters everything. Collapsed to one `safe_headers` binding.
2026-08-05 10:06:52 -07:00
Mateo Wang
8fe9809a4b
Merge pull request #35365 from rimysore/fix-managed-files-null-object
fix(managed-files): skip rows without file objects
2026-08-05 10:01:42 -07:00
Mateo Wang
520e38e232
Merge pull request #35929 from BerriAI/litellm_zero_dashboard_eslint_headroom
chore(ui): zero stale headroom on local dashboard eslint budgets
2026-08-05 09:47:16 -07:00
Mateo Wang
0b8c7f29ed
Merge pull request #35927 from BerriAI/litellm_zero_more_local_basedpyright_rules
chore(lint): zero out seven more purely local basedpyright rules
2026-08-05 09:46:21 -07:00
Mateo Wang
551f395dbf
Merge pull request #35928 from BerriAI/litellm_zero_ruff_lit_headroom
chore(lint): zero stale ruff and LIT headroom and strip inert type: ignore comments
2026-08-05 09:46:05 -07:00
Abhimanyu Kapur
cc1c7d6101
feat(complexity_router): let operators rename the four complexity tiers (#35893)
* feat(complexity_router): let operators rename the four complexity tiers

Adds an optional tier_labels map to complexity_router_config so a deployment can
put its own vocabulary on the four tiers, e.g. Cheap / Standard / Premium / Deep,
instead of reading SIMPLE / MEDIUM / COMPLEX / REASONING in its dashboard, its
spend logs, and the rubric the LLM classifier reasons with.

Labels are display-only. Every config key stays canonical, so tiers,
keyword_tier_rules[].tier, and tier_boundaries are written exactly as they are
without labels, and partial maps are fine with unlisted tiers keeping their
default name. A validator rejects blank labels, two tiers sharing a label, and a
label that is another tier's canonical name, since any of those would make a log
row or a rubric line ambiguous. That validator runs on the /model/new and
/model/update write path already, so an ambiguous config gets a 400 rather than
being stored for the router to refuse later.

Under the default heuristic scorer the names are cosmetic: the scorer maps a
weighted score to a rung and never reads a tier name, verified by running the
eval corpus with and without a rename and getting identical tier and identical
score on all 29 cases. Under classifier_type: llm the labels are the names in the
rubric and the values the classifier must return, so the response format's enum
is now built from the configured labels and a reply is resolved back to its tier
against labels first, then canonical names, case-insensitively. An unresolvable
reply degrades to the heuristic on the existing fallback path. A test pins the
generated schema for an unrenamed deployment as equal to the shipped
TierClassification schema, so the wire shape can't drift.

Spend logs keep routing_decision.tier canonical so rows from before and after a
rename stay comparable, and gain routing_decision.tier_label on the tiers that
were renamed.

* refactor(complexity_router): drop added comments and the Counter construction

Review feedback: the repository guide bans new comments, so the explanatory
comments and the appended docstring paragraphs this branch added come back out.
One-line docstrings stay in complexity_router.py, matching that file's own
convention.

The duplicate-label check no longer builds a Counter, which the mutable-collection
budget counts, and the error text drops its list() reprs for joined strings. The
labels are stripped in tier_label() now rather than by rewriting the field in the
validator, so the stored config keeps exactly what the operator wrote.

schema.d.ts is regenerated: ComplexityRouterConfig is exposed in the OpenAPI spec,
so tier_labels surfaces there.

* fix(ui): carry tier_labels through the auto-router preset prefill

buildPresetPrefill maps every payload key onto form state, but the tier_labels
key added by this branch had no line, so a preset shipping labels would apply
its tiers and silently drop its names.
2026-08-05 09:42:57 -07:00
Mateo Wang
7900e1fc79
Merge pull request #35251 from BerriAI/litellm_fix_codecov_oidc_flake 2026-08-05 09:26:43 -07:00
mateo-berri
f270b53144 Merge branch 'litellm_internal_staging' into fix-managed-files-null-object 2026-08-05 03:05:32 -07:00
mateo-berri
20d297a151 Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_zero_ruff_lit_headroom
# Conflicts:
#	litellm/llms/anthropic/experimental_pass_through/responses_adapters/streaming_iterator.py
2026-08-05 02:53:06 -07:00
Mateo Wang
b735578822
Merge pull request #35367 from rimysore/fix-responses-batch-usage
fix(batches): account for Responses API usage
2026-08-05 02:51:35 -07:00
mateo-berri
83008a916d Merge remote-tracking branch 'origin/litellm_internal_staging' into fix-responses-batch-usage
# Conflicts:
#	litellm/batches/batch_utils.py
2026-08-05 02:38:02 -07:00
mateo-berri
338e411103 chore(lint): strip inert type: ignore comments and zero LIT009, LIT010, LIT011 headroom 2026-08-05 02:37:24 -07:00
Mateo Wang
64f4bedde1
Merge pull request #34957 from BerriAI/litellm_gpt56_cache_token_pricing
fix(cost): bill gpt-5.6 prompt cache reads at the cache read rate
2026-08-05 02:30:41 -07:00
Mateo Wang
71f7fad16a
Merge pull request #34812 from BerriAI/litellm_fix_openai_cache_token_details_loss
fix(cost_tracking): keep OpenAI prompt cache token details through usage reassembly
2026-08-05 02:21:49 -07:00
mateo-berri
0c50661307 chore(lint): re-tighten reportPrivateUsage and reportDeprecated to post-merge counts 2026-08-05 02:15:42 -07:00
mateo-berri
d4611a1253 Merge origin/litellm_internal_staging 2026-08-05 02:12:38 -07:00
mateo-berri
69a8043667 chore: keep base field ordering for service tier cache write costs 2026-08-05 02:11:05 -07:00
mateo-berri
a9902fcdb5 fix(streaming): carry Anthropic cache-creation TTL split through fallback usage reassembly 2026-08-05 02:06:52 -07:00
mateo-berri
e8a80b9883 docs(anthropic): state why usage-shape detection requires a cache key, pin Responses-shape rejection 2026-08-05 02:01:53 -07:00
mateo-berri
bd04520d98 Merge branch 'litellm_internal_staging' into litellm_gpt56_cache_token_pricing 2026-08-05 01:51:07 -07:00
mateo-berri
b4b5c8f0a1 chore(ui): zero stale headroom on local dashboard eslint budgets 2026-08-05 01:45:02 -07:00
mateo-berri
cdfefd7f41 chore(lint): zero stale headroom on purely local ruff and LIT rules 2026-08-05 01:40:30 -07:00
mateo-berri
021b52527b chore(lint): zero out seven more purely local basedpyright rules 2026-08-05 01:31:09 -07:00
mateo-berri
74f1b934be chore(ui): format CacheLeakageCard with prettier 2026-08-05 01:23:54 -07:00
mateo-berri
7288247682 Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_fix_openai_cache_token_details_loss
# Conflicts:
#	litellm/litellm_core_utils/llm_cost_calc/utils.py
#	litellm/litellm_core_utils/streaming_chunk_builder_utils.py
#	litellm/litellm_core_utils/streaming_handler.py
#	tests/test_litellm/litellm_core_utils/test_streaming_chunk_builder_utils.py
2026-08-05 01:23:54 -07:00
Mateo Wang
732bba00df
Merge pull request #35862 from BerriAI/litellm_self_heal_evicted_httpx_clients
fix(http_handler): self-heal handler clients closed after cache eviction
2026-08-04 23:55:53 -07:00
mateo-berri
c11ea9694a Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_self_heal_evicted_httpx_clients 2026-08-04 22:52:06 -07:00
mateo-berri
34f87a1a91 fix(async_client_cleanup): stop cleanup from resurrecting healed clients 2026-08-04 22:43:40 -07:00
tin-berri
4fcaf7d736
feat(spend): derive a default auto-router savings baseline from the hardest tier (#35907)
* feat(spend): derive a default auto-router savings baseline from the hardest tier

The savings driver shipped off by default: unless an operator names
litellm_settings.autorouter_savings_baseline_model, every auto-routed request
records $0.00 and the dashboard card never populates. Nobody discovers a knob
whose feature they have never seen work, so the default has to come from
somewhere the proxy already knows.

The router's own tier ladder is that place. Without a router a deployment runs
one model that can carry the hardest request it will see, so the derived
baseline is the priciest model in the hardest configured tier, REASONING when
present, otherwise the most severe tier the router actually defines. A cheap
tier is a choice the router made, not a ceiling it was bounded by.

An earlier draft of #35521 derived this per request and was deleted for it:
ranking candidates against the request that ran meant reading the request, and
every input shape it could take produced its own review finding. This
derivation is ranked against one fixed reference request instead, a cache-heavy
shape matching real auto-routed traffic, so it never reads the request at all.
Candidates still resolve through the router's deployments, so Azure base_model
and per-deployment pricing overrides rank correctly.

The deciding router records the result on its routing_decision, because one
model name can carry several tag-scoped routers with different tier ladders and
only the deciding instance knows which of them routed the request. The spend
writer's precedence is: configured baseline, then the recorded one, then off.
When the setting is present the router skips deriving entirely rather than
pricing candidates per decision only to be ignored.

Resolution never raises; an unresolvable baseline zeroes the driver instead of
failing a live request. Rows queued by a pod on the previous release carry no
recorded baseline and fall back to the configured setting, exactly as today.

The schema.d.ts regeneration also picks up the reminder_markers field that
UI-19232 (#35874) added without regenerating, so one hunk there is inherited
staleness rather than part of this change.

* fix(spend): cache the derived baseline, price it by deployment, keep it out of the routing preview

Three review findings on the derived baseline, addressed together because they
all sit on the same value's path from derivation to consumer.

Derivation walked and priced the hardest tier's whole pool inside a property
read on every routing decision, unbounded by pool size. The router now caches
the result per instance with a 30 second TTL, None results included, so the
hot path is a clock compare and a deployment edit still lands within a window
no operator watches closer than.

Ranking used each deployment's effective pricing but recorded only the model
name, so the spend writer priced the winning baseline at its public rate: a
hardest tier whose deployment carries a negotiated rate produced materially
wrong savings. The decision now also records savings_baseline_deployment_id
and the writer resolves it through Router.get_deployment_model_info, exactly
as the selected arm already does. The id is ignored whenever the configured
setting overrides the recorded baseline, since the setting names a model, not
a deployment.

/auto_router/test_routing returns the routing decision verbatim to team admins
while only authorizing the classifier and embedding models, so a derived
baseline would resolve another team's model-group alias into its backend
provider/model mapping and hand it to a caller never authorized for it. The
preview's throwaway router is built with derive_savings_baseline=False; its
decisions are never spend-tracked, so nothing is lost, and a source-pinning
test keeps the flag on the endpoint.

Also strips the explanatory comments this PR had added.

* refactor(spend): pin the derived baseline per router instance instead of a TTL

Creating or editing a router already rebuilds its ComplexityRouter instance,
through unregister and re-add on upsert and through the registry reset on a
full model_list load, so a value derived once per instance refreshes on
exactly the flows that can change it. That makes the TTL a solution to a
problem the rebuild lifecycle already solves, and it goes.

Derivation stays deferred to first use rather than running in __init__: during
a config load this router can be constructed before the deployments its tiers
name, and a baseline pinned at that moment would be empty for the process
lifetime.

The one behavior the TTL had that the pin does not: editing a tier deployment
without touching the router itself refreshed the baseline within a window.
That edit path rebuilds only the edited deployment's own strategies, so the
pin holds the old answer until the router is next saved or the config next
loads. A stale deployment id degrades to public-rate pricing rather than
failing, which is where every other unresolvable baseline already lands.
2026-08-04 22:36:45 -07:00
Mateo Wang
86b59fd1bb
Merge pull request #35903 from BerriAI/litellm_precommit_parallel_blocks
perf(pre-commit): run python, dashboard, and gen-api checks concurrently
2026-08-04 22:30:18 -07:00
Mateo Wang
09be7f4b94
Merge pull request #35895 from BerriAI/litellm_bootstrap_node_floor
fix(bootstrap): switch to the dashboard node floor via nvm or fnm
2026-08-04 22:30:09 -07:00
mateo-berri
d7dbb28b32 fix(pre-commit): scope interrupt cleanup to the job process groups 2026-08-04 21:37:01 -07:00
mateo-berri
a1f497c7c0 fix(pre-commit): kill background jobs and remove their logs on interrupt 2026-08-04 21:28:46 -07:00
mateo-berri
e528e57e53 fix(bootstrap): fail fast when nvm cannot activate the pinned node 2026-08-04 21:18:58 -07:00
mateo-berri
2f36625e7f perf(pre-commit): run python, dashboard, and gen-api checks concurrently 2026-08-04 21:18:00 -07:00
tin-berri
bbc6e3feea
Update autorouter_presets.json (#35896) 2026-08-04 21:16:52 -07:00
mateo-berri
c418ea59ae fix(bootstrap): switch to the dashboard node floor via nvm or fnm
The dashboard pins engines node >=24.14.1 with engine-strict, so make
bootstrap dies with EBADENGINE on any shell whose default node is older.
Wrap the npm install in scripts/with_dashboard_node.sh: it execs the
command as-is when node already meets the floor, otherwise activates the
.nvmrc version via nvm or fnm, and fails fast with install instructions
when neither manager exists
2026-08-04 21:02:26 -07:00
Abhimanyu Kapur
31a86daa85
feat(auto-router): make reminder marker pair configurable (#35874)
* feat(auto-router): make reminder marker pair configurable

Some harnesses inject internal context using their own marker pair
instead of Claude Code's <system-reminder>/</system-reminder>
convention, and some send it as a separate follow-up user message
rather than inline with the ask. Both cases fall out of the same root
cause: the router's marker-matching is hardcoded, so foreign markers
never strip to empty and the reminder-only turn wins "newest human
ask" selection instead of being skipped.

Add an optional reminder_markers field to ComplexityRouterConfig so
operators can override the (open, close) pair via proxy config, with
the existing skip-when-empty selection logic handling both cases once
the markers match.

* test(auto-router): drop unsolicited comments from the reminder-markers regression test

Per Greptile review on #35874: no comments unless explicitly requested.
2026-08-05 03:08:49 +00:00
Yassin Kortam
1e265dc86c
fix(auth): name enable_jwt_auth when a JWT-shaped key is rejected (#35831)
A three-segment token presented while `general_settings.enable_jwt_auth` is
unset is never treated as JWT-shaped, so it falls through to the virtual-key
path and is rejected for not starting with 'sk-'. That reads as a missing
key in the verification table and sends the operator off to inspect virtual
keys, when the real cause is one missing config line. The rejection now
names `enable_jwt_auth`, appended to the existing text so the Prometheus
invalid-key filter and the admin UI keep matching what they match today.

The hint claims only that the key is JWT-shaped. Segment count cannot tell a
JWT from any other dotted credential, so asserting the key IS a JWT would
swap one confident misdiagnosis for a narrower one.

The enterprise gate on that same path raised a bare `ValueError`, which the
terminal handler turns into a 401. Every sibling enterprise gate answers
403, and a 401 tells the client to retry with a better credential, which no
credential can satisfy while the install is unlicensed. It now raises a 403
`ProxyException` like the SSO gate does.
2026-08-04 20:05:03 -07:00
Mateo Wang
5aeb34b58c
Merge pull request #35884 from BerriAI/litellm_precommit_stale_types_no_rerun
chore: stop advising pre-commit and bootstrap
2026-08-04 20:00:17 -07:00
Mateo Wang
548c67c120
Merge pull request #35888 from BerriAI/litellm_remove_flake8
chore: remove unused .flake8 config and flake8 dev dependency
2026-08-04 19:43:39 -07:00
Mateo Wang
a0d08b8143 chore: remove pre-commit and bootstrap advisories
They were taking too long
2026-08-04 19:38:34 -07:00
mateo-berri
38cd75342d Note the one case where staging schema.d.ts changes what runs
For a backend-only commit, staging the regenerated schema.d.ts newly
satisfies the ui file triggers, so the folder-wide dashboard lint
budgets run locally for the first time and CI's frontend-lint job
(budgets plus knip) activates on the PR. Those can only fail from
pre-existing dashboard-tree state, never from the regenerated file,
but the guidance should say so instead of implying a re-run is
always redundant.
2026-08-04 19:38:34 -07:00
mateo-berri
4a2ceed595 Stop advising a pre-commit re-run for stale dashboard API types
The stale-types failure already writes the regenerated schema.d.ts to the
working tree, and staging it cannot introduce a new failure: the file is
listed in .prettierignore and the eslint config ignores, so no lint pass
sees it, and gen:api derives it purely from the Python proxy code, so a
second regeneration is a no-op. The only reason left to re-run is when
other checks also failed, so say exactly that in the script message and
CLAUDE.md instead of prescribing an unconditional re-run.
2026-08-04 19:38:34 -07:00
yuneng-jiang
03de6280b6
Merge pull request #35802 from BerriAI/litellm_/modest-pascal-71b7b2
refactor(ui): inject the fetch client's base url instead of reading it at import
2026-08-04 19:34:39 -07:00
yuneng-jiang
96c66ce4b7
Merge pull request #35812 from BerriAI/litellm_/internal-user-endpoint-audit-36c1c5
feat(ui): add role capability gating, migrate Tool Policies route
2026-08-04 19:34:26 -07:00
Mateo Wang
faf3c51469
Merge pull request #35869 from BerriAI/litellm_gate_owns_basedpyright_heap
fix(lint): move the basedpyright heap flag into the type check gate
2026-08-04 19:26:24 -07:00