Commit graph

7998 commits

Author SHA1 Message Date
Sameer Kankute
d333dc4077 address greptile review feedback (greploop iteration 1)
- Fix async path: call async_get_chat_completion_prompt in aresponses()
  before executor dispatch, mirroring acompletion() in main.py. Discard
  merged_optional_params in async path (sync responses() handles them
  via local_vars), avoiding TypeError from duplicate kwargs in partial().
- Fix provider re-resolution: replace "/" in model heuristic with
  model != original_model comparison so bare model names are handled.
- Add 3 async tests covering hook invocation, optional param
  propagation, and non-message item filtering in aresponses().

Made-with: Cursor
2026-03-18 16:49:07 +05:30
Sameer Kankute
67f5ce9c7c address greptile review feedback (greploop iteration 1)
- Restore backward compat for leading assistant(tool_calls) — always prepend user_continue
- Replace partial assertions with full list assertion in trailing tool-call test

Made-with: Cursor
2026-03-18 16:41:26 +05:30
Sameer Kankute
b32f5ea379 Fix greptile comments 2026-03-18 16:37:52 +05:30
Sameer Kankute
0941e40363 fix(prompting): address greptile review - fix SyntaxError, restore backward compat, add trailing tool-call test
- Remove stray ): on line 303 (P0 SyntaxError)
- Restore backward-compatible trailing-assistant behavior (P1)
- Add test_ensure_alternating_roles_trailing_tool_call_assistant
- Keep role check alongside _counts_for_alternation (P2 is false positive)

Made-with: Cursor
2026-03-18 16:30:42 +05:30
Sameer Kankute
ae350ed370 Fix greptile comments 2026-03-18 16:10:33 +05:30
Sameer Kankute
f1421d1082 fix(prompting): preserve tool chains in alternation insertion
Avoid inserting assistant continue messages in the middle of assistant tool_call->tool chains by inserting before the next counted user turn, and add regression coverage for this edge case.

Made-with: Cursor
2026-03-18 15:55:51 +05:30
Sameer Kankute
0d70864d09 Add support for prompt management for responses 2026-03-18 15:48:31 +05:30
Sameer Kankute
3cdabff323 Fix greptile review 2026-03-18 15:45:09 +05:30
Sameer Kankute
b9266bb3b9 Fix ensure_alternating_roles for correct order 2026-03-18 15:25:57 +05:30
Cursor Agent
5e7645a99b
chore: remove unused imports (get_key_object, _cache_key_object)
These were only used in block_key/unblock_key for cache refresh,
which now uses _delete_cache_key_object instead.

Co-authored-by: yuneng-jiang <yuneng-jiang@users.noreply.github.com>
2026-03-18 08:47:44 +00:00
Cursor Agent
b428cfb4a4
test: add unit tests for block_key/unblock_key with non-existent keys
- test_block_key_nonexistent_key_returns_404: verifies block_key returns
  404 (not misleading 401) when the key doesn't exist in the DB
- test_unblock_key_nonexistent_key_returns_404: same for unblock_key
- test_block_key_existing_key_succeeds: verifies block_key succeeds and
  invalidates cache for existing keys
- Update test_unblock_key_supports_both_sk_and_hashed_tokens to reflect
  the new cache invalidation pattern (_delete_cache_key_object instead
  of get_key_object + _cache_key_object)

Co-authored-by: yuneng-jiang <yuneng-jiang@users.noreply.github.com>
2026-03-18 08:44:22 +00:00
Sameer Kankute
32ded9b2f8 fix double-billing issue 2026-03-18 12:47:42 +05:30
Sameer Kankute
7660f39fdb fix(file_search): promote DB helper, suppress sub-call billing, add queries-plural test
- Promote _fetch_managed_vector_stores_by_uuids from @staticmethod to a module-level
  async helper get_managed_vector_store_rows_by_uuids, following the same standalone
  helper pattern as get_team_object / get_key_object so the hot-path DB read is a
  named importable function rather than an inline prisma_client.db.* call
- Pass no-log=True to both inner _call_aresponses sub-calls so they do not fire
  independent billing/monitoring callbacks; cost is accumulated in the synthesized
  response's _hidden_params for the outer responses() call
- Add test_H11b covering the primary queries (plural array) function-tool schema,
  complementing H11 which exercises only the backward-compat singular query path

