litellm/tests/test_litellm/llms
mubashir1osmani 5339c2d783
fix(vertex/files): stream OpenAI->Vertex batch JSONL uploads (#31036)
* fix(vertex/files): stream OpenAI->Vertex batch JSONL uploads to fix OOM on large files

Large (1GB+) batch JSONL uploads to Vertex AI / GCS caused OOM or killed the worker
because the request body was buffered and multiplied 2-3x in size. The create-file
path is now streaming end-to-end: transform_create_file_request returns a
ResumableChunkedUploadConfig carrying a lazy _OpenAIToVertexBatchUploadStream, and the
HTTP handler opens a GCS resumable session and PUTs the body in bounded 8 MiB chunks
(Content-Range, 308 between chunks) so the transformed payload is never held in full.
The proxy /v1/files endpoint streams from Starlette's spooled upload handle instead of
reading the whole body, and batch rate limiting counts tokens and models in a single
streaming pass.

Only gcs_bucket_name is supported for the GCS target; the legacy bucket_name key is
intentionally not read.

Also removes the unreachable VertexAIFilesHandler create path and everything only it
kept alive (VertexAIJsonlFilesTransformation, _stream_openai_jsonl_to_vertex, the legacy
transform helpers), plus the orphaned batch_utils helpers the streaming rewrite replaced.

* fix(batches): return original JSONL on unparseable row to avoid silent batch truncation

The streaming rewrite of replace_model_in_jsonl accumulated physical lines and
skipped a row on JSONDecodeError to support multi-line objects, but a genuinely
malformed or truncated row never completes: it poisons the buffer, swallows every
following row, and the function still returned the partial rewrite (the rows before
the bad one, already model-rewritten) as if the batch were complete. That turned the
pre-rewrite behavior of returning the original file unchanged (so the provider rejects
the bad batch loudly) into a silent partial submission.

Restore the original-content fallback: when an unparseable remainder is left after the
loop, return the original file_content (rewinding a consumed seekable source) instead of
the truncated output. The multi-line happy path is unchanged.

* test(batches): mock resumable GCS upload in vertex batch prediction test

The vertex batch file-create path now streams to a GCS resumable session via
_aresumable_chunked_upload (httpx send) instead of AsyncHTTPHandler.post, so the
existing test's post mock no longer intercepted the upload and a real request hit
GCS (401). Mock _aresumable_chunked_upload to return the GCS object response; the
resumable protocol itself is covered in test_vertex_ai_files_streaming.py.

* fix(batches): resilient per-row token accounting; no hard-block on count failure

The batch input-file pass iterated a generator whose json.loads raised on a
malformed line; the outer except caught it and stopped the loop, so any body.model
on rows after a bad line was never collected and the model allowlist check ran
against a partial set. It also hard-blocked the batch with a 400 whenever token
counting raised, a backwards-incompatible change from the prior swallow-and-proceed
behavior that breaks legitimate rows the token counter cannot measure (e.g. some
multimodal content).

Iterate the JSONL line-by-line and account each row independently. A malformed line
is skipped (its request cannot run upstream anyway) and a row the counter cannot
measure falls back to a conservative size-based estimate. The loop never aborts, so
the allowlist check always sees every parseable model, and the token total is never
zeroed, so a crafted uncountable row still cannot evade the TPM limit, without
hard-rejecting a legitimate batch.

* perf(vertex/files): unblock async upload; drop empty finalize; widen batch MIME types

Three review follow-ups on the resumable batch upload:
- _aresumable_chunked_upload pulled chunks from a synchronous generator that runs
  the per-row transform inline on the event loop thread, blocking other requests
  between PUTs on large uploads. Each chunk is now produced via asyncio.to_thread.
- _iter_resumable_chunks no longer yields a trailing empty chunk, so an exactly
  chunk-aligned upload finalizes on its last data chunk instead of an extra
  zero-byte PUT; a 0-byte stream still finalizes via the caller's empty request.
- valid_content_type now accepts the MIME types clients label .jsonl batch uploads
  with (text/plain, application/json, ndjson, ...), so such a batch file no longer
  silently bypasses the streaming path into the buffered media upload.

* fix(vertex/files): keep legacy bucket_name as GCS bucket fallback

The rename to gcs_bucket_name dropped the legacy bucket_name key entirely, so an SDK caller passing bucket_name to a Vertex AI file create/retrieve/content call with GCS_BUCKET_NAME unset got ValueError("GCS bucket_name is required") where it previously resolved the bucket. _get_configured_bucket_name now reads gcs_bucket_name, then bucket_name, then the env var, and bucket_name is restored to OPTIONAL_KWARGS_KEYS so it survives get_litellm_params on the retrieve and content paths. gcs_bucket_name keeps precedence when both are present

* style: sort imports in llm_http_handler to satisfy I001 budget

---------

Co-authored-by: Yuneng Jiang <yuneng@berri.ai>
(cherry picked from commit 56825926af)
2026-06-24 18:10:04 -07:00
..
amazon_nova/chat style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
anthropic fix(anthropic): price and surface response service_tier in cost tracking (#30558) 2026-06-17 18:33:56 -07:00
apiserpent Litellm oss staging (#29492) 2026-06-02 08:48:10 -07:00
azure Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
azure_ai Litellm oss staging 030626 (#29578) 2026-06-03 11:01:51 -07:00
base_llm fix(team): keep team_alias cache in sync on _cache_team_object writes (#28737) 2026-05-25 19:16:36 -07:00
baseten/chat style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
bedrock Add Claude Fable 5 across Anthropic, Bedrock, Vertex AI, and Azure AI (#30064) (#30143) 2026-06-10 11:04:00 -07:00
bedrock_mantle feat(bedrock_mantle): add SigV4/IAM auth to Responses API route (fixes #29665) (#29788) 2026-06-15 18:19:17 -07:00
black_forest_labs Litellm OSS Staging 010626 (#29422) 2026-06-01 21:42:51 -07:00
bytez/chat fix: preserve safe provider model path segments 2026-04-29 22:09:54 -07:00
chat style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
chatgpt Litellm oss staging 04 21 2026 2 (#26569) 2026-05-20 21:25:19 -07:00
cloudflare fix: preserve safe provider model path segments 2026-04-29 22:09:54 -07:00
cohere Litellm oss staging 050626 (#29774) 2026-06-05 13:51:51 -07:00
cometapi/chat style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
compactifai style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
crusoe fix(crusoe): remove trailing slashes from API base URLs and fix list indentation 2026-05-01 17:27:52 +05:30
custom_httpx feat(bedrock_mantle): add SigV4/IAM auth to Responses API route (fixes #29665) (#29788) 2026-06-15 18:19:17 -07:00
dashscope Litellm oss staging (#28161) 2026-05-18 16:27:44 -07:00
databricks style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
datarobot style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
deepgram style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
deepinfra style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
deepseek fix(deepseek): use native /anthropic/v1/messages endpoint and sanitize tools (#28200) 2026-05-18 18:14:13 -07:00
docker_model_runner style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
elevenlabs test: avoid provider test module name collision 2026-04-29 22:36:57 -07:00
fal_ai/image_generation feat(fal_ai): add Nano Banana / Gemini 2.5 Flash Image generation support (#29798) 2026-06-06 11:16:44 -07:00
featherless_ai/chat style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
fireworks_ai Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
gemini Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
github_copilot Litellm oss staging (#29492) 2026-06-02 08:48:10 -07:00
heroku style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
hosted_vllm fix(hosted_vllm): normalize custom tools for chat completions (#25763) 2026-05-05 17:27:02 -07:00
huggingface Litellm oss staging 040626 (#29671) 2026-06-04 11:07:20 -07:00
inception Litellm oss staging 030626 (#29578) 2026-06-03 11:01:51 -07:00
jina_ai/embedding feat(JinaAI): support multimodal embedding models (#13181) 2025-08-05 19:21:56 -07:00
langflow feat(agents): add LangFlow agent provider with A2A session bridging (#28963) 2026-06-02 14:45:56 -07:00
lemonade Litellm OSS Staging (#29161) 2026-06-01 21:22:35 -07:00
litellm_proxy chore: simplify ownership tracking — drop thin stores, in-memory fallback, hand-rolled cache 2026-05-05 00:23:32 +00:00
llamafile/chat style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
lm_studio style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
manus fix: encode upstream URL path identifiers 2026-04-29 22:02:39 -07:00
meta_llama fix: add missing OpenAI chat completion params to OPENAI_CHAT_COMPLETION_PARAMS (#21360) 2026-02-16 20:31:21 -08:00
minimax style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
mistral Merge pull request #25256 from BerriAI/litellm_ishaan_april6 2026-04-17 16:26:45 -07:00
moonshot Litellm oss staging 050626 (#29774) 2026-06-05 13:51:51 -07:00
nebius
neosantara Litellm oss staging 050626 (#29774) 2026-06-05 13:51:51 -07:00
novita/chat
nscale/chat
nvidia_riva feat(audio_transcription): add NVIDIA Riva STT provider (#27185) 2026-05-05 17:17:51 -07:00
oci CI: copy of #25177 (OCI GenAI: embeddings, streaming/reasoning fixes, model catalog) (#28223) 2026-05-23 12:15:41 -07:00
ocr Add OCR guardrail_translation handler and support (#22145) 2026-02-28 17:39:36 -08:00
ollama Litellm OSS Staging (#29161) 2026-06-01 21:22:35 -07:00
openai fix(tests): drop import-time completion call in test_register_model (#29521) 2026-06-02 16:10:43 -07:00
openai_like Litellm OSS Staging 010626 (#29422) 2026-06-01 21:42:51 -07:00
openrouter style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
ovhcloud fix(ovhcloud): remove dead transform_response override 2026-04-28 23:09:17 +05:30
perplexity style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
pg_vector/vector_stores fix: encode upstream URL path identifiers 2026-04-29 22:02:39 -07:00
publicai style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
ragflow/chat fix: encode upstream URL path identifiers 2026-04-29 22:02:39 -07:00
recraft style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
reducto Litellm oss staging 04 21 2026 2 (#26569) 2026-05-20 21:25:19 -07:00
runwayml fix: encode upstream URL path identifiers 2026-04-29 22:02:39 -07:00
s3_vectors Fix extra body error 2026-04-29 08:34:31 +05:30
sagemaker fix(sagemaker): send native Cohere embed payload to Cohere SageMaker endpoints (#28613) 2026-05-22 12:00:42 -07:00
sambanova Feat/sambanova embeddings (#13308) 2025-08-12 17:15:26 -07:00
sap style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
scaleway Feature/add audio support for scaleway (#26110) 2026-04-20 14:49:41 -07:00
snowflake style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
soniox Litellm oss staging 050626 (#29774) 2026-06-05 13:51:51 -07:00
stability style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
vercel_ai_gateway style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
vertex_ai fix(vertex/files): stream OpenAI->Vertex batch JSONL uploads (#31036) 2026-06-24 18:10:04 -07:00
volcengine fix: encode upstream URL path identifiers 2026-04-29 22:02:39 -07:00
voyage/rerank style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
wandb (feat): Add W&B Inference to LiteLLM 2025-09-11 00:07:30 +05:30
watsonx Litellm OSS Staging 010626 (#29422) 2026-06-01 21:42:51 -07:00
xai Litellm oss staging (#29492) 2026-06-02 08:48:10 -07:00
you_com Litellm oss staging 050626 (#29774) 2026-06-05 13:51:51 -07:00
zai style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_cache_control_and_reasoning.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_file_content_block.py Litellm oss staging (#28161) 2026-05-18 16:27:44 -07:00
test_file_search_responses.py fix(tests): use canonical litellm_enterprise import path (#27699) 2026-05-12 12:32:57 -07:00
test_lifecycle_fix.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_oom_fixes.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_polling_url_origin_match.py chore(security): close two unaddressed SSRF cases 2026-05-01 18:43:47 +00:00
test_predibase_transformation.py refactor(predibase): migrate transform_request and transform_response… (#25249) 2026-04-27 08:58:22 +05:30