Commit Graph
39 Commits
Author SHA1 Message Date
Chesars cb15296693 fix(azure): auto-route gpt-5.4+ tools+reasoning to Responses API
Azure GPT-5.4+ models now get the same auto-routing treatment as OpenAI
when both `reasoning_effort` and `tools` are used in `litellm.completion()`.
Previously, `reasoning_effort` was silently dropped for Azure; now the
request is bridged to the Responses API which supports both parameters.

Fixes #23914
2026-03-17 23:06:39 -03:00
Sameer Kankute 30645d683f Reserve reasoning for responses via chat completion 2026-03-13 23:59:57 +05:30
Sameer Kankute 7abbe2dc06 Fix routing of tool call + reasoning effor for gpt-5.4 2026-03-13 23:59:53 +05:30
yuneng-jiangandGitHub 2b71b0fb25 Revert "QA: improve gpt-5.4 code/bugs" 2026-03-13 10:15:47 -07:00
Sameer Kankute 9b3ffd04ef Reserve reasoning for responses via chat completion 2026-03-13 14:19:40 +05:30
Sameer Kankute 288b08fd25 Fix routing of tool call + reasoning effor for gpt-5.4 2026-03-13 14:19:04 +05:30
Giulio Leone 556c64875e fix(models): set gpt-5.4-pro mode to responses instead of chat
gpt-5.4-pro and gpt-5.4-pro-2026-03-05 do not support the
/v1/chat/completions endpoint — OpenAI returns a 404 with
"This is not a chat model". These models are responses-only,
like o3-pro and o1-pro.

Changes:
- Set mode from "chat" to "responses" for both model entries
- Update supported_endpoints to ["/v1/responses", "/v1/batch"]
- Add regression test for responses API bridge routing

Fixes BerriAI/litellm#23014
2026-03-09 12:10:08 +01:00
Sameer Kankute 7a35116148 Fix : test_video_content_handler_uses_get_for_openai 2026-02-17 20:06:08 +05:30
Julio Quinteros ProandClaude Sonnet 4.5 d8dbb7f5ab refactor(test): remove redundant cache flush from test_openai_env_base
The manual cache flush is redundant since the autouse fixture
clear_client_cache (lines 21-32) already flushes the cache before
and after every test in this module.

The manual flush was added in Jan 2026 before the autouse fixture
existed. Now that the fixture handles it, the manual flush is unnecessary.

Related: greptile review comment on PR #21255

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 14:24:38 -03:00
jquinterGitHubgreptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
a4deaaa7ac Update tests/test_litellm/test_main.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-15 13:34:32 -03:00
Julio Quinteros ProandClaude Sonnet 4.5 a2a3d14443 fix(test): add cleanup for disable_aiohttp_transport in test_extra_body_with_fallback
Fixes test isolation issue where test_extra_body_with_fallback was setting
litellm.disable_aiohttp_transport = True but never resetting it, causing
state pollution that affected other tests.

Changes:
- Save original value of disable_aiohttp_transport before modifying
- Wrap test logic in try/finally block
- Restore original value in finally to ensure cleanup even on failure

Root Cause:
The test was modifying global litellm state without cleanup. When run in
certain orders with other tests:
- If this test ran first, it left disable_aiohttp_transport=True globally
- If other tests ran first, their state could interfere with this test
- Result: "All fallback attempts failed" error in CI

Impact:
Test passes in isolation but fails when run with other tests, especially
in parallel execution or CI environments.

