Commit Graph

136 Commits

Author SHA1 Message Date
Mateo Wang 05439530c2 Merge branch 'litellm_internal_staging' into litellm_vcr-cassette-llm-tests-af37 2026-05-01 14:37:48 -07:00
mateo-berri 80415b472e tests(vcr): drop redundant comments and docstrings
Remove explanatory comments that restated what the code already says.
Kept only those that document non-obvious external contracts (the aiohttp
record-path patch's reason for re-feeding the body, and the warning
messages inside save_cassette that reach the user).
2026-05-01 14:36:48 -07:00
mateo-berri 53f71fbf4d tests(vcr): emit per-test verdicts via xdist controller's terminalreporter
Previous attempt wrote to sys.__stderr__ from the test fixture. Under
xdist, fixtures run inside worker subprocesses whose stderr is captured
by the controller and only released to the live log on test failure —
so passing tests' verdicts were silently swallowed.

Round-trip via report.user_properties: the worker-side fixture stashes
the verdict on user_properties, xdist serializes it onto the report,
and a controller-side pytest_runtest_logreport hook writes it via the
TerminalReporter (the same plugin that emits PASSED/FAILED markers).
TerminalReporter is resolved lazily on first hook call because it's
not yet registered when conftest's pytest_configure runs.

Verified locally in both serial and xdist modes.
2026-05-01 14:29:06 -07:00
mateo-berri c05c865a1c tests(vcr): emit verbose verdicts to un-redirected stderr
Previously, the per-test [VCR HIT/MISS/...] line was written via
TerminalReporter.write_line from inside fixture teardown. Pytest
captures that stream by default and only surfaces it on FAILED tests
(under 'Captured stdout teardown'), so passing tests' verdicts were
invisible in CI logs and the user couldn't tell whether the cache
was working.

Write directly to sys.__stderr__ so the line bypasses pytest's
capture entirely. Under xdist each worker has its own __stderr__
which CircleCI aggregates into the live job log alongside the
PASSED/FAILED markers.
2026-05-01 14:14:44 -07:00
mateo-berri ff63bdb984 tests(vcr): only persist cassette on test pass to avoid poisoning cache
A test that fails (incl. all the failing retries before a passing one)
can otherwise overwrite a known-good cassette with a 'bad luck'
recording. Tests like test_prompt_caching, which assert on provider
state across two calls, can produce a 200 response that semantically
fails the assertion — the 2xx filter doesn't catch this because the
HTTP layer is fine.

- pytest_runtest_makereport hook attaches each phase report to the
  pytest item.
- _vcr_outcome_gate fixture (combining the verbose-mode reporter)
  reads the call-phase outcome at teardown and informs the persister
  via mark_test_outcome_for_cassette before vcrpy's Cassette.__exit__
  triggers save_cassette.
- save_cassette consults the per-key 'did the test pass?' flag and
  short-circuits when False, leaving any prior good recording intact.
- Defaults to passed=True when no marker is present so non-test
  usage of the persister still works.
2026-05-01 13:35:29 -07:00
mateo-berri cf4c9ede61 tests(vcr): add LITELLM_VCR_VERBOSE per-test hit/miss reporting
Set LITELLM_VCR_VERBOSE=1 to print a one-line cassette verdict per
test (HIT / MISS / PARTIAL / NOOP) showing replay vs new-recording
counts. Useful for local QA to confirm which tests actually exercised
the cache and which fell through to the live provider.
2026-05-01 13:00:20 -07:00
mateo-berri 4c69557621 tests(vcr): isolate cassette redis to CASSETTE_REDIS_URL
Stop falling back to REDIS_URL/REDIS_SSL_URL/REDIS_HOST for the VCR
persister. Sharing a Redis with the application cache risks cassettes
being wiped by tests that flush the app Redis.
2026-05-01 12:32:59 -07:00
Sameer Kankute 15288f3ae7 test: include response key in response.completed chunk for ID hook test
_base_process_chunk only encodes response IDs when parsed_chunk contains
a top-level "response" key. Align test_process_chunk_completed_response_
updates_id_and_usage_cost with that contract and test_base_responses_api_streaming_iterator.

