From c2408889d2840ab9cd5eb87760a234bd62824038 Mon Sep 17 00:00:00 2001 From: UnaiAlias <52742669+UnaiAlias@users.noreply.github.com> Date: Fri, 31 Jul 2026 18:53:57 +0000 Subject: [PATCH] fix: remove duplicate litellm stream call in fetch_response_litellm_openai The streaming path called litellm.acompletion twice with the same kwargs. The first result was assigned to a variable that is never read, and only the second call's stream was returned. Every streamed request therefore consumed two provider requests (e.g. two NVIDIA NIM requests) with the same API key, halving effective per-key rate limits and leaking the first stream. Keep a single acompletion call for the streamed path; same fix in the tool_call_id truncation retry branch. --- src/cai/sdk/agents/models/chatcompletions/litellm_adapter.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cai/sdk/agents/models/chatcompletions/litellm_adapter.py b/src/cai/sdk/agents/models/chatcompletions/litellm_adapter.py index 795d65a0..8533bb68 100644 --- a/src/cai/sdk/agents/models/chatcompletions/litellm_adapter.py +++ b/src/cai/sdk/agents/models/chatcompletions/litellm_adapter.py @@ -68,7 +68,6 @@ async def fetch_response_litellm_openai( """ try: if stream: - ret = await litellm.acompletion(**kwargs) stream_obj = await litellm.acompletion(**kwargs) return _build_response_obj(model_name, model_settings, tool_choice, parallel_tool_calls), stream_obj else: @@ -102,7 +101,6 @@ async def fetch_response_litellm_openai( kwargs["messages"] = messages if stream: - ret = await litellm.acompletion(**kwargs) stream_obj = await litellm.acompletion(**kwargs) return _build_response_obj(model_name, model_settings, tool_choice, parallel_tool_calls), stream_obj else: