From 1fb38dfa311e5aab6c29ada4f43590544624eec4 Mon Sep 17 00:00:00 2001 From: Cesar Garcia <128240629+Chesars@users.noreply.github.com> Date: Wed, 4 Mar 2026 19:54:49 -0300 Subject: [PATCH] Update litellm/llms/openai/responses/count_tokens/transformation.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- .../openai/responses/count_tokens/transformation.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/litellm/llms/openai/responses/count_tokens/transformation.py b/litellm/llms/openai/responses/count_tokens/transformation.py index ca9526bc187..b9b36dcbea5 100644 --- a/litellm/llms/openai/responses/count_tokens/transformation.py +++ b/litellm/llms/openai/responses/count_tokens/transformation.py @@ -118,6 +118,16 @@ class OpenAICountTokensConfig: text_parts.append(block) instructions_parts.append("\n".join(text_parts)) elif role == "user": + if isinstance(content, list): + # Extract text from content blocks for Responses API + text_parts = [] + for block in content: + if isinstance(block, dict) and block.get("type") == "text": + text_parts.append(block.get("text", "")) + elif isinstance(block, str): + text_parts.append(block) + content = "\n".join(text_parts) + input_items.append({"role": "user", "content": content}) input_items.append({"role": "user", "content": content}) elif role == "assistant": # Map tool_calls to Responses API function_call items