Commit Graph
33 Commits
Author SHA1 Message Date
michelligabrieleandGitHub f74cd07419 feat(proxy): add project-level guardrails support (#25087) 2026-04-03 20:20:44 -07:00
90eb6729d5 Agent Tracing - support context_id based trace id propogation + nested llm calls (#22626)
* style(ui/): distinguish agent calls from llm calls on ui

* feat: initial grouping working

* feat: set stable contextid for a2a calls - allows for easily passing to downstream llm/mcp calls

* feat(a2a_endpoints.py): fix tracing to avoid recreating logging objects for the same call

allows stable trace id usage

* fix(guardrail_endpoints): handle string ui_type values in _build_field_dict

_build_field_dict unconditionally called .value on ui_type, which crashes
for guardrail configs that use plain strings (e.g. BlockCodeExecutionGuardrailConfigModel
uses "multiselect" and "percentage"). Now checks with hasattr before calling .value.

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

* fix: propagate trace/session id from headers in MCP server calls

Cherry-picked mcp_server/server.py fixes from 6feb9bab: adds
get_chain_id_from_headers to extract x-litellm-trace-id /
x-litellm-session-id from raw headers, and uses it in call_tool
and list_tools to keep spend logs and tracing consistent with A2A.

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 18:19:12 -08:00
ryan-crabbeandGitHub 07def978cf Fix plaintext JWTs leaking in debug logs (#22424)
* Fix plaintext JWTs leaking in debug logs

Wrap raw request headers in RedactedDict (dict subclass with redacted
str/repr) at the single entry point where they enter the system. This
prevents any downstream logging path from exposing Bearer tokens.

Also remove a redundant log that re-read request.headers directly,
bypassing the already-cleaned _headers variable.

* Add e2e test for JWT redaction in debug logs

* Preserve RedactedDict type through copy()
2026-02-28 15:44:38 -08:00
Krish DholakiaandGitHub 76ccc9e844 Guardrail Policy Versioning (#21862)
* feat: initial commit, adding support for policy versioning on litellm

* fix(policy_registry): support policy versioning

* fix: multiple QA fixes for policy flow builder with guardrail versioning on litellm

* feat: ui improvements

* feat: add prisma migration

* fix: address greptile fixes
2026-02-21 20:14:31 -08:00
ryan-crabbeandGitHub a8dbcb1a30 Merge pull request #20526 from ryan-crabbe/perf/add-litellm-data-to-request-optimizations
Perf: add_litellm_data_to_request optimizations
2026-02-21 12:16:05 -08:00
Julio Quinteros ProandClaude Sonnet 4.6 7b6ffbb52a fix(tests): wrap callbacks cleanup in try/finally and resolve merge conflict
- test_litellm_pre_call_utils.py: wrap test body in try/finally so
  litellm.callbacks is always restored even when an assertion fails,
  addressing greptile review comment
- test_langfuse_otel.py: resolve trivial merge conflict in comment
  ("unpatched" vs "unpatch-ed"), keeping correct spelling

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 18:50:17 -03:00
Julio Quinteros ProandClaude Sonnet 4.6 2e0a8b3cf8 fix(tests): resolve MCP test isolation failures in parallel execution
Three test isolation issues fixed:

1. test_mcp_debug.py: Replace deprecated asyncio.get_event_loop().run_until_complete()
   with asyncio.run() in TestWrapSendWithDebugHeaders. In Python 3.10+,
   get_event_loop() raises RuntimeError when no event loop is set in the
   current thread, causing test_injects_headers and test_body_messages_unchanged
   to fail in isolation.

2. test_mcp_server_manager.py: After _reload_mcp_manager_module() creates a new
   global_mcp_server_manager instance, server.py still holds a stale reference
   to the old instance. Tests in test_mcp_server.py that populate the new
   manager's registry and then call server.py functions (e.g. _get_tools_from_mcp_servers)
   get empty results because server.py reads from the old manager. Fix: update
   server.py's module-level reference after each reload.

3. test_litellm_pre_call_utils.py: test_add_litellm_metadata_from_request_headers
   sets litellm.callbacks without restoring it afterward. Add cleanup to restore
   original callbacks after the test to prevent state leaking to subsequent tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 14:08:48 -03:00
Julio Quinteros Pro 7dcef86cc6 Fix test_embedding_header_forwarding_with_model_group for parallel test execution
- Reload litellm_pre_call_utils module inside test to get fresh litellm reference
- Use string-based patch("litellm.model_group_settings") instead of patch.object
- These changes ensure the patch targets the correct module after conftest reloads litellm
2026-02-15 13:08:41 -03:00
Julio Quinteros Pro c52251ca72 test: Fix test isolation issues caused by module reloading
Fix several tests that fail in CI due to parallel test execution and
module reloading in conftest.py.

1. test_empty_assistant_message_handling:
   - Use patch.object on factory_module.litellm instead of direct assignment
   - Ensures the correct litellm reference is modified after conftest reloads

2. test_embedding_header_forwarding_with_model_group:
   - Use patch.object on pre_call_utils_module.litellm instead of direct assignment
   - Same fix for module reloading issue

3. test_embedding_input_array_of_tokens:
   - Move mock inside test function (after fixture initializes router)
   - Add skip condition if llm_router is None
   - Fixes "AttributeError: None does not have 'aembedding'" in parallel execution

Root cause: conftest.py reloads litellm at module scope, which can cause:
- Different litellm references between test code and library code
- Global state (like llm_router) being None at decorator execution time
- isinstance checks failing due to class identity mismatches
2026-02-15 13:08:41 -03:00
Ryan Crabbe b4b27203fc perf: cache request.url.path in _get_metadata_variable_name (add_litellm_data_to_request)
Cache request.url.path once instead of accessing it 6 times (2 in
assistants check + 4 in LITELLM_METADATA_ROUTES loop). Reduces
per-call time from 47µs to 20µs (-58%).

Also inline the assistants API check to avoid function call overhead.

Adds 8 tests for _get_metadata_variable_name covering all return paths.
2026-02-05 14:09:11 -08:00
Ishaan JaffandGitHub a870722f65 [Feat] UI + Backend - Allow adding policies on Keys/Teams + Viewing on Info panels (#19688)
* ui for policy mgmt

* test_add_guardrails_from_policy_engine_accepts_dynamic_policies_and_pops_from_data
2026-01-23 19:03:44 -08:00
Ishaan JaffandGitHub c23e4b87dc [Feat] New LiteLLM Policy engine - create policies to manage guardrails, conditions - permissions per Key, Team (#19612)
* init PolicyMatcher

* TestPolicyMatcherGetMatchingPolicies

* TestPolicyMatcherGetMatchingPolicies

* feat: init PolicyResolver

* init resolver types

* init policy from config

* inint PolicyValidator

* validate policy

* init Architecture Diagram

* test_add_guardrails_from_policy_engine

* init _init_policy_engine

* test updates

* test fixws

* new attachment config

* simplify types

* TestPolicyResolverInheritance

* fix policy resolver

* fix policies

* fix applied policy

* docs fix

* docs fix

* fix linting + QA checks

* fix linting + QA fixes

* test fixes
2026-01-22 19:49:53 -08:00
YutaSaitoandGitHub eec4ed640b Revert "Stabilise mock tests" 2026-01-17 06:26:18 +09:00
yuneng-jiangandGitHub 6a7edd8f2b Merge pull request #18785 from BerriAI/litellm_user_promethus_metrics
[Feature] User Metrics for Promethus
2026-01-15 15:51:02 -08:00
Sameer Kankute f28d951202 Fix: tests/test_litellm/proxy/test_litellm_pre_call_utils.py::test_embedding_header_forwarding_with_model_group 2026-01-15 19:41:16 +05:30
yuneng-jiang 567f723214 Merge remote-tracking branch 'origin' into litellm_user_promethus_metrics 2026-01-12 15:59:16 -08:00
Sameer Kankute dbec9c7084 Fix: Header forwarding for embeddings endpoint 2026-01-12 18:00:48 +05:30
yuneng-jiang d01c48ec5e User metrics for promethus 2026-01-07 15:05:09 -08:00
yuneng-jiangandGitHub 7225fc066f Fix key model alias (#16896) 2025-11-20 16:05:49 -08:00
Ishaan JaffandGitHub 5c375b23ae [Fix] Guardrails - Ensure Key Guardrails are applied (#16025)
* _add_guardrails_from_key_or_team_metadata

* test_team_guardrails_append_to_key_guardrails

* fix move_guardrails_to_metadata

* fix _add_guardrails_from_key_or_team_metadata
2025-10-28 16:40:49 -07:00
Ishaan JaffandGitHub 02df4c6b30 [Fix] DD logging - ensure key's metadata + guardrail is logged on DD (#15980)
* fix get_sanitized_user_information_from_key

* test_get_sanitized_user_information_from_key_includes_guardrails_metadata
2025-10-27 13:45:09 -07:00
Boopesh ShanmugamandGitHub 8b338a4d8c User Headers X LiteLLM Users Mapping feature (#14485)
* Draft commit.

* user header mapping feature with backward compatibility with user_header_name field.

* user header mapping feature with backward compatibility with user_header_name field optimizations.

* Added unit tests.
2025-09-12 11:49:37 -07:00
Ishaan JaffandGitHub 128d9a3488 [Feature]: Add header support for spend_logs_metadata (#14186)
* fix: allow settings spend_logs_metadata

* fix add_litellm_data_for_backend_llm_call

* fix: add add_litellm_metadata_from_request_headers

* fix add_litellm_metadata_from_request_headers

* test_add_litellm_metadata_from_request_headers

* add_litellm_metadata_from_request_headers

* docs Tracking Spend with custom metadata

* add_litellm_metadata_from_request_headers

* add_litellm_metadata_from_request_headers
2025-09-02 15:13:15 -07:00
Krrish Dholakia 2e16f2cb13 test: add unit tests 2025-08-18 21:19:43 -07:00
Krish DholakiaandGitHub 5b50a12329 Revert "fix: Set user from token user_id for OpenMeter integration (#13029)" (#13107)
This reverts commit f8c09e44f6.
2025-07-29 15:49:20 -07:00
Better than breakfast.andGitHub f8c09e44f6 fix: Set user from token user_id for OpenMeter integration (#13029) 2025-07-29 15:41:50 -07:00
Krish DholakiaandGitHub d26f74ade5 Request Headers - support x-litellm-num-retries + Usage - support usage by model group (#12890)
* feat(litellm_pre_call_utils.py): add num_retries to litellm data for backend call

allow user to pass in num retries via request headers

* test(test_litellm_pre_call_utils.py): add unit test

* docs(request_headers.md): document new request header

* fix(common_daily_activity.py): show spend breakdown by model group

Partial fix for https://github.com/BerriAI/litellm/issues/12887

* feat(new_usage.tsx): new tab switcher for viewing usage by model group vs. received model

Closes https://github.com/BerriAI/litellm/issues/12887
2025-07-22 23:09:36 -07:00
Ishaan JaffandGitHub b41ce5c92f [Feat] - Track cost + add tags for health checks done by LiteLLM Proxy (#12880)
* refactor to use add_user_api_key_auth_to_request_metadata

* add get_litellm_internal_health_check_user_api_key_auth

* add get_litellm_internal_health_check_user_api_key_auth

* add _update_model_params_with_health_check_tracking_information

* add HealthCheckHelpers

* refactor to use clean helpers

* test_update_model_params_with_health_check_tracking_information

* test_get_litellm_internal_health_check_user_api_key_auth

* test_add_user_api_key_auth_to_request_metadata

* fix _update_model_params_with_health_check_tracking_information
2025-07-22 18:45:57 -07:00
Jugal D. BhattandGitHub b443817a56 [Key Access] Litellm disabled callbacks for UI (#12769)
* add disabled callbacks to ui

* added body

* update edit settings

* add tests
2025-07-19 14:32:05 -07:00
Ishaan JaffandGitHub eef0623443 [Feat] Add Arize Team Based Logging (#12264)
* working KeyAndTeamLoggingSettings

* add arize_space_id to StandardCallbackDynamicParams

* add construct_dynamic_arize_headers

* add construct_dynamic_arize_headers to

* update otel arize logging

* fix imports

* test_construct_dynamic_arize_headers

* dynamic key/team settings

* test_get_dynamic_logging_metadata_with_arize_team_logging
2025-07-02 17:15:35 -07:00
Krish DholakiaandGitHub 7f8b2579a2 Minor Fixes (#11868)
* fix(litellm_pre_call_utils.py): add user agent tags to spend logs in standard logging payload logic

avoid clash when tag based routing is enabled

* test: remove redundant test

* test: rename oidc test to run earlier

quicker debuging

* fix(azure.py): return more detailed error message

* fix(azure/common_utils.py): use default scope, if scope is none

fixes oidc test

* fix: always default to cognitiveservices.azure.com

* test: update test
2025-06-18 14:12:59 -07:00
Krish DholakiaandGitHub 87ae2cf3d7 SSO - Allow passing additional headers + Spend Tags - automatically track spend by user agent (allows cost tracking for claude code) (#11781)
* feat(ui_sso.py): allow admin to specify additional headers for sso provider

some sso providers require special headers to return a json response

* test(test_ui_sso.py): add unit tests to ensure custom headers are respect3ed

* docs(config_settings.md): document new header param

* fix(litellm_pre_call_utils.py): add spend tag tracking by user agent

allows checking spend for cli tools like claude code

* feat(litellm_pre_call_utils.py): track spend by user agent part if user agent contains "/"

allows tracking spend across user agent versions

Better cost tracking for claude cod

* test(test_litellm_pre_call_utils.py): add testing for pre call utils, user agent parsing

* fix: fix linting check
2025-06-16 21:53:40 -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