Commit graph

33624 commits

Author SHA1 Message Date
yuneng-jiang
a1eadb4406 optimize key_aliases to select only key_alias column and add unit tests
Add select={"key_alias": True} to the find_many call so only the alias
column is fetched from the database instead of full token rows. Add
five unit tests in test_key_management_endpoints.py covering response
shape, pagination skip/take computation, search filter injection,
absence of contains filter when no search term is given, and the
select-only-alias optimization.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-03 18:15:51 +05:30
yuneng-jiang
8696c33d7b [Fix] /key/aliases: Add pagination and search to prevent OOMs
The /key/aliases endpoint previously fetched all key aliases from the database without limit, causing OOM crashes with large key sets. Added page, size, and search query parameters with database-level filtering to enable paginated and searchable key alias retrieval. Updated the response to include pagination metadata (total_count, current_page, total_pages, size) matching the /v2/model/info pattern.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-03 18:15:51 +05:30
Harshit28j
d883d01de0 fix: req changes 2026-03-03 18:15:51 +05:30
Harshit28j
38c88d1022 fix: custom auth budget issue 2026-03-03 18:15:51 +05:30
michelligabriele
b46af6de3e test(mcp): add e2e test for stateless StreamableHTTP behavior (#22033)
Adds TestProxyMcpStatelessBehavior to test_proxy_mcp_e2e.py with a test
that verifies two independent MCP clients can connect, initialize, and
call tools without sharing session state. This catches the regression
from PR #19809 where stateless=False broke clients that don't manage
mcp-session-id headers.

Regression test for #20242
2026-03-03 18:15:51 +05:30
michelligabriele
0fcae5b210 fix(websearch_interception): preserve thinking blocks in agentic loop follow-up messages
When extended thinking is enabled, the websearch interception agentic loop
builds a follow-up assistant message with only tool_use blocks. Anthropic's
API requires assistant messages to start with thinking/redacted_thinking
blocks when thinking is enabled, causing a 400 Bad Request.

Extract thinking blocks from the model's initial response, thread them
through the agentic loop, and prepend them to the follow-up assistant
message — matching the pattern used by anthropic_messages_pt in factory.py.

Fixes the error: "Expected 'thinking' or 'redacted_thinking', but found
'tool_use'"
2026-03-03 18:15:51 +05:30
Julio Quinteros Pro
13ee2e2bc4 fix(tests): update MCP server test mocks to match production API
The tests were mocking `filter_server_ids_by_ip` but the production
code in server.py now calls `filter_server_ids_by_ip_with_info` which
returns a (server_ids, blocked_count) tuple. Update all 8 mock sites
to use the correct method name and return signature.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 18:15:51 +05:30
Sameer Kankute
d6d81854f2 Fix based on review 2026-03-03 18:15:50 +05:30
Sameer Kankute
10de52a807 Fix: Passing of image and parameters in videos api 2026-03-03 18:15:50 +05:30
Sameer Kankute
f38295fd02 Add audio as supported openai param 2026-03-03 18:15:50 +05:30
Sameer Kankute
63b922de4b Add JSON exact match test for vLLM embeddings 2026-03-03 18:15:50 +05:30
Sameer Kankute
2225247447 Remove logger 2026-03-03 18:15:50 +05:30
Sameer Kankute
b0def4f18d fix(embeddings): allow dimensions param passthrough via allowed_openai_params for non-text-embedding-3 OpenAI models
When calling non-text-embedding-3 models routed through the openai provider
(e.g. nvidia/llama-3.2-nv-embedqa-1b-v2), passing `dimensions` previously
raised an UnsupportedParamsError unconditionally. This fix threads
`allowed_openai_params` through the embedding call stack so that providers
can opt-in to passing `dimensions` by including it in the list.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 18:15:50 +05:30
Sameer Kankute
c78013e020 Return Clear error message why no tools are available / IP Filtering occured 2026-03-03 18:15:50 +05:30
Sameer Kankute
833fd870db Revert "fix(proxy): improve auth exception logging levels and add structured …"
This reverts commit efeaf650aa.
2026-03-03 18:15:50 +05:30
Sameer Kankute
2c28725a66 Bump litellm version to 1.81.16 2026-03-03 18:15:50 +05:30
mubashir1osmani
cb6708c052 fix(test): update Phoenix OTEL test for dedicated TracerProvider architecture
The old test assumed ArizePhoenixLogger reused the global TracerProvider.
With the nested traces fix, Phoenix now creates its own dedicated provider
and produces litellm_proxy_request + litellm_request + raw_gen_ai_request
spans independently.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-03 18:15:50 +05:30
mubashir1osmani
dfdf651099 fix(arize-phoenix): enable nested traces coexistence with otel callback
- ArizePhoenixLogger now creates spans on its own dedicated TracerProvider
  instead of trying to reuse parent spans from the global otel TracerProvider
  (which were invisible in Phoenix since they go to a different exporter)
- Auto-initialize ArizePhoenixLogger when otel callback is configured and
  Phoenix env vars (PHOENIX_API_KEY, PHOENIX_COLLECTOR_*) are detected
- Use exact type check in get_custom_logger_compatible_class to prevent
  ArizePhoenixLogger (subclass) from being returned when looking up otel
- Fix tool_permission guardrail to check non-function tools like
  code_interpreter (previously skipped with `type != "function"`)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-03 18:15:50 +05:30
Jins K Joy
bb962a609b Adjust input and output cost per token for mistral-small-2503 (#22097)
* Adjust input and output cost per token for mistral-small-2503

Cost per million for mistral-small-2503 is not correct.

In Azure Documentation:
Pay-as-you-go (per 1,000 tokens)
$0.0001
Model input
$0.0003
Model output

* Update input and output cost per token for model
2026-03-03 18:15:50 +05:30
Sameer Kankute
8bb4b00daa Fix code qa for agent_id 2026-03-03 18:15:50 +05:30
Sameer Kankute
a1be8177ed Fix code qa 2026-03-03 18:15:50 +05:30
Sameer Kankute
708b241297 Fix test_vertex_passthrough_forwards_anthropic_beta_header 2026-03-03 18:15:50 +05:30
Sameer Kankute
84b908413f Fix gaurdrail code qa 2026-03-03 18:15:50 +05:30
Sameer Kankute
eb7a6040c1 Fix pass through tests 2026-03-03 18:15:50 +05:30
Sameer Kankute
34460655d7 Fix code qa 2026-03-03 18:15:50 +05:30
Sameer Kankute
2fec2907b7 Fix_mapped tests part 2 2026-03-03 18:15:50 +05:30
Sameer Kankute
393b5715b2 FIx : litellm/tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py 2026-03-03 18:15:50 +05:30
Sameer Kankute
113af3f334 Fix code qa 2026-03-03 18:15:50 +05:30
Sameer Kankute
b09bfbfd85 Fix : enterprise tests 2026-03-03 18:15:50 +05:30
Sameer Kankute
24424abec8 Fix test_standard_logging_payload_includes_guardrail_information 2026-03-03 18:15:50 +05:30
Sameer Kankute
57d0ea2ae9 Fix: test_gaurdrails* 2026-03-03 18:15:50 +05:30
Sameer Kankute
f435a0fbd7 Fix: litellm/tests/test_litellm/proxy/common_utils/test_http_parsing_utils.py 2026-03-03 18:15:50 +05:30
Sameer Kankute
3b7055a6b1 Fix code qa 2026-03-03 18:15:50 +05:30
Sameer Kankute
06a65e9c44 FIx test_read_request* 2026-03-03 18:15:50 +05:30
Sameer Kankute
fa6f30bdbc Fix test_pass_through_request_logging_failure 2026-03-03 18:15:50 +05:30
Sameer Kankute
ade9603a63 Fix: test_sentence[te_6] 2026-03-03 18:15:49 +05:30
Sameer Kankute
d6e95a613e Fix test_async_gcs_pub_sub_v1 2026-03-03 18:15:42 +05:30
Sameer Kankute
722d041b17 Fix UI build 2026-03-03 18:15:41 +05:30
Sameer Kankute
8dd1888497 Fix code qa for _types.py 2026-03-03 18:15:37 +05:30
Sameer Kankute
04dcb20f03 Fix test_perform_health_check_filters_by_model_id 2026-03-03 18:15:37 +05:30
Sameer Kankute
5ed564aeca Fix mypy issues 2026-03-03 18:15:35 +05:30
Ishaan Jaff
61e2fdf463 feat(realtime guardrails): end_session_after_n_fails + Endpoint Settings wizard step (#22165)
* feat(realtime guardrails): end_session_after_n_fails + Endpoint Settings wizard step

Adds per-session violation thresholds and an optional endpoint-settings step
to the guardrail wizard for /v1/realtime.

Backend:
- Add end_session_after_n_fails, on_violation, realtime_violation_message fields
  to BaseLitellmParams (no DB migration — stored in existing JSON column)
- Store same fields on CustomGuardrail instance attrs
- Pass through in litellm_content_filter initializer
- Track _violation_count per RealTimeStreaming session; close backend_ws when
  on_violation=end_session OR violation count >= end_session_after_n_fails
- Use realtime_violation_message as the spoken text (falls back to guardrail
  error string if not configured)

UI (add_guardrail_form.tsx):
- Rename "Default Categories" step to "Topics"
- Add step 5 "Endpoint Settings (Optional)" for content filter guardrails
- Call type dropdown shows /v1/realtime
- Settings are in a collapsed accordion (closed by default)
- "End session after X violations" + on_violation radio + spoken message field

Tests: 2 new tests in test_realtime_streaming.py
- test_end_session_after_n_fails_closes_connection
- test_on_violation_end_session_closes_on_first_fail

* fix(test): move inline imports to module level in realtime streaming tests

* Update ui/litellm-dashboard/src/components/guardrails/add_guardrail_form.tsx

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

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-03-03 18:15:28 +05:30
Ishaan Jaff
587ad3ccb1 fix(realtime): guardrails with pre_call/post_call mode now work on realtime WebSocket (#22161)
* fix(realtime): guardrails with pre_call/post_call mode now work on realtime WebSocket; return error directly to consumer

* fix(realtime guardrails): address code review feedback

- Restore session.update injection for audio/VAD path, but only when
  realtime_input_transcription guardrails are configured (not pre_call).
  Forward session.created to the client first so no error arrives before
  the client sees the session.
- Change _swallow_next_response_create bool to int counter so consecutive
  blocked items are handled correctly.
- Extract _build_litellm_metadata() helper to eliminate duplicated
  metadata-building logic across OpenAI/Azure/XAI provider branches.
- Plumb litellm_metadata and user_api_key_dict to Azure and XAI handlers
  so guardrails work for those providers too.
- Add tests for session.update injection, no-inject for pre_call-only,
  and consecutive-block counter.

* simplify: remove response.create swallowing after guardrail block

When an item is blocked, the error event is already sent to the client.
The subsequent response.create from the client is fine to forward through —
the LLM may respond to previous context which is acceptable behavior.
Removing the swallow counter eliminates unnecessary state tracking.
2026-03-03 18:15:28 +05:30
Ishaan Jaff
1ed4023700 Development environment setup (#22160)
* feat: add pretty view for realtime API logs in dashboard

- Create RealtimePrettyView component that renders structured session
  config, conversation turns with transcripts, and token breakdowns
- Update PrettyMessagesView to detect realtime responses (via
  isRealtimeResponse helper) and delegate to the new component
- Session card shows model, voice, modalities, temperature, instructions
  in a collapsible panel
- Conversation turns show status, per-turn token usage, and audio/text
  transcripts with appropriate icons
- Add 24 tests for RealtimePrettyView and 3 tests for PrettyMessagesView
- All 75 LogDetailsDrawer tests pass

Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>

* chore: remove dev_config.yaml from tracked files

Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>

* feat: show turn count in realtime pretty view session header and output header

- Add purple 'N turns' tag to Session card header for at-a-glance turn count
- Add 'Turns: N' to the Output section header next to tokens/cost
- Extend SectionHeader to accept optional turnCount prop
- Add 3 new tests for turn count display (singular, plural, output header)

Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>

* fix: address Greptile review feedback

- Remove response.audio.done and conversation.item.created from
  isRealtimeResponse() detection since the view doesn't render them;
  prevents misleading fallback for responses with only those events
- Remove dead code: index >= 0 is always true in .map() callback

Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>
2026-03-03 18:15:28 +05:30
Roni Frantchi
d82262224b fix(adapter): populate cache_read_input_tokens from prompt_tokens_details for OpenAI/Azure (#22090)
* fix(adapter): populate cache_read_input_tokens from prompt_tokens_details

The Anthropic adapter's translate_openai_response_to_anthropic checked
only the private _cache_read_input_tokens attr (set by Anthropic/DeepSeek)
but not prompt_tokens_details.cached_tokens (set by OpenAI/Azure).

Use prompt_tokens_details.cached_tokens directly — it is already extracted
and is the standard field populated by all providers.

Fixes #22089

* fix(adapter): apply same cache_read_input_tokens fix to streaming path

The streaming path in translate_streaming_openai_response_to_anthropic
had the same bug — relying on _cache_read_input_tokens instead of
prompt_tokens_details.cached_tokens.
2026-03-03 18:15:28 +05:30
Benedikt Óskarsson
d3b28ff9c9 fix(proxy): improve auth exception logging levels and add structured context (#22099)
* fix(proxy): improve auth exception logging levels and add structured context

Downgrade expected auth failures (ProxyException, HTTPException < 500,
BudgetExceededError) from ERROR to WARNING log level to reduce noise from
routine rejected requests (e.g. missing/invalid API keys on polled endpoints
like /schedule/model_cost_map_reload/status).

Unexpected exceptions and HTTPException with status >= 500 still log at
ERROR with full traceback.

Enrich log messages with structured context: route, HTTP method, masked
API key (using existing abbreviate_api_key), error type, and error code.
All fields also passed via log extra dict for log aggregation tools.

Fixes #21293

* Update tests/test_litellm/proxy/auth/test_auth_exception_handler.py

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

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-03-03 18:15:28 +05:30
Gaurav Singh
c935a816bf fix(proxy): honor MAX_STRING_LENGTH_PROMPT_IN_DB from config env vars (#22106)
* fix(proxy): honor MAX_STRING_LENGTH_PROMPT_IN_DB from config env vars

* fix(proxy): reuse constants fallback for MAX_STRING_LENGTH_PROMPT_IN_DB runtime resolver

* test(proxy): restore PEP8 spacing between spend tracking tests
2026-03-03 18:15:28 +05:30
yuneng-jiang
cababa6cc2 fixing ui build 2026-03-03 18:15:28 +05:30
Ishaan Jaff
eb8b74a14e feat(vertex_ai): Vertex AI Gemini Live via unified /realtime endpoint (#22153)
* feat(vertex_ai): add Vertex AI Gemini Live support via unified /realtime endpoint

Adds VertexAIRealtimeConfig which translates the OpenAI Realtime WebSocket
protocol to Vertex AI BidiGenerateContent. Supports voice in/voice out
(16 kHz mic → 24 kHz speaker) and text in/text out through the proxy's
/realtime endpoint.

Key changes:
- New litellm/llms/vertex_ai/realtime/transformation.py with VertexAIRealtimeConfig
  - Builds correct wss:// URL (regional + global)
  - OAuth2 Bearer token auth (not API key)
  - Full model path (projects/.../publishers/google/models/...)
  - Ignores session.update (Vertex AI only accepts one setup message)
- realtime_api/main.py: vertex_ai branch resolves OAuth token + constructs config
- llm_http_handler.py: auto-sends session setup before bidirectional_forward
- gemini/realtime/transformation.py: fix crashes on empty turnComplete events
- realtime_streaming.py: try/except guard so bad messages don't kill the loop
- proxy_server.py: add missing websockets.exceptions import

* docs: add vertex_realtime to sidebars

* fix: drop unknown event types in Gemini transform; add vertex_ai health check

* fix: propagate UUID fallback IDs from transform_content_done_event to return_additional_content_done_events

* fix: route guardrail backend sends through provider transform; fix str.strip misuse for model prefix

* fix: handle Vertex AI full resource path in session.created; route guardrail block sends through _send_to_backend

* fix: remove unused VertexBase in transformation.py; apply UUID fallback in return_additional_content_done_events
2026-03-03 18:15:28 +05:30
Krish Dholakia
6100380568 feat(add-new-block_code_execution-guardrail): prevent agent from executing code (#22154)
Adds a new block_code_execution guardrail that detects markdown fenced code blocks
in request/response content and blocks or masks them by language. Includes full
UI integration, type definitions, compliance test dataset, and 26 unit tests.

Key guardrail capabilities:
- Regex-based fenced code block detection with configurable blocked languages
- Confidence scoring with tunable threshold
- Execution-intent heuristics (request-side only) with conflict resolution
- Block or mask actions for detected code
- Support for pre_call, post_call, and during_call event hooks

Security hardening:
- Response-side blocking skips intent heuristics (LLM output doesn't contain
  user intent phrases, so checking would silently disable post_call blocking)
- No-execution short-circuit includes conflict resolution: if both no-execution
  and execution phrases match, execution intent wins
- Tightened overly broad phrases to prevent trivial bypass
- _normalize_escaped_newlines only applies to pure-escaped payloads to avoid
  corrupting content that discusses escape sequences

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 18:15:28 +05:30