Made-with: Cursor
2026-03-18 11:38:49 +05:30
yuneng-jiang
b0990e2684 Revert "fix: prevent body 'key' field from overriding Authorization header in auth"
This reverts commit 2c874a7f3c.
2026-03-17 23:02:54 -07:00
yuneng-jiang
d2e77e74ee
Merge pull request #23938 from BerriAI/litellm_/sweet-austin
[Feature] /v2/team/list: Add org admin access control, members_count, and indexes
2026-03-17 23:01:41 -07:00
yuneng-jiang
2c874a7f3c fix: prevent body 'key' field from overriding Authorization header in auth
On /key/block, /key/unblock, and /key/update, the request body 'key'
field could contaminate the api_key Security dependency, causing the
auth layer to authenticate against the target key instead of the
caller's bearer token. This returned 401 for a nonexistent body key
even when the Authorization header contained a valid master key.

Added a guard in user_api_key_auth that re-reads the Authorization
header directly from the request, ensuring the header is always the
authoritative source for authentication.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 23:00:05 -07:00
Sameer Kankute
76176f2a64 fix(file_search): restore should_use_emulated helper, fix dedup, extract DB helper, clean docstring
- Re-add should_use_emulated_file_search() to emulated_handler.py so H5/H6/H7/H13 tests don't fail with ImportError
- Remove per-file-id deduplication from _build_search_results_for_include so all chunks are returned (matching OpenAI native file_search behaviour); update test_H14 to assert 2 results
- Extract raw prisma DB query in check_vector_store_ids_access into a static _fetch_managed_vector_stores_by_uuids helper so the hot request path uses a named, testable function instead of an inline prisma_client.db.* call
- Remove developer-local path from test module docstring

Made-with: Cursor
2026-03-18 11:26:27 +05:30
Sameer Kankute
694cf22c9e
Update tests/test_litellm/llms/vertex_ai/test_vertex_ai_batch_transformation.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-03-18 11:09:20 +05:30
Krish Dholakia
cec3e9e7d4
Merge pull request #23808 from voidborne-d/fix/shared-aiohttp-session-auto-recovery
fix: auto-recover shared aiohttp session when closed
2026-03-17 22:23:01 -07:00
Sameer Kankute
c4d27cb239 fix(vertex-ai): address greptile review – proxy retrieve URL, timeout forwarding, sync logging
- Fix retrieve_api_base derivation to handle custom proxies with
  path-based routing (not just :cancel suffix)
- Forward timeout to POST calls in cancel_batch (sync + async)
- Add try/except error logging to sync cancel path (parity with async)
- Add tests for timeout forwarding and custom proxy retrieve URL

Made-with: Cursor
2026-03-18 10:30:05 +05:30
yuneng-jiang
41a7747e8c fix: document org scope behavior, fix test mocks, add org admin tests
- Document intentional legacy-matching behavior: when user_id is
  provided to an org admin, no org filter is applied (returns all of
  that user's teams across all orgs, same as legacy endpoint)
- Fix two existing security tests to properly patch user_api_key_cache,
  proxy_logging_obj, and get_user_object instead of relying on
  incidental error handling
- Add three new org admin test cases:
  - Org admin sees org-scoped teams (200 with correct where clause)
  - Org admin rejected when filtering by other org (403)
  - Org admin with user_id filter returns target user's teams

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 21:56:57 -07:00
Sameer Kankute
ecb8c05d37 Add test for reasoning effort none 2026-03-18 10:24:21 +05:30
Sameer Kankute
e46dd949f2 Add test for reasoning effort none 2026-03-18 09:58:20 +05:30
yuneng-jiang
0485a1859a fix: use get_user_object helper, preserve caller org_id filter
- Replace raw find_unique with get_user_object in
  _build_team_list_where_conditions for cache/metrics consistency
- Remove over-complex OR clause for org admin + user_id: when user_id
  is provided, filter by that user's direct team memberships (same as
  regular users) since the access control gate already verified the
  org admin's authority
- Preserve caller-supplied organization_id instead of overwriting with
  org_admin_org_ids
- Update test mock to match get_user_object call path

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 21:19:42 -07:00
Sameer Kankute
d0d593beb8
Update tests/test_litellm/llms/vertex_ai/test_vertex_ai_batch_transformation.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-03-18 09:48:24 +05:30
Cesar Garcia
6a5b0058e3
Merge pull request #23926 from Chesars/fix/azure-gpt5-4-responses-api-routing
fix(azure): auto-route gpt-5.4+ tools+reasoning to Responses API
2026-03-18 01:14:50 -03:00
Sameer Kankute
74ae17d153 greptile comments 2026-03-18 09:41:46 +05:30
Sameer Kankute
5dd89f16f5 address greptile review: remove unused import, normalize model lookup, add xhigh tests
- Remove unused _get_model_info_helper import
- Normalize model via get_llm_provider in _is_reasoning_effort_level_explicitly_disabled
  so provider-prefixed names (openai/gpt-5.4-mini) resolve correctly
