litellm/tests/unit/proxy/openai_files_endpoint
mika-lt f0548f9a19
fix(proxy): rewrite batch JSONL alias rows to the deployment model on model-routed uploads (#51843)
* fix(proxy): rewrite batch JSONL rows to the deployment model on model-routed uploads

* fix(proxy): rewrite only alias rows and authorize them against the alias at batch create

* fix(proxy): keep batch create working when the credentials lookup names no model

* fix(proxy): spool the batch alias rewrite to disk and close it after upload

* fix(proxy): rewrite only alias rows in model-routed batch uploads and charge both project quotas

Rows that do not name the alias now reach the provider exactly as uploaded, and a file with no alias row is sent unchanged. Rewritten rows are compact UTF-8 JSON. Rows routed through the alias count against the project quota of both the alias and the model the row names

* fix(proxy): keep every byte of non-alias batch rows and skip files with nothing to rewrite

* fix(proxy): rewind batch uploads instead of calling seekable() so Python 3.10 works

* fix(vertex_ai): honor deployment and row drop_params for sampling params in batch file rows

* fix(batches): rewrite escaped alias rows and charge shared quota counters once

Parse each row's model to find rows naming the alias, so an alias written
with JSON escapes is rewritten too. Merge a row's alias and real model into
one project quota descriptor per counter, so a model_group_alias that puts
both in one group charges the row once against the lower limit.

* test(batches): prove the shared quota counter is charged once on the Redis store

* test(files): capture model-routed batch uploads at the provider HTTP boundary

* fix(batches): charge a shared project counter once per batch and keep rows JSON cannot re-encode

A batch file that mixes rows naming the proxy alias and rows naming the
deployment model built one project ITPM/OTPM descriptor per row group, so
the in-memory limiter checked each group against the quota on its own and
let the batch through. Descriptors now merge by counter with summed tokens,
and the 429 detail reports the merged total.

A row whose numbers JSON cannot write back, such as 1e400, was rewritten as
Infinity. It now stays byte-identical, the same as rows the rewrite skips.

* fix(batch_rate_limiter): hold a shared project counter to its strictest limit

When a batch file mixes rows naming the alias and rows naming a model in the
same group, both row groups charge one project ITPM/OTPM counter. The merged
descriptor kept the first group's limit, so a stricter limit set on the other
name was skipped. Merge them with the limiter's coalesce_rate_limit_descriptors,
which keeps the lowest limit, the same rule a single request already follows.

* chore(rust): restore generate_stdlib_fixtures.py as it is on main

An earlier merge commit reformatted this ruff-excluded fixture script. Restoring main's bytes keeps the PR to the batch alias fix

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-16 15:12:52 -08:00
..
__init__.py
test_batch_guardrails.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_file_usage_caps.py
test_files_batch_file_validation.py fix(vertex_ai): return 400 with file line number for malformed batch JSONL row (#40097) 2026-10-15 03:21:48 -07:00
test_files_common_utils.py fix(files): match every spelling of a provider file id in the ownership check (#51498) 2026-11-13 05:43:43 +00:00
test_files_endpoint.py fix(proxy): rewrite batch JSONL alias rows to the deployment model on model-routed uploads (#51843) 2026-11-16 15:12:52 -08:00
test_general_upload_validation.py
test_storage_backend_service.py refactor(typing): clear 1181 basedpyright Any errors across 431 files (#47789) 2026-10-24 11:31:09 -07:00