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]

test(proxy): fix marketplace request fixture after staging merge

moe-berri989140d06592
diff --cc litellm/integrations/custom_logger.py
index df3237bff07,8f03e08f02d..d445a3adf14
--- a/litellm/integrations/custom_logger.py
+++ b/litellm/integrations/custom_logger.py
@@@ -3,12 -3,12 +3,13 @@@
import re
import traceback
from collections.abc import AsyncGenerator, Mapping, Sequence
++from types import MappingProxyType
from typing import TYPE_CHECKING, Any, ClassVar, Final, Optional
from pydantic import BaseModel
from litellm._logging import verbose_logger
--from litellm.constants import DEFAULT_MAX_RECURSE_DEPTH_SENSITIVE_DATA_MASKER
++from litellm.constants import DEFAULT_MAX_RECURSE_DEPTH_SENSITIVE_DATA_MASKER, EMPTY_MAPPING
from litellm.types.integrations.argilla import ArgillaItem
from litellm.types.integrations.custom_logger import AgenticLoopPlan
from litellm.types.llms.openai import AllMessageValues, ChatCompletionRequest
@@@ -950,15 -956,8 +951,18 @@@ class CustomLogger: # https://docs.lit
model_response_dict: Final = model_response.model_dump()
standard_logging_object_copy["response"] = model_response_dict
- redacted_details: Final = {**model_call_details, "standard_logging_object": standard_logging_object_copy}
- model_call_details_copy["standard_logging_object"] = standard_logging_object_copy
- return model_call_details_copy
+ params: Final = model_call_details.get("litellm_params")
+ request: Final = params.get("proxy_server_request") if isinstance(params, dict) else None
- if turn_off_message_logging and isinstance(params, dict) and isinstance(request, dict):
- return {
- **redacted_details,
- "litellm_params": {**params, "proxy_server_request": without_classifier_audit(request)},
- }
- return redacted_details
++ redacted_params: Final = (
++ MappingProxyType({"litellm_params": {**params, "proxy_server_request": without_classifier_audit(request)}})
++ if turn_off_message_logging and isinstance(params, dict) and isinstance(request, dict)
++ else EMPTY_MAPPING
++ )
++ return {
++ **model_call_details,
++ **redacted_params,
++ "standard_logging_object": standard_logging_object_copy,
++ }
async def get_proxy_server_request_from_cold_storage_with_object_key(
self,
diff --cc litellm/proxy/spend_tracking/spend_tracking_utils.py
index da35553a941,a21d761996f..16d6857c34c
--- a/litellm/proxy/spend_tracking/spend_tracking_utils.py
+++ b/litellm/proxy/spend_tracking/spend_tracking_utils.py
@@@ -4,6 -4,6 +4,7 @@@ import secret
from collections.abc import Mapping, Sequence
from datetime import datetime, timezone
from datetime import datetime as dt
++from types import MappingProxyType
from typing import Final, Literal, Protocol, cast, runtime_checkable
from pydantic import BaseModel
@@@ -862,7 -860,7 +863,7 @@@ _SENSITIVE_REQUEST_BODY_KEYS: Final = f
def _sanitize_request_body_for_spend_logs_payload(
-- request_body: dict,
++ request_body: Mapping[str, object],
visited: set | None = None,
max_string_length_prompt_in_db: int | None = None,
) -> dict:
@@@ -1249,13 -1247,9 +1250,13 @@@ def _get_proxy_server_request_for_spend
If turn_off_message_logging is enabled, redact messages in the request body.
"""
if _should_store_prompts_and_responses_in_spend_logs():
- _proxy_server_request: Final = cast(dict | None, litellm_params.get("proxy_server_request", {}))
+ _proxy_server_request: Final = cast(dict | None, litellm_params.get("proxy_server_request", EMPTY_MAPPING))
if _proxy_server_request is not None:
- _request_body = _proxy_server_request.get("body", {}) or {}
+ _request_body = _proxy_server_request.get("body", EMPTY_MAPPING) or EMPTY_MAPPING
+
+ standard_payload: Final = (kwargs or EMPTY_MAPPING).get("standard_logging_object")
+ if isinstance(standard_payload, Mapping):
- _request_body = {**_request_body, **classifier_audit_fields(standard_payload)}
++ _request_body = MappingProxyType({**_request_body, **classifier_audit_fields(standard_payload)})
if kwargs is not None:
realtime_tools: Final = kwargs.get("realtime_tools")
diff --cc litellm/router_strategy/complexity_router/complexity_router.py
index 6b30c6f3588,214872c17c9..a748bb5df27
--- a/litellm/router_strategy/complexity_router/complexity_router.py
+++ b/litellm/router_strategy/complexity_router/complexity_router.py
@@@ -2064,12 -2066,9 +2064,14 @@@ class ComplexityRouter(CustomLogger)
payload: Final = (
self._native_classifier_payload(messages_for_call, response_format, encrypted_task)
if encrypted_task is not None
-- else {"messages": messages_for_call, "response_format": response_format, **classifier_call_params}
++ else MappingProxyType(
++ {"messages": messages_for_call, "response_format": response_format, **classifier_call_params}
++ )
)
- proxy_server_request: Final = {"body": {"model": llm_config.model, **payload}}
+ proxy_server_request: Final = {
+ "originating_request_masked": masked_originating_request(request_kwargs),
+ "body": {"model": llm_config.model, **payload},
+ }
classify: Final = (
self.litellm_router_instance.aresponses
if encrypted_task is not None
diff --cc tests/test_litellm/proxy/anthropic_endpoints/test_claude_code_marketplace.py
index 99b09f48fe5,a7c2bd7ba20..a585666743f
--- a/tests/test_litellm/proxy/anthropic_endpoints/test_claude_code_marketplace.py
+++ b/tests/test_litellm/proxy/anthropic_endpoints/test_claude_code_marketplace.py
@@@ -377,6 -468,75 +468,75 @@@ async def test_register_plugin_unknown_
assert exc_info.value.status_code == 400
assert "git-subdir" in exc_info.value.detail["error"]
+ assert "archive" in exc_info.value.detail["error"]
+
+
+ @pytest.mark.asyncio
+ async def test_archive_source_registers_and_is_served_verbatim_in_marketplace():
+ response = await register_plugin(
+ request=RegisterPluginRequest(name="s3-skill", source=_ARCHIVE_SOURCE),
+ user_api_key_dict=_USER,
+ )
+
+ assert response.action == "created"
+ assert response.plugin.source == _ARCHIVE_SOURCE
+
- marketplace = json.loads((await get_marketplace()).body)
++ marketplace = json.loads((await get_marketplace(request=MagicMock())).body)
+ assert marketplace["plugins"] == [{"name": "s3-skill", "source": _ARCHIVE_SOURCE, "version": "1.0.0"}]
+
+
+ @pytest.mark.asyncio
+ async def test_archive_source_without_sha256_is_accepted():
+ source = {"source": "archive", "url": "https://artifacts.example.com/plugin.zip"}
+
+ response = await register_plugin(
+ request=RegisterPluginRequest(name="unpinned-skill", source=source),
+ user_api_key_dict=_USER,
+ )
+
+ assert response.plugin.source == source
+
+
+ @pytest.mark.asyncio
+ async def test_update_plugin_to_archive_source():
+ name = "my-monorepo-plugin"
+ await register_plugin(
+ request=RegisterPluginRequest(name=name, source=_GIT_SUBDIR_SOURCE),
+ user_api_key_dict=_USER,
+ )
+
+ response = await update_plugin(
+ plugin_name=name,
+ request=UpdatePluginRequest(source=_ARCHIVE_SOURCE),
+ user_api_key_dict=_USER,
+ )
+
+ assert response.action == "updated"
+ assert (await _read_stored_manifest(name))["source"] == _ARCHIVE_SOURCE
+
+
+ @pytest.mark.asyncio
+ @pytest.mark.parametrize(
+ "source, expected_fragment",
+ [
+ ({"source": "archive"}, "url"),
+ ({"source": "archive", "url": ""}, "url"),
+ ({"source": "archive", "url": "http://artifacts.example.com/plugin.zip"}, "https"),
+ ({"source": "archive", "url": "s3://skills-bucket/plugin.zip"}, "https"),
+ ({"source": "archive", "url": "https://"}, "https"),
+ ({"source": "archive", "url": "https:///plugin.zip"}, "https"),
+ ({"source": "archive", "url": "https://[::1/plugin.zip"}, "https"),
+ ({"source": "archive", "url": "https://artifacts.example.com/plugin.zip", "sha256": "a" * 63}, "sha256"),
+ ({"source": "archive", "url": "https://artifacts.example.com/plugin.zip", "sha256": "a" * 65}, "sha256"),
+ ({"source": "archive", "url": "https://artifacts.example.com/plugin.zip", "sha256": "g" * 64}, "sha256"),
+ ],
+ )
+ async def test_register_plugin_archive_rejects_malformed_source(source, expected_fragment):
+ with pytest.raises(HTTPException) as exc_info:
+ await register_plugin(request=RegisterPluginRequest(name="bad-plugin", source=source), user_api_key_dict=_USER)
+
+ assert exc_info.value.status_code == 400
+ assert expected_fragment in exc_info.value.detail["error"]
@pytest.mark.asyncio