- Add test_gpt5_4_mini_allows_reasoning_effort_xhigh
- Add test_gpt5_4_nano_allows_reasoning_effort_xhigh
- Add test_gpt5_4_mini_provider_prefixed_rejects_minimal
- Extend test_gpt5_minimal_explicitly_disabled_check for openai/gpt-5.4-mini
2026-03-18 09:37:19 +05:30
Sameer Kankute
52bf372319 fix(gpt5): treat missing supports_minimal_reasoning_effort as supported
Add _is_reasoning_effort_level_explicitly_disabled to use opt-out semantics
for minimal effort: unknown/unlisted models pass through, only blocked when
the model map explicitly sets supports_minimal_reasoning_effort=false.

xhigh keeps opt-in semantics (must be explicitly supported).

Adds test for unknown-model passthrough and explicit-disabled detection.

Made-with: Cursor
2026-03-18 09:17:57 +05:30
Cesar Garcia
3c7e37799a
Merge pull request #23928 from Chesars/fix/gemini-context-caching-custom-api-base
fix(gemini): pass model to context caching URL builder for custom api_base
2026-03-18 00:43:16 -03:00
Sameer Kankute
018ccff23f fix(vertex-ai): address greptile review feedback on batch cancel
- Add try/except httpx.HTTPStatusError blocks in _async_cancel_batch for
  both POST cancel and GET retrieve calls, with verbose_logger error logging
- Fix endpoint extraction inconsistency: compute endpoint from URL without
  :cancel suffix so it matches behaviour of create_batch/retrieve_batch
- Add explicit validation that api_base ends with ':cancel' before
  stripping it, raising a descriptive error for unsupported custom proxy
  URL rewriting scenarios
- Use string-based patch() in test instead of patch.object() for robustness
  against import order changes

Made-with: Cursor
2026-03-18 09:11:20 +05:30
Sameer Kankute
6fe3188af0 fix(azure-ai-agents): accumulate annotations from multiple text items in streaming
- Fix bug where only last text item's annotations were preserved when
  thread.message.completed contained multiple text content items
- Accumulate annotations via extend() instead of overwriting
- Add test_azure_ai_agents_streaming_annotations_from_completed_message
- Add test_azure_ai_agents_streaming_accumulates_annotations_from_multiple_text_items

Addresses Greptile review on PR #23849

Made-with: Cursor
2026-03-18 09:04:00 +05:30
Cesar Garcia
f059ba55a9
Merge pull request #23925 from Chesars/fix/mistral-diarize-segments-response
fix(mistral): preserve diarization segments in transcription response
2026-03-18 00:32:53 -03:00
Cesar Garcia
a46b88c237
Merge pull request #23906 from Chesars/fix/anthropic-file-block-cache-control
fix(anthropic): preserve cache directive on file-type content blocks
2026-03-18 00:32:35 -03:00
Cesar Garcia
4947074aac
Merge pull request #23907 from Chesars/fix/vertex-count-tokens-location-override
fix(vertex): respect vertex_count_tokens_location for Claude count_tokens
2026-03-18 00:30:55 -03:00
Cesar Garcia
501ddb428c
Merge pull request #23618 from gambletan/fix/file-to-input-file-mapping
fix: map Chat Completion file type to Responses API input_file
2026-03-18 00:29:06 -03:00
Chesars
8828f002be fix(gemini): pass model to context caching URL builder for custom api_base
_get_token_and_url_context_caching() was hardcoding model=None when
calling _check_custom_proxy(), which raises ValueError when api_base
is set because Gemini proxy URLs need the model name:
{api_base}/models/{model}:cachedContents

Fixes #23846
2026-03-17 23:21:24 -03:00
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
Chesars
9afc469725 fix(mistral): preserve diarization segments in transcription response
Fixes #23890 — Mistral's Voxtral transcription with `diarize=true` returns
`segments` (with speaker_id, timestamps) and `language`, but these fields
were dropped when mapping the response to TranscriptionResponse.
2026-03-17 23:04:51 -03:00
Krish Dholakia
5e570b3a66
Merge pull request #23911 from kelvin-tran/fix/cache-control-params-anthropic-document-file-message-blocks 2026-03-17 18:00:05 -07:00
d 🔹
88f59e1465 fix: use AsyncMock for concurrent test consistency
Address review feedback from greptile — use new_callable=AsyncMock
on the concurrent test's patch.object to ensure the mock is properly
typed as async, even though side_effect already handles the coroutine.
2026-03-18 00:54:23 +00:00
Kelvin Tran
c6e9a2a40f
Merge branch 'main' into fix/cache-control-params-anthropic-document-file-message-blocks 2026-03-17 15:34:00 -07:00
Chesars
8f015e2db2 fix(vertex): respect vertex_count_tokens_location for Claude count_tokens
The count_tokens handler unconditionally overrode vertex_location to
us-central1 for Claude models, ignoring the user-configured
vertex_count_tokens_location parameter. Also, us-central1 is no longer
a supported region — Google now supports us-east5, europe-west1, and
asia-southeast1.

