Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Litellm dev 05 26 2025 p1 (#11165)

Krish Dholakia066a502b89db
diff --git a/litellm/main.py b/litellm/main.py
index 7f1ecd737f8..afdbb2d2e05 100644
--- a/litellm/main.py
+++ b/litellm/main.py
@@ -1187,10 +1187,8 @@ def completion( # type: ignore # noqa: PLR0915
special_params=non_default_params,
custom_llm_provider=custom_llm_provider,
additional_drop_params=kwargs.get("additional_drop_params"),
- )
- processed_non_default_params = add_provider_specific_params_to_optional_params(
- optional_params=processed_non_default_params,
- passed_params=non_default_params,
+ remove_sensitive_keys=True,
+ add_provider_specific_params=True,
)
if litellm.add_function_to_prompt and optional_params.get(
diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml
index e85ddfdc2be..dd3c1061317 100644
--- a/litellm/proxy/_new_secret_config.yaml
+++ b/litellm/proxy/_new_secret_config.yaml
@@ -4,7 +4,8 @@ model_list:
model: openai/fake
api_key: fake-key
api_base: https://exampleopenaiendpoint-production.up.railway.app/
-
-
litellm_settings:
- cache: true
\ No newline at end of file
+ cache: true
+ success_callback: ["langfuse"]
+ failure_callback: ["langfuse"]
+ alerting: ["slack"]
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index df40577e1a0..8ce5b38119d 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -173,7 +173,10 @@ from litellm.proxy.batches_endpoints.endpoints import router as batches_router
## Import All Misc routes here ##
from litellm.proxy.caching_routes import router as caching_router
-from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing, create_streaming_response
+from litellm.proxy.common_request_processing import (
+ ProxyBaseLLMRequestProcessing,
+ create_streaming_response,
+)
from litellm.proxy.common_utils.callback_utils import initialize_callbacks_on_proxy
from litellm.proxy.common_utils.debug_utils import init_verbose_loggers
from litellm.proxy.common_utils.debug_utils import router as debugging_endpoints_router
@@ -749,17 +752,17 @@ try:
os.rename(src, dst)
if server_root_path != "":
- print( # noqa
- f"server_root_path is set, forwarding any /ui requests to {server_root_path}/ui"
+ verbose_proxy_logger.info( # noqa
+ f"server_root_path is set, forwarding any /ui requests to {server_root_path}/ui, any /sso/key/generate requests to {server_root_path}/sso/key/generate"
) # noqa
- if os.getenv("PROXY_BASE_URL") is None:
- os.environ["PROXY_BASE_URL"] = server_root_path
@app.middleware("http")
async def redirect_ui_middleware(request: Request, call_next):
if request.url.path.startswith("/ui"):
new_url = str(request.url).replace("/ui", f"{server_root_path}/ui", 1)
return RedirectResponse(new_url)
+ elif request.url.path == "/sso/key/generate":
+ return RedirectResponse(f"{server_root_path}/sso/key/generate")
return await call_next(request)
except Exception:
@@ -3581,7 +3584,9 @@ async def chat_completion( # noqa: PLR0915
return StreamingResponse(
selected_data_generator,
media_type="text/event-stream",
- status_code=e.status_code if hasattr(e, "status_code") else status.HTTP_400_BAD_REQUEST,
+ status_code=e.status_code
+ if hasattr(e, "status_code")
+ else status.HTTP_400_BAD_REQUEST,
)
_usage = litellm.Usage(prompt_tokens=0, completion_tokens=0, total_tokens=0)
_chat_response.usage = _usage # type: ignore
@@ -3783,7 +3788,9 @@ async def completion( # noqa: PLR0915
selected_data_generator,
media_type="text/event-stream",
headers={},
- status_code=e.status_code if hasattr(e, "status_code") else status.HTTP_400_BAD_REQUEST,
+ status_code=e.status_code
+ if hasattr(e, "status_code")
+ else status.HTTP_400_BAD_REQUEST,
)
else:
_response = litellm.TextCompletionResponse()
@@ -5106,7 +5113,7 @@ async def run_thread(
request_data=data,
),
media_type="text/event-stream",
- headers={}, # Added empty headers dict, original call missed this argument
+ headers={}, # Added empty headers dict, original call missed this argument
)
### ALERTING ###
diff --git a/litellm/utils.py b/litellm/utils.py
index d2e1437c4be..04682239516 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -2678,6 +2678,8 @@ def pre_process_non_default_params(
custom_llm_provider: str,
additional_drop_params: Optional[List[str]],
model: str,
+ remove_sensitive_keys: bool = False,
+ add_provider_specific_params: bool = False,
) -> dict:
"""
Pre-process non-default params to a standardized format
@@ -2759,9 +2761,32 @@ def pre_process_non_default_params(
):
new_parameters.pop("additionalProperties", None)
tool_function["parameters"] = new_parameters
+
+ if add_provider_specific_params:
+ non_default_params = add_provider_specific_params_to_optional_params(
+ optional_params=non_default_params,
+ passed_params=passed_params,
+ )
+
+ if remove_sensitive_keys:
+ non_default_params = remove_sensitive_keys_from_dict(non_default_params)
return non_default_params
+def remove_sensitive_keys_from_dict(d: dict) -> dict:
+ """
+ Remove sensitive keys from a dictionary
+ """
+ sensitive_key_phrases = ["key", "secret", "access", "credential"]
+ remove_keys = []
+ for key in d.keys():
+ if any(phrase in key.lower() for phrase in sensitive_key_phrases):
+ remove_keys.append(key)
+ for key in remove_keys:
+ d.pop(key)
+ return d
+
+
def pre_process_optional_params(
passed_params: dict, non_default_params: dict, custom_llm_provider: str
) -> dict:
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_bedrock_call.json b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_bedrock_call.json
new file mode 100644
index 00000000000..aa96e5949e5
--- /dev/null
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_bedrock_call.json
@@ -0,0 +1,78 @@
+{
+ "batch": [
+ {
+ "id": "3c9b544f-ef3f-449e-8ec1-763acbb56bec",
+ "type": "trace-create",
+ "body": {
+ "id": "litellm-test-c4c1c850-e8c9-4b16-b5a4-bff2bf9fa4f6",
+ "timestamp": "2025-05-26T21:13:16.796768Z",
+ "name": "litellm-acompletion",
+ "input": {
+ "messages": [
+ {
+ "role": "user",
+ "content": "Hello!"
+ }
+ ]
+ },
+ "tags": []
+ },
+ "timestamp": "2025-05-26T21:13:16.796875Z"
+ },
+ {
+ "id": "90e6bc70-05d9-4444-8b87-4523a9a54c17",
+ "type": "generation-create",
+ "body": {
+ "traceId": "litellm-test-c4c1c850-e8c9-4b16-b5a4-bff2bf9fa4f6",
+ "name": "litellm-acompletion",
+ "startTime": "2025-05-26T14:13:16.469836-07:00",
+ "metadata": {
+ "hidden_params": {
+ "model_id": null,
+ "cache_key": null,
+ "api_base": null,
+ "response_cost": 0.00018,
+ "additional_headers": {},
+ "litellm_overhead_time_ms": null,
+ "batch_models": null,
+ "litellm_model_name": "bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0",
+ "usage_object": null
+ },
+ "litellm_response_cost": 0.00018,
+ "cache_hit": false,
+ "requester_metadata": {}
+ },
+ "input": {
+ "messages": [
+ {
+ "role": "user",
+ "content": "Hello!"
+ }
+ ]
+ },
+ "level": "DEFAULT",
+ "id": "time-14-13-16-469836_chatcmpl-3803a9e9-aa68-4493-94d9-247f354830d6",
+ "endTime": "2025-05-26T14:13:16.795438-07:00",
+ "completionStartTime": "2025-05-26T14:13:16.795438-07:00",
+ "model": "anthropic.claude-3-5-sonnet-20240620-v1:0",
+ "modelParameters": {
+ "aws_region": "us-east-1"
+ },
+ "usage": {
+ "input": 10,
+ "output": 10,
+ "unit": "TOKENS",
+ "totalCost": 0.00018
+ }
+ },
+ "timestamp": "2025-05-26T21:13:16.797156Z"
+ }
+ ],
+ "metadata": {
+ "batch_size": 2,
+ "sdk_integration": "litellm",
+ "sdk_name": "python",
+ "sdk_version": "2.44.1",
+ "public_key": "pk-lf-3bfc4db9-217f-48e9-92e0-142566e3c204"
+ }
+}
\ No newline at end of file
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_vertex_call.json b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_vertex_call.json
new file mode 100644
index 00000000000..51a4fac0579
--- /dev/null
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_vertex_call.json
@@ -0,0 +1,76 @@
+{
+ "batch": [
+ {
+ "id": "7d33d536-2730-4815-8957-80866c09c053",
+ "type": "trace-create",
+ "body": {
+ "id": "litellm-test-72861437-ff5b-4c48-89c0-a143534d9e7a",
+ "timestamp": "2025-05-26T21:15:40.610459Z",
+ "name": "litellm-acompletion",
+ "input": {
+ "messages": [
+ {
+ "role": "user",
+ "content": "Hello!"
+ }
+ ]
+ },
+ "tags": []
+ },
+ "timestamp": "2025-05-26T21:15:40.610603Z"
+ },
+ {
+ "id": "ebb5079c-7726-4adb-9616-e1862735e1d8",
+ "type": "generation-create",
+ "body": {
+ "traceId": "litellm-test-72861437-ff5b-4c48-89c0-a143534d9e7a",
+ "name": "litellm-acompletion",
+ "startTime": "2025-05-26T14:15:40.349639-07:00",
+ "metadata": {
+ "hidden_params": {
+ "model_id": null,
+ "cache_key": null,
+ "api_base": null,
+ "response_cost": 7.5e-06,
+ "additional_headers": {},
+ "litellm_overhead_time_ms": null,
+ "batch_models": null,
+ "litellm_model_name": "vertex_ai/gemini-2.0-flash-001",
+ "usage_object": null
+ },
+ "litellm_response_cost": 7.5e-06,
+ "cache_hit": false,
+ "requester_metadata": {}
+ },
+ "input": {
+ "messages": [
+ {
+ "role": "user",
+ "content": "Hello!"
+ }
+ ]
+ },
+ "level": "DEFAULT",
+ "id": "time-14-15-40-349639_chatcmpl-59a988d0-7ef1-4dc4-bc18-d2e78961817f",
+ "endTime": "2025-05-26T14:15:40.607266-07:00",
+ "completionStartTime": "2025-05-26T14:15:40.607266-07:00",
+ "model": "gemini-2.0-flash-001",
+ "modelParameters": {},
+ "usage": {
+ "input": 10,
+ "output": 10,
+ "unit": "TOKENS",
+ "totalCost": 7.5e-06
+ }
+ },
+ "timestamp": "2025-05-26T21:15:40.610953Z"
+ }
+ ],
+ "metadata": {
+ "batch_size": 2,
+ "sdk_integration": "litellm",
+ "sdk_name": "python",
+ "sdk_version": "2.44.1",
+ "public_key": "pk-lf-3bfc4db9-217f-48e9-92e0-142566e3c204"
+ }
+}
\ No newline at end of file
diff --git a/tests/logging_callback_tests/test_langfuse_e2e_test.py b/tests/logging_callback_tests/test_langfuse_e2e_test.py
index 12aa2f38bda..8d5e63fcdc0 100644
--- a/tests/logging_callback_tests/test_langfuse_e2e_test.py
+++ b/tests/logging_callback_tests/test_langfuse_e2e_test.py
@@ -381,6 +381,68 @@ class TestLangfuseLogging:
await self._verify_langfuse_call(
setup["mock_post"], "completion_with_no_choices.json", setup["trace_id"]
)
+
+ @pytest.mark.asyncio
+ async def test_langfuse_logging_completion_with_bedrock_llm_response(
+ self, mock_setup
+ ):
+ """Test Langfuse logging for chat completion with malformed LLM response"""
+ setup = await mock_setup # Await the fixture
+ litellm._turn_on_debug()
+ with patch("httpx.Client.post", setup["mock_post"]):
+ mock_response = litellm.ModelResponse(
+ choices=[],
+ usage=litellm.Usage(
+ prompt_tokens=10,
+ completion_tokens=10,
+ total_tokens=20,
+ ),
+ model="anthropic.claude-3-5-sonnet-20240620-v1:0",
+ object="chat.completion",
+ created=1723081200,
+ ).model_dump()
+ await litellm.acompletion(
+ model="bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0",
+ messages=[{"role": "user", "content": "Hello!"}],
+ mock_response=mock_response,
+ metadata={"trace_id": setup["trace_id"]},
+ aws_access_key_id="fake-key",
+ aws_secret_access_key="fake-key",
+ aws_region="us-east-1",
+ )
+ await self._verify_langfuse_call(
+ setup["mock_post"], "completion_with_bedrock_call.json", setup["trace_id"]
+ )
+ @pytest.mark.asyncio
+ async def test_langfuse_logging_completion_with_vertex_llm_response(
+ self, mock_setup
+ ):
+ """Test Langfuse logging for chat completion with malformed LLM response"""
+ setup = await mock_setup # Await the fixture
+ litellm._turn_on_debug()
+ with patch("httpx.Client.post", setup["mock_post"]):
+ mock_response = litellm.ModelResponse(
+ choices=[],
+ usage=litellm.Usage(
+ prompt_tokens=10,
+ completion_tokens=10,
+ total_tokens=20,
+ ),
+ model="vertex/gemini-2.0-flash-001",
+ object="chat.completion",
+ created=1723081200,
+ ).model_dump()
+ await litellm.acompletion(
+ model="vertex_ai/gemini-2.0-flash-001",
+ messages=[{"role": "user", "content": "Hello!"}],
+ mock_response=mock_response,
+ metadata={"trace_id": setup["trace_id"]},
+ vertex_credentials="my-mock-credentials",
+ api_key="my-mock-credentials-2",
+ )
+ await self._verify_langfuse_call(
+ setup["mock_post"], "completion_with_vertex_call.json", setup["trace_id"]
+ )
@pytest.mark.asyncio
async def test_langfuse_logging_with_router(self, mock_setup):
@@ -419,4 +481,4 @@ class TestLangfuseLogging:
)
await self._verify_langfuse_call(
setup["mock_post"], "completion_with_router.json", setup["trace_id"]
- )
\ No newline at end of file
+ )