Made-with: Cursor
2026-05-01 15:41:17 +05:30
Noah 8947a74e13 fix(cache): persist and replay streamed Responses API requests (#24580)
* fix(cache): persist and replay streamed Responses API requests

* Add focused coverage for streamed responses cache

* Cover streamed responses cache helper branches

* Exercise streamed responses cache edge branches
2026-05-01 11:55:36 +05:30
mateo-berri 67287460e5 tests(vcr): drop redundant comments and docstrings 2026-04-30 18:45:56 -07:00
mateo-berri 687ff32616 tests(vcr): patch vcrpy aiohttp record path instead of forcing httpx transport
vcrpy's aiohttp stub captures response bodies via 'await response.read()',
which drains aiohttp's StreamReader. Downstream consumers of the same
ClientResponse (litellm's AiohttpResponseStream, which iterates
response.content.iter_chunked) then see an empty body and surface as
JSON 'Expecting value: line 1 column 1 (char 0)' errors on every
record-path call.

The previous workaround set litellm.disable_aiohttp_transport=True for
the whole VCR-active session, which made the tests exercise pure httpx
instead of the production aiohttp transport. That hid the production
transport from coverage and surfaced its own bugs (e.g. the Azure
DELETE-with-empty-body case fixed in upstream staging).

Replace the workaround with a targeted monkey-patch that re-feeds the
captured body into the StreamReader via unread_data after vcrpy records
it. Tests now run through the same transport customers do, both on
first record and on replay, for both unary and streaming endpoints.

Verified locally against api.anthropic.com with the production
LiteLLMAiohttpTransport: record path passes (real network, 4.2s),
replay path passes (Redis cache, 1.8s).
2026-04-30 18:43:06 -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
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
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 59d5901766 tests(vcr): allow playback repeats so duplicate intra-test requests serve from cache 2026-04-30 22:57:21 +00:00
mateo-berri e1f2b4b818 tests(vcr): trim non-load-bearing comments and docstrings
Removes commentary that restated the code, including:

- module-level banners explaining what the conftest does (covered by
  Readme.md and the function bodies)
- docstrings on _scrub_response, _before_record_response, vcr_config,
  _vcr_disabled, pytest_recording_configure (function names + bodies
  are self-evident)
- inline notes about header filtering, match_on, etc.
- per-test docstrings restating the test name

Keeps the two non-obvious notes that aren't recoverable from the code:
the vcrpy/respx httpx-transport collision rationale on
_RESPX_CONFLICTING_FILES, the vcrpy "return None to skip persisting"
contract on filter_non_2xx_response, and the fixture-ordering
dependency on _vcr_record_retries.
2026-04-30 21:48:48 +00:00
mateo-berri c7d647b567 tests: drop YAML cassettes, make Redis-backed VCR the default
Removes the YAML cassette feature entirely and replaces it with a
Redis-only flow. Every test in tests/llm_translation/ and
tests/llm_responses_api_testing/ is auto-marked @pytest.mark.vcr via
conftest.pytest_collection_modifyitems, so any provider call lands in
the Redis cache (litellm:vcr:cassette:<rel_path>, 24h TTL). First run
records, runs within the day replay, day rollover re-records and
surfaces upstream API drift within 24h.

VCR is on by default. Set LITELLM_VCR_DISABLE=1, or simply leave
REDIS_HOST unset, to opt out — both bypass the auto-marker entirely so
nothing about cassettes runs. record_mode is "once" so cache-miss
records and cache-hit replays.

The 8 existing respx-using files in tests/llm_translation are excluded
from the auto-marker (vcrpy and respx both patch the httpx transport;
applying both makes one silently win). The persister's own unit-test
file is also excluded so it doesn't recursively run inside a cassette.

The persister moved from tests/llm_translation/_vcr_redis_persister.py
to tests/_vcr_redis_persister.py so both conftests share it. The two
demo tests in test_anthropic_completion_vcr.py were ported into
test_anthropic_completion.py and the demo file was deleted.

Adds tests/_flush_vcr_cache.py + a Make target
(test-llm-translation-flush-vcr-cache) that scans
litellm:vcr:cassette:* and pipelines DELETEs, for the
"I want the next CI run to re-record now" workflow. Drops the now-dead
test-llm-translation-record target.

Provider keys are still required on cache-miss (which happens on first
run and once a day after that). Replay-mode runs need only Redis.
2026-04-30 21:40:58 +00:00
Ishaan Jaffer e8461b5b97 style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
Krrish Dholakia 0cf4b05991 test: remove bad e2e tests - e2e failing due to low rate limits on ci/cd 2026-03-30 19:18:10 -07:00
Krrish Dholakia bc829d51f2 test: test 2026-03-28 19:17:38 -07:00
Krrish Dholakia 08f0cbc2e9 fix: address greptile feedback 2026-03-18 21:36:39 -07:00
Sameer Kankute 631400cb17 Fix anthropic responses 2026-02-20 17:30:42 -08:00
Ishaan Jaff d11832bfad fix(responses): eliminate per-chunk thread spawning in async streaming path (#21709)
* fix(responses): fix O(n²) CPU overhead in reasoning streaming path

stream_chunk_builder was called on every reasoning chunk, rebuilding the
entire response from all collected chunks each time. Replace with
incremental accumulation of reasoning_content parts, only joining at
reasoning end.

* fix(responses): eliminate per-chunk thread spawning in async streaming path

_process_chunk() called run_async_function() on every SSE chunk, which
when invoked from an async context spawns a thread + event loop per call.

Move the hook call out of _process_chunk into the callers: async __anext__
directly awaits it, sync __next__ uses run_async_function.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* perf: reduce responses streaming CPU for text-only streams

* fix(test): replace deprecated claude-3-7-sonnet-latest in responses API test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(test): replace deprecated claude-3-7-sonnet-latest in tool result fix test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(test): replace deprecated claude-3-7-sonnet-latest in tool result empty call_id test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 16:26:23 -08:00
yuneng-jiang 45e6440b0a fixing test_basic_openai_responses_api 2026-02-16 20:14:06 -08:00
Ishaan Jaffer b8f572fc39 test_responses_api_shell_tool_streaming_sees_shell_output 2026-02-14 12:55:44 -08:00
Ishaan Jaffer 6a4b531057 def get_advanced_model_for_shell_tool(self) -> Optional[str]:
AZURE
2026-02-14 12:29:42 -08:00
Ishaan Jaffer 77dd3cb2b2 test_responses_api_shell_tool_streaming_sees_shell_output 2026-02-14 11:32:52 -08:00
Ishaan Jaffer ad910de1e3 test_o1_parallel_tool_calls 2026-02-14 10:47:38 -08:00
Ishaan Jaff 736daf0a7d [Feat] Adds Shell tool support for the OpenAI Responses API (#21063)
* test_responses_api_context_management_server_side_compaction

* Server-side compaction

* docs fix

* test_responses_api_shell_tool

* add SHELL tool

* test_responses_api_shell_tool

* add SHELL_CALL_IN_PROGRESS

* add SHELL_CALL_IN_PROGRESS events

* TestOpenAIResponsesAPITest

* transform_streaming_response

* test_responses_api_shell_tool_streaming_sees_shell_output

* test_responses_api_shell_tool_streaming_sees_shell_output

* test_responses_api_shell_tool

* docs fix
2026-02-12 13:04:29 -08:00
Ishaan Jaff 3d9b145b04 [Feat] Adds support for server-side compaction on the OpenAI Responses API context_management (#21058)
* test_responses_api_context_management_server_side_compaction

* Server-side compaction

* docs fix

* test_responses_api_shell_tool
2026-02-12 10:00:30 -08:00
Sameer Kankute 8357d05615 Fix: Responses API logging error for StopIteration 2026-01-23 18:42:33 +05:30
Sameer Kankute ff7bb59824 Merge branch 'main' into litellm_fix_streaming_test 2026-01-19 19:43:16 +05:30
Sameer Kankute c9de4776bc Fix test_process_chunk_exception_calls_handle_failure_once 2026-01-19 19:39:12 +05:30
Cesar Garcia b49f0a91e4 fix(responses): resolve deepcopy error with tool_choice ValidatorIterator (#17192) (#17205)
Replace copy.deepcopy with model_dump + model_validate in streaming
iterator logging to handle Pydantic ValidatorIterator objects that
cannot be pickled when tool_choice uses allowed_tools mode.

Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
2026-01-19 05:44:20 -08:00
Sameer Kankute fbf2d83375 Fix: _handle_failure method getting called 2 times 2026-01-19 10:19:31 +05:30
Ishaan Jaffer 1ebe979eee test_manus_responses_api_with_file_upload 2026-01-10 15:12:00 -08:00
Ishaan Jaff c0cf8bc27d [Feat] Manus FILES API - Add File upload, get, delete, list (#18904)
* add MANUS get response

* init TwoStepFileUploadRequest

* init TwoStepFileUploadConfig

* add async_create_file to handle 2 step uploads

* init ManusFilesConfig

* add add get_provider_files_config MANUS

* fix validate_environment

* test_manus_files_api_e2e_all_methods

* aws fix base

* init files API MANUS

* test_manus_responses_api_with_file_upload

* mypy lint fixes

* fix BedrockFilesConfig

* manus docs

* docs manus

* mypy lint

* add add fix resposne api utils MANUS
2026-01-10 13:27:54 -08:00
Ishaan Jaff f19cce950c add MANUS get response (#18900) 2026-01-10 12:21:45 -08:00
Ishaan Jaffer 10ec499369 responses API fixes 2026-01-08 19:16:23 +05:30
Ishaan Jaffer ebf09218d5 TestManusResponsesAPITest 2026-01-08 18:59:46 +05:30
Ishaan Jaff b482d336b3 [Feat] New provider - Manus API on /responses, GET /responses (#18804)
* init ManusResponsesAPIConfig

* init MANUS ApI

* init MANUS create responses

* init MANUS

* test_extract_agent_profile

* transform_get_response_api_request

* test fix

* fixes non stream

* fix streaming

* add MANUSConfig

* test_multiturn_responses_api

* code QA check

* add manus

* Potential fix for code scanning alert no. 3961: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2026-01-08 18:37:42 +05:30
Ishaan Jaff 76eda472be [Feat] New API Endpoint - Responses API (v1/responses/compact) (#18697)
* init transform_compact_response_api_request

* init acompact_responses

* init async_compact_response_api_handler in llm http handler

* init transform_compact_response_api_request for openai

* init acompact_responses

* fix acompact_responses

* add OAI Compact API

* docs responses API Compact

* code qa checks

* test_openai_compact_responses_api

* fix mypy linting
2026-01-06 16:24:04 +05:30
LingXuanYin 499fc9f48a Align responses API streaming hooks with chat pipeline 2026-01-06 10:54:19 +08:00
Alexsander Hamir 5a76aada3c [Fix] CI/CD - responses_api_testing (#18295) 2025-12-20 10:27:58 -08:00
Alexsander Hamir 0c48826cdc Revert "[Fix] CI/CD - local_testing & mapped tests (#18222)" (#18223)
This reverts commit dc7f500c47.
2025-12-18 14:46:09 -08:00
Alexsander Hamir dc7f500c47 [Fix] CI/CD - local_testing & mapped tests (#18222) 2025-12-18 14:34:48 -08:00
Alexsander Hamir 5230e97448 [Fix] CI/CD - Add missing documentation for ENVs & Clean Functionality (#18211) 2025-12-18 13:16:15 -08:00
Sameer Kankute 85907cebb5 Add custom headers in responses API 2025-12-16 11:31:15 +05:30
Ishaan Jaffer 50328d15d4 test_process_chunk_with_response_completed_event 2025-11-26 11:52:05 -08:00
Sameer Kankute 82dc0354ce Litellm sameer nov 3 stable branch (#16963)
* Add openai metadata filed in the request

* Add docs related to openai metadata

* Add utils

* test_completion_openai_metadata[True]

* Added support for though signature for gemini 3 in responses api (#16872)

* Added support for though signature for gemini 3

* Update docs with all supported endpoints and cost tracking

* Added config based routing support for batches and files

* fix lint errors

* Litellm anthropic image url support (#16868)

* Add image as url support to anthropic

* fix mypy errors

* fix tests

* Fix: Populate spend_logs_metadata in batch and files endpoints (#16921)

* Add spend-logs-metadata to the metadata

* Add tests for spend logs metadata in batches

* use better names

* Remove support for penalty param for gemini 3 (#16907)

* Remove support for penalty param

* remove halucinated model names

* fix mypy/test errors

* fix tests

* fix too many lines error

* fix too many lines error

* Add config for cicd test case

* Fix final tests

* fix batch tests

* fix batch tests
2025-11-22 09:35:05 -08:00