Now vertex_count_tokens_location takes precedence, vertex_location is
used as fallback, and us-east5 is the default only when neither is set.

Fixes #23872
2026-03-17 19:14:08 -03:00
Chesars
20f8d413e5 fix(anthropic): preserve cache_control on file-type content blocks
Fixes #23873
2026-03-17 19:10:19 -03:00
Cesar Garcia
1f5a67ab45
Merge pull request #23895 from Chesars/fix/streaming-tool-call-finish-reason-empty-content
fix(vertex): streaming finish_reason='stop' instead of 'tool_calls' for gemini-3.1-flash-lite-preview
2026-03-17 18:49:27 -03:00
Cesar Garcia
c1db67ab67
Merge pull request #23899 from Chesars/fix/map-anthropic-refusal-finish-reason
fix(core): map Anthropic 'refusal' finish reason to 'content_filter'
2026-03-17 18:49:03 -03:00
Rohan
bed44f5fe5
Add Akto Guardrails to LiteLLM (#23250)
* akto guardrails support in litellm

* docs(guardrails): add akto to supported values in types/guardrails.py

* frontend changes + fixes

* feat(akto): update Akto guardrail integration with new configuration options and modes

* docs(akto): enhance Akto documentation and configuration descriptions for clarity

* feat(tests): add proxy server request headers to sample request data

* refactor(akto): remove optional account and VXLAN IDs; update documentation and tests

* feat(akto): add event_type parameter for enhanced observability in guardrail logging

* refactor(akto): update environment variable references

* refactor the python codes

* refactor and fix linting

* refactor(akto): remove unused event hook and clean up imports

* refactor(akto): enhance AktoGuardrail with async support and improved logging

* fix: Register DynamoAI guardrail initializer and enum entry (#23752)

* fix: Register DynamoAI guardrail initializer and enum entry

Fix the "Unsupported guardrail: dynamoai" error by:
1. Adding DYNAMOAI to SupportedGuardrailIntegrations enum
2. Implementing initialize_guardrail() and registries in dynamoai/__init__.py

The DynamoAI guardrail was added in PR #15920 but never properly registered
in the initialization system. The __init__.py was missing the
guardrail_initializer_registry and guardrail_class_registry dictionaries
that the dynamic discovery mechanism looks for at module load time.

Fixes #22773

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* Update litellm/proxy/guardrails/guardrail_hooks/dynamoai/__init__.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Update litellm/proxy/guardrails/guardrail_hooks/dynamoai/__init__.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* test: Add tests for DynamoAI guardrail registration

Verifies enum entry, initializer registry, class registry,
instance creation, and global registry discovery.

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

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* docs: add v1.82.3 release notes and update provider_endpoints_support.json (#23816)

* Revert "docs: add v1.82.3 release notes and update provider_endpoints_support…" (#23817)

This reverts commit 966124966f.

* Refactor Akto guardrail configuration and tests; update UI description and tags

* add account and vxlan ID parameters to Akto guardrail initialization; update Akto logo format

* enhance Akto guardrail documentation and improve error handling for non-JSON responses

* address greptile issues

* fix: update payload handling to use 'data' instead of 'json' in AktoGuardrail and adjust tests accordingly

---------

Co-authored-by: Harshit Jain <48647625+Harshit28j@users.noreply.github.com>
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Joe Reyna <joseph.reyna@gmail.com>
Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
2026-03-17 14:38:04 -07:00
Kelvin Tran
d0c5f494a8 fix: cache_control directive dropped anthropic document/file blocks 2026-03-17 14:30:12 -07:00
Chesars
8b4a74a69c fix(core): map Anthropic 'refusal' finish reason to 'content_filter'
Anthropic's 'refusal' stop_reason was missing from _FINISH_REASON_MAP,
causing it to fall through to the default 'stop' — hiding the fact that
the model refused to respond due to safety policies.

Fixes #23793
2026-03-17 18:06:42 -03:00
Chesars
0c28b47057 fix(vertex): streaming finish_reason="stop" instead of "tool_calls" for gemini-3.1-flash-lite-preview
Models like gemini-3.1-flash-lite-preview send the final streaming chunk
with empty content (text:"") alongside finishReason:"STOP", instead of
omitting content entirely. The existing fix (PR #21577) only handled
chunks without content, so this case was missed.

Now, after processing candidates, if tool_calls were seen in earlier
chunks and a choice has finish_reason="stop", it is overridden to
"tool_calls" to match the OpenAI spec.

Fixes #22900
2026-03-17 17:47:01 -03:00