Fixes: Test isolation for test_extra_body_with_fallback

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 13:31:30 -03:00
0c006794f1 litellm_fix_mapped_tests_core: fix test isolation and mock injection issues (#20209)
* litellm_fix_mapped_tests_core: fix test isolation and mock injection issues

## Problem
Four tests in litellm_mapped_tests_core were failing:
1. test_register_model_with_scientific_notation - KeyError due to test isolation issues
2. test_search_uses_registry_credentials - Mock not being called due to incorrect patch path
3. test_send_email_missing_api_key - Real API calls despite mocking
4. test_stream_transformation_error_sync - Mock not effective, real API called

## Solution

### test_register_model_with_scientific_notation
- Use unique model name to avoid conflicts with other tests
- Clear LRU caches before test to prevent stale data
- Clean up model_cost entry after test

### test_search_uses_registry_credentials
- Use patch.object() on the actual base_llm_http_handler instance
- String-based patching for instance methods can fail; direct object patching is more reliable

### test_send_email_missing_api_key
- Directly inject mock HTTP client into logger instance
- This bypasses any caching issues that could cause the fixture mock to be ineffective

### test_stream_transformation_error_sync
- Patch litellm.completion directly instead of the handler module's litellm reference
- This ensures the mock is effective regardless of import order

## Regression
These tests were affected by LRU caching added in #19606 and HTTP client caching.

* fix(test): use patch.object for container API tests to fix mock injection

## Problem
test_retrieve_container_basic tests were failing because mocks weren't
being applied correctly. The tests used string-based patching:
  patch('litellm.containers.main.base_llm_http_handler')

But base_llm_http_handler is imported at module level, so the mock wasn't
intercepting the actual handler calls, resulting in real HTTP requests
to OpenAI API.

## Solution
Use patch.object() to directly mock methods on the imported handler
instance. Import base_llm_http_handler in the test file and patch like:
  patch.object(base_llm_http_handler, 'container_retrieve_handler', ...)

This ensures the mock is applied to the actual object being used,
regardless of import order or caching.

* fix(test): add missing Prometheus metric labels to test_proxy_failure_metrics

Add client_ip, user_agent, model_id labels to expected metric patterns.
These labels were added in PRs #19717 and #19678 but test wasn't updated.

* fix(test_resend_email): use direct mock injection for all email tests

Extend the mock injection pattern used in test_send_email_missing_api_key
to all other tests in the file:
- test_send_email_success
- test_send_email_multiple_recipients

Instead of relying on fixture-based patching and respx mocks which can
fail due to import order and caching issues, directly inject the mock
HTTP client into the logger instance. This ensures mocks are always used
regardless of test execution order.

* fix(test): use patch.object for image_edit and vector_store tests

- test_image_edit_merges_headers_and_extra_headers: import base_llm_http_handler
  and use patch.object instead of string path patching
- test_search_uses_registry_credentials: import module and patch via
  module.base_llm_http_handler to ensure we patch the right instance

---------

Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
2026-01-31 17:53:54 -08:00
37a45a3295 litellm_fix_mapped_tests_core: clear client cache and fix isinstance checks (#20196)
## Problem
Tests using mocked HTTP clients were hitting real APIs because:
1. HTTP client cache was returning previously cached real clients
2. isinstance checks failed due to module identity issues from sys.path

### Tests affected:
- test_send_email_missing_api_key
- test_send_email_multiple_recipients (resend & sendgrid)
- test_search_uses_registry_credentials
- test_vector_store_create_with_simple_provider_name
- test_vector_store_create_with_provider_api_type
- test_vector_store_create_with_ragflow_provider
- test_image_edit_merges_headers_and_extra_headers
- test_retrieve_container_basic (container API tests)

## Solution
1. Add clear_client_cache fixture (autouse=True) to clear
   litellm.in_memory_llm_clients_cache before each test
2. Fix isinstance checks to use type name comparison
   (avoids module identity issues from sys.path.insert)

## Why not disable_aiohttp_transport
The default transport is aiohttp, so tests should work with it.
Clearing the cache ensures mocks are used instead of cached real clients.

## Regression
PR #19829 (commit f95572e3ed) added @respx.mock but cached clients
from earlier tests were being reused, bypassing the mocks.

Co-authored-by: shin-bot-litellm <shin-bot-litellm@users.noreply.github.com>
2026-01-31 15:42:17 -08:00
Alexsander HamirandGitHub f2c3a01a57 fix: make HTTPHandler mockable in OIDC secret manager tests (#19803)
* fix: make HTTPHandler mockable in OIDC secret manager tests

- Add _get_oidc_http_handler() factory function to make HTTPHandler
  easily mockable in tests
- Update test_oidc_github_success to patch factory function instead
  of HTTPHandler directly
- Update Google OIDC tests for consistency
- Fixes test_oidc_github_success failure where mock was bypassed

This change allows tests to properly mock HTTPHandler instances used
for OIDC token requests, fixing the test failure where the mock was
not being used.

* fix: patch base_llm_http_handler method directly in container tests

- Use patch.object to patch container_create_handler method directly
  on the base_llm_http_handler instance instead of patching the module
- Fixes test_provider_support[openai] failure where mock wasn't applied
- Also fixes test_error_handling_integration with same approach

The issue was that patching 'litellm.containers.main.base_llm_http_handler'
didn't work because the module imports it with 'from litellm.main import',
creating a local reference. Using patch.object patches the method on the
actual object instance, which works regardless of import style.

* fix: resolve flaky test_openai_env_base by clearing cache

- Add cache clearing at start of test_openai_env_base to prevent cache pollution
- Ensures no cached clients from previous tests interfere with respx mocks
- Fixes intermittent failures where aiohttp transport was used instead of httpx
- Test-only change with low risk, no production code modifications

Resolves flaky test marked with @pytest.mark.flaky(retries=3, delay=1)
Both parametrized versions (OPENAI_API_BASE and OPENAI_BASE_URL) now pass consistently

* test: add explicit mock verification in test_provider_support

- Capture mock handler with 'as mock_handler' for explicit validation
- Add assert_called_once() to verify mock was actually used
- Ensures test verifies no real API calls are made
- Follows same pattern as test_openai_env_base validation
2026-01-26 11:00:42 -08:00
Ishaan Jaffer d8e0c43a21 test fixes 2026-01-24 14:08:48 -08:00
Ishaan Jaffer a62ccd582d fix flaky tests 2026-01-24 13:04:20 -08:00
Ishaan Jaffer bd38374a45 fix: FLAKY tests 2026-01-24 11:13:44 -08:00
Cesar GarciaandGitHub 6d831ffff4 fix(ocr): add missing ocr and aocr to CallTypes enum (#17435)
Add `ocr` and `aocr` entries to the CallTypes enum to fix the
ValueError that occurs when using the /v1/ocr endpoint with
guardrails enabled.

The OCR endpoint uses route_type="aocr", but the CallTypes enum
was missing these values, causing guardrail hooks to fail when
trying to instantiate CallTypes("aocr").

Fixes #17381
2025-12-03 21:28:13 -08:00
Sameer Kankute cf6dda5e29 block input_examples in fucntion definition for non anthropic providers 2025-11-27 22:46:28 +05:30
Ishaan Jaffer 5c289df374 test url with format 2025-11-22 10:10:08 -08:00
Ishaan Jaffer badbadba0d fix img URL for tests 2025-11-22 09:41:15 -08:00
Sameer KankuteandGitHub 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
Krrish Dholakia b90e916c68 build: squash merge litellm_dev_10_10_2025_p1 2025-10-25 12:21:12 -07:00
Byron GroganandGitHub bf47c25de0 [fix] Pass user-defined headers and extra_headers to image-edit calls (#15811) 2025-10-23 15:08:10 -07:00
Ishaan Jaffer 426c6fea9f Revert "Merge pull request #14761 from uzaxirr/feat/sdk-additional-headers"
This reverts commit 8628c265b9, reversing
changes made to be193fbffd.
2025-09-23 13:59:54 -07:00
uzaxirr 50d717cde0 Apply Black formatting and fix Ruff issues
- Format code with Black to meet style requirements
- Fix auto-fixable Ruff linting issues
- Maintain header implementation functionality
2025-09-22 04:46:08 +05:30
uzaxirr 3986b073c9 feat: Add SDK support for additional headers 2025-09-21 14:58:14 +05:30
0x5751 8dd04c4eee fix: test error 2025-08-26 01:58:04 +08:00
0x5751 d6cd50dfdb feat: Add support for custom Anthropic-compatible API endpoints
This commit adds support for custom Anthropic-compatible API endpoints
that don't follow the standard /v1/messages or /v1/complete path convention.

## Changes
- Added LITELLM_ANTHROPIC_DISABLE_URL_SUFFIX environment variable
- When set to true, prevents automatic appending of /v1/messages (for anthropic)
- When set to true, prevents automatic appending of /v1/complete (for anthropic_text)
- Added debug logging to indicate when suffix is being skipped
- Maintained full backward compatibility - existing deployments are unaffected
2025-08-26 01:22:51 +08:00
Krish DholakiaandGitHub 8cd6c25e1e Fix async retryer on .acompletion() + forward clientside headers - filter out content-type from clientside request (causes llm api call to hang) (#12886)
* fix(main.py): fix async retryer

Fixes https://github.com/BerriAI/litellm/issues/12830

* fix(forward_clientside_headers_by_model_group.py): filter out 'content-type' from forwardable headers

clientside content-type != proxy content type, can cause requests to hang
2025-07-22 19:50:05 -07:00
Ishaan Jaff bf300f8ca7 Revert "Litellm dev 07 21 2025 p1 (#12848)"
This reverts commit e4e10aa4ed.
2025-07-22 18:28:36 -07:00
Krish DholakiaandGitHub e4e10aa4ed Litellm dev 07 21 2025 p1 (#12848)
* fix(main.py): fix async retryer

Fixes https://github.com/BerriAI/litellm/issues/12830

* fix(forward_clientside_headers_by_model_group.py): filter out 'content-type' from forwardable headers

clientside content-type != proxy content type, can cause requests to hang

* test(tests/): update tests
2025-07-21 22:09:39 -07:00
Krish DholakiaandGitHub 76c9df1f91 Add 'thinking blocks' to stream chunk builder + remove experimental 'by_tag' metrics on prometheus (fix cardinality issue) (#12395)
* feat(stream_chunk_builder_utils.py): combine thinking blocks in stream chunk builder

* fix(prometheus.py): remove experimental 'by_tag' metrics

Fixes LIT-225
2025-07-07 21:41:44 -07:00
Krish DholakiaandGitHub f755b70528 fix(factory.py): support optional args for bedrock (#12287)
* fix(factory.py): support optional args for bedrock

Closes https://github.com/BerriAI/litellm/pull/12276

* test(main.py): Support async await on mock_delay

Closes https://github.com/BerriAI/litellm/issues/12282
2025-07-03 21:15:10 -07:00
Krish DholakiaandGitHub df49b24bc0 Azure - responses api bridge - respect responses/ + Gemini - generate content bridge - handle kwargs + litellm params containing stream (#12224)
* fix(main.py): handle router custom azure model name for responses api bridge

* fix(responses/handler): ensure azure model name is stripped before sending to provider

Fixes model name error

* fix(google_genai/main.py): handle stream=true being set in kwargs

* docs: cleanup icons from sidebar

* fix(test-litellm.yml): add google-genai to test litellmyml

* fix(main.py): strip 'responses/' from bridge

* fix(main.py): fix linting errors

* fix(types/openai.py): allow item to be none

handle azure streaming response

* fix(base.py): allow extra fields + handle azure item = none value in response output item added event

* fix(main.py): correctly handle removing responses/

* test(test_main.py): add unit tests
2025-07-02 13:53:52 -07:00
ZaydandGitHub 7ef590df84 Passes through extra_ properties on "custom" llm provider (#12185)
* Passes through headers on "custom" llm provider

* add test

* adds extra_body support for custom llm providers
2025-07-01 18:07:38 -07:00
Ishaan Jaff 6863073aa4 fix: tests 2025-05-31 13:14:37 -07:00
Ishaan Jaff 7d47417906 test: fixes 2025-05-31 12:42:56 -07:00
Krish DholakiaandGitHub ef42461c1e Litellm fix GitHub action testing (#11163)
* test: add __init__.py files

* refactor: rename test folder to avoid naming conflict

* test: update workflows

* test: update tests

* test: update imports

* test: update tests

* test: remove unused import

* ci(test-litellm.yml): add pytest retry to github workflow

* test: fix test
2025-05-26 14:41:42 -07:00