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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge branch 'litellm_internal_staging' into litellm_bedrock_converse_no_trailing_empty_chunk
mateo-berrie0511e938409
diff --cc litellm/llms/bedrock/chat/invoke_handler.pyindex 595884ae630,ce89c6c23e2..35e82f1961a--- a/litellm/llms/bedrock/chat/invoke_handler.py+++ b/litellm/llms/bedrock/chat/invoke_handler.py@@@ -559,12 -560,13 +560,17 @@@ class AWSEventStreamDecoderelif "stopReason" in chunk_data:finish_reason = map_finish_reason(chunk_data.get("stopReason", "stop"))elif "usage" in chunk_data:- usage = converse_config._transform_usage(chunk_data.get("usage", {}))+ usage = converse_config.transform_usage(+ chunk_data.get("usage", {}),+ thinking_ran=self._thinking_ran,+ )+ if thinking_blocks:+ self._thinking_ran = True+ carries_message_content: Final = any(- key in chunk_data for key in ("start", "delta", "contentBlockIndex", "stopReason")++ key in chunk_data for key in ("start", "delta", "contentBlockIndex", "stopReason", "trace")+ )+model_response_provider_specific_fields: Final = {}if "trace" in chunk_data:trace: Final = chunk_data.get("trace")diff --cc tests/test_litellm/llms/bedrock/chat/test_invoke_handler.pyindex 9783976db4a,e2892a6ccee..cd305d8ed26--- a/tests/test_litellm/llms/bedrock/chat/test_invoke_handler.py+++ b/tests/test_litellm/llms/bedrock/chat/test_invoke_handler.py@@@ -1,16 -1,10 +1,12 @@@+import datetime- import os- import sysfrom unittest.mock import AsyncMock, MagicMock+ import httpximport pytest- sys.path.insert(- 0, os.path.abspath("../../../../..")- ) # Adds the parent directory to the system path--+ import litellm+from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj+from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapperfrom litellm.llms.bedrock.chat.invoke_handler import (AWSEventStreamDecoder,make_call,@@@ -297,45 -292,49 +294,182 @@@ def test_make_sync_call_honors_explicitresponse.iter_bytes.assert_called_once_with(chunk_size=2048)- @pytest.mark.asyncio- async def test_converse_stream_ends_on_finish_reason_chunk():- """The usage-only metadata event Bedrock sends after messageStop must not reach the caller as an extra- assistant delta following the finish_reason chunk."""- model = "anthropic.claude-sonnet-4-6"- events = (- {"role": "assistant"},- {"contentBlockIndex": 0, "delta": {"text": "Hello"}},- {"contentBlockIndex": 0, "delta": {"text": " world"}},- {"contentBlockIndex": 0},- {"stopReason": "end_turn"},- {"usage": {"inputTokens": 10, "outputTokens": 5, "totalTokens": 15}, "metrics": {"latencyMs": 100}},- )++CONVERSE_MODEL = "anthropic.claude-sonnet-4-6"++CONVERSE_METADATA_EVENT = {++ "usage": {"inputTokens": 10, "outputTokens": 5, "totalTokens": 15},++ "metrics": {"latencyMs": 100},++}+++++def _converse_stream_wrapper(events):+ async def bedrock_stream():- decoder = AWSEventStreamDecoder(model=model)++ decoder = AWSEventStreamDecoder(model=CONVERSE_MODEL)+ for event in events:+ yield decoder._chunk_parser(chunk_data=event)+- wrapper = CustomStreamWrapper(++ return CustomStreamWrapper(+ completion_stream=bedrock_stream(),- model=model,++ model=CONVERSE_MODEL,+ custom_llm_provider="bedrock",+ logging_obj=LiteLLMLoggingObj(- model=model,++ model=CONVERSE_MODEL,+ messages=[{"role": "user", "content": "hi"}],+ stream=True,+ call_type="completion",+ start_time=datetime.datetime.now(),+ litellm_call_id="1234",+ function_id="1234",+ ),+ )+++++ "events, expected_finish_reason",++ [++ pytest.param(++ (++ {"role": "assistant"},++ {"contentBlockIndex": 0, "delta": {"text": "Hello"}},++ {"contentBlockIndex": 0, "delta": {"text": " world"}},++ {"contentBlockIndex": 0},++ {"stopReason": "end_turn"},++ CONVERSE_METADATA_EVENT,++ ),++ "stop",++ id="text",++ ),++ pytest.param(++ (++ {"role": "assistant"},++ {"contentBlockIndex": 0, "start": {"toolUse": {"toolUseId": "t1", "name": "get_weather"}}},++ {"contentBlockIndex": 0, "delta": {"toolUse": {"input": '{"city": "SF"}'}}},++ {"contentBlockIndex": 0},++ {"contentBlockIndex": 1, "start": {"toolUse": {"toolUseId": "t2", "name": "get_time"}}},++ {"contentBlockIndex": 1, "delta": {"toolUse": {"input": '{"tz": "PT"}'}}},++ {"contentBlockIndex": 1},++ {"stopReason": "tool_use"},++ CONVERSE_METADATA_EVENT,++ ),++ "tool_calls",++ id="multiple_tool_calls",++ ),++ pytest.param(++ (++ {"role": "assistant"},++ {"contentBlockIndex": 0, "start": {}},++ {"contentBlockIndex": 0, "delta": {"text": "Let me check."}},++ {"contentBlockIndex": 0},++ {"contentBlockIndex": 1, "start": {"toolUse": {"toolUseId": "t1", "name": "get_weather"}}},++ {"contentBlockIndex": 1, "delta": {"toolUse": {"input": '{"city": "SF"}'}}},++ {"contentBlockIndex": 1},++ {"stopReason": "tool_use"},++ CONVERSE_METADATA_EVENT,++ ),++ "tool_calls",++ id="text_then_tool_call",++ ),++ pytest.param(++ (++ {"role": "assistant"},++ {"contentBlockIndex": 0, "start": {}},++ {"contentBlockIndex": 0, "delta": {"reasoningContent": {"text": "thinking hard"}}},++ {"contentBlockIndex": 0, "delta": {"reasoningContent": {"signature": "sig123"}}},++ {"contentBlockIndex": 0},++ {"contentBlockIndex": 1, "start": {}},++ {"contentBlockIndex": 1, "delta": {"text": "Answer"}},++ {"contentBlockIndex": 1},++ {"stopReason": "end_turn"},++ CONVERSE_METADATA_EVENT,++ ),++ "stop",++ id="reasoning_then_text",++ ),++ ],++)++async def test_converse_stream_ends_on_finish_reason_chunk(events, expected_finish_reason):++ """The usage-only metadata event Bedrock sends after messageStop must not reach the caller as an extra++ assistant delta following the finish_reason chunk."""++ wrapper = _converse_stream_wrapper(events)+++ chunks = [chunk async for chunk in wrapper]+- assert [choice.finish_reason for chunk in chunks for choice in chunk.choices].count("stop") == 1- assert chunks[-1].choices[0].finish_reason == "stop", (++ finish_reasons = [choice.finish_reason for chunk in chunks for choice in chunk.choices if choice.finish_reason]++ assert finish_reasons == [expected_finish_reason]++ assert chunks[-1].choices[0].finish_reason == expected_finish_reason, (+ f"stream must end on the finish_reason chunk, got trailing {chunks[-1].model_dump(exclude_none=True)}"+ )++ roles = [choice.delta.role for chunk in chunks for choice in chunk.choices if choice.delta.role]++ assert roles == ["assistant"]+ assert any(getattr(chunk, "usage", None) is not None for chunk in wrapper.chunks)+++++async def test_converse_stream_still_emits_guardrail_trace_after_finish_reason():++ """Guardrail metadata events carry a trace payload alongside usage; that chunk must still reach the caller++ after the finish_reason chunk, as it did before the regression."""++ trace = {"guardrail": {"inputAssessment": {"g1": {}}}}++ events = (++ {"role": "assistant"},++ {"contentBlockIndex": 0, "delta": {"text": "Hello"}},++ {"contentBlockIndex": 0},++ {"stopReason": "end_turn"},++ {**CONVERSE_METADATA_EVENT, "trace": trace},++ )++ wrapper = _converse_stream_wrapper(events)++++ chunks = [chunk async for chunk in wrapper]++++ finish_reasons = [choice.finish_reason for chunk in chunks for choice in chunk.choices if choice.finish_reason]++ assert finish_reasons == ["stop"]++ assert chunks[-1].provider_specific_fields == {"trace": trace}++ assert chunks[-1].choices[0].delta.content == ""++ assert chunks[-1].choices[0].delta.role == "assistant"+++++ def test_invoke_streaming_forwards_bedrock_response_headers():+ response = MagicMock()+ response.status_code = 200+ response.iter_bytes = MagicMock(return_value=iter([]))+ response.headers = httpx.Headers({"x-amzn-requestid": "req-789"})+ client = HTTPHandler()+ client.post = MagicMock(return_value=response)++ stream = litellm.completion(+ model="bedrock/invoke/anthropic.claude-haiku-4-5-20251001-v1:0",+ messages=[{"role": "user", "content": "hi"}],+ stream=True,+ client=client,+ aws_access_key_id="fake",+ aws_secret_access_key="fake",+ aws_region_name="us-east-1",+ )++ assert stream._hidden_params["additional_headers"]["llm_provider-x-amzn-requestid"] == "req-789"+++ @pytest.mark.asyncio+ async def test_async_invoke_streaming_forwards_bedrock_response_headers():+ async def _no_bytes(chunk_size=None):+ return+ yield b""++ response = MagicMock()+ response.status_code = 200+ response.aiter_bytes = _no_bytes+ response.headers = httpx.Headers({"x-amzn-requestid": "req-987"})+ client = AsyncHTTPHandler()+ client.post = AsyncMock(return_value=response)++ stream = await litellm.acompletion(+ model="bedrock/invoke/anthropic.claude-haiku-4-5-20251001-v1:0",+ messages=[{"role": "user", "content": "hi"}],+ stream=True,+ client=client,+ aws_access_key_id="fake",+ aws_secret_access_key="fake",+ aws_region_name="us-east-1",+ )++ assert stream._hidden_params["additional_headers"]["llm_provider-x-amzn-requestid"] == "req-987"+diff --cc ui/litellm-dashboard/src/components/claude_code_plugins/skill_detail.tsxindex fe001641135,9479b38ff41..25b35c34861--- a/ui/litellm-dashboard/src/components/claude_code_plugins/skill_detail.tsx+++ b/ui/litellm-dashboard/src/components/claude_code_plugins/skill_detail.tsx@@@ -276,8 -302,69 +302,69 @@@ const SkillDetail: React.FC<SkillDetail<h2 style={{ fontSize: 18, fontWeight: 400, color: "#202124", margin: "0 0 8px 0" }}>One-time marketplace setup</h2>- <p style={{ fontSize: 14, color: "#5f6368", margin: "0 0 24px 0", lineHeight: 1.6 }}>- Add this to{" "}++ {/* Option 1: single command — fastest path for most users */}+ <p style={{ fontSize: 14, color: "#5f6368", margin: "0 0 12px 0", lineHeight: 1.6 }}>+ Run this command in Claude Code to register the marketplace:+ </p>+ <div+ style={{+ border: "1px solid #dadce0",+ borderRadius: 8,+ overflow: "hidden",+ marginBottom: 24,+ }}+ >+ <div+ style={{+ display: "flex",+ alignItems: "center",+ justifyContent: "space-between",+ padding: "10px 16px",+ backgroundColor: "#f8f9fa",+ borderBottom: "1px solid #dadce0",+ }}+ >+ <span style={{ fontSize: 13, color: "#3c4043", fontWeight: 500 }}>Run in Claude Code</span>+ <button+ onClick={() => {+ const origin = typeof window !== "undefined" ? window.location.origin : "";+ copyToClipboard(`/plugin marketplace add ${origin}/claude-code/marketplace.json`, "marketplace-cmd");+ }}+ style={{+ display: "flex",+ alignItems: "center",+ gap: 4,+ fontSize: 12,+ color: copiedKey === "marketplace-cmd" ? "#137333" : "#1a73e8",+ background: "none",+ border: "none",+ cursor: "pointer",+ padding: 0,+ }}+ >- {copiedKey === "marketplace-cmd" ? <CheckOutlined /> : <CopyOutlined />}++ {copiedKey === "marketplace-cmd" ? <Check className="size-3" /> : <Copy className="size-3" />}+ {copiedKey === "marketplace-cmd" ? "Copied" : "Copy"}+ </button>+ </div>+ <pre+ style={{+ margin: 0,+ padding: "14px 16px",+ fontSize: 13,+ fontFamily: "monospace",+ color: "#202124",+ backgroundColor: "#fff",+ }}+ >+ {`/plugin marketplace add ${typeof window !== "undefined" ? window.location.origin : "<proxy-url>"}/claude-code/marketplace.json`}+ </pre>+ </div>++ {/* Option 2: settings.json — for persistent config or managed deployments.+ extraKnownMarketplaces requires source to be a nested object, not a flat string. */}+ <p style={{ fontSize: 14, color: "#5f6368", margin: "0 0 12px 0", lineHeight: 1.6 }}>+ Or add this to{" "}<code style={{ fontSize: 13, backgroundColor: "#f1f3f4", padding: "1px 6px", borderRadius: 4 }}>~/.claude/settings.json</code>{" "}