Repository navigation
Description
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
The SDK silently drops all image content for openhands/deepseek-v4.1-flash
from outgoing requests, even though LLM.vision_is_active() returns True
and the provider can genuinely process images.
This report was drafted by an AI agent (OpenHands) on behalf of the user.
Expected Behavior
A model that the SDK/proxy recognises as vision-capable should serialize image
content with the list serializer. If a model truly requires string-only content,
the SDK should still deliver images via a non-dropping path, or at minimum warn
loudly instead of silently discarding them.
Concretely: deepseek-v4-flash / deepseek-v4.1-flash / deepseek-v4-pro
should not match FORCE_STRING_SERIALIZER_MODELS, since they accept structured
(list) content.
Actual Behavior
Images are removed from the outgoing payload. In this environment the only image
tool observation in the conversation event log contains the base64 image, but the
formatted LLM request contains no image_url part, and the agent reports it can
only see text.
Steps to Reproduce
- Use a model whose name contains
deepseekand whose provider reports
supports_vision=True, e.g.openhands/deepseek-v4.1-flash. - Leave
force_string_serializerunset (defaultNone). - Format a user message that contains an image:
from openhands.sdk import LLM
from openhands.sdk.llm.message import Message, TextContent, ImageContent
llm = LLM(model="openhands/deepseek-v4.1-flash", api_key="...") # force_string_serializer defaults to None
msg = Message(
role="user",
content=[TextContent(text="What color is this?"), ImageContent(image_urls=["data:image/png;base64,..."])],
)
payload = llm.format_messages_for_llm([msg])Observed:
vision_is_active() = True
force_string_serializer (effective) = True # from "deepseek" substring
image_url parts in payload = 0
payload = [{"content": "What color is this?", "role": "user"}]
Setting force_string_serializer=False restores it:
force_string_serializer (effective) = False
image_url parts in payload = 1
The same drop occurs for role="tool" (observation) messages.
Acceptance Criteria
- A
deepseek-named model that reportssupports_vision=Trueno longer has
its image parts dropped (image_url present in the formatted payload). -
FORCE_STRING_SERIALIZER_MODELSno longer uses the unqualified"deepseek"
substring; only the specific legacy ids that genuinely require string-only
content match. - Unit test asserting
get_features("openhands/deepseek-v4.1-flash").force_string_serializer is False
(or that a vision-active model is never string-serialized). - Existing
DeepSeek-V3.2-Expstring-serializer behavior (PR Add glm4.6 to FORCE_STRING_SERIALIZER #994/Add tests for string serializer #996) is preserved.
Installation Method
pip install openhands-sdk
If you selected "Other", please specify
No response
SDK Version
openhands-sdk==1.49.6 (also present on main at the time of filing: FORCE_STRING_SERIALIZER_MODELS still contains the bare "deepseek" substring).
Version Confirmation
- I have confirmed this bug exists on the LATEST version of OpenHands SDK
Python Version
3.12
Model Name (if applicable)
openhands/deepseek-v4.1-flash (also reproduced reasoning for deepseek-v4-flash, deepseek-v4-pro). Provider reports supports_vision=True.
Operating System
MacOS
Logs and Error Messages
o error is raised — the image is silently removed. Evidence from
LLM.format_messages_for_llm:
force_string_serializer=None -> effective=True images_in_payload=0 # default (bug)
force_string_serializer=False -> effective=False images_in_payload=1 # fix
force_string_serializer=True -> effective=True images_in_payload=0
Direct provider probe (tool message with list vs. string content) shows the
provider accepts list content, i.e. it does not need the string serializer:
=== deepseek-v4.1-flash ===
list-content OK
string-content OK
=== deepseek-v4-flash ===
list-content OK
string-content OK
Minimal Code Sample
from openhands.sdk import LLM
from openhands.sdk.llm.message import Message, TextContent, ImageContent
TINY = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
def image_parts(fm):
return sum(1 for m in fm for p in (m.get("content") or [])
if isinstance(p, dict) and p.get("type") == "image_url")
msg = Message(role="user", content=[TextContent(text="color?"), ImageContent(image_urls=[TINY])])
for v in (None, False):
llm = LLM(model="openhands/deepseek-v4.1-flash", api_key="x", force_string_serializer=v)
print(v, "->", image_parts(llm.format_messages_for_llm([msg])))
# None -> 0 (bug)
# False -> 1 (works)Screenshots and Additional Context
Introduced by PR #994 / #995 / #996, which moved "deepseek" into the
substring-matched FORCE_STRING_SERIALIZER_MODELS (originally for
DeepSeek-V3.2-Exp). Since then, all DeepSeek models match.
- Suggested fix: narrow the entry to the specific legacy ids (e.g.
deepseek-v3,deepseek-v3.2,deepseek-reasoner,deepseek-chat), or skip
string serialization whenevervision_is_active()isTrue. - Two independent contributing factors for users: (a) the substring match forces
the flagTrue; (b)capability_overridescannot override it, and aNone
field is dropped on profile save (exclude_none=True), so it silently
reverts to auto-detect.
Related but not the same root cause:
- Deepseek-v4-pro cannot see images in SaaS #3768 "Deepseek-v4-pro cannot see images in SaaS" — related but different:
the proxy's/v1/model/inforeportssupports_vision=Falsefor
deepseek-v4-pro(anddeepseek-v4-flash), so those models genuinely are not
vision-capable and the agent was not doing anything wrong for them. This report
is specifically aboutdeepseek-v4.1-flash, which is flagged
supports_vision=Trueyet still loses its images. - Kimi-k2.6 is not being recognized as a vision model in the SDK #3767 "Kimi-k2.6 is not being recognized as a vision model in the SDK" — same
family of symptom; different model, closed as stale. - Vision capability detection + image serialization with LiteLLM/OpenRouter: inconsistent supports_vision on prefixed names can drop images or cause 400s #1331 / Vision capability detection + image serialization with LiteLLM/OpenRouter: supports_vision on prefixed names leads to dropped images or 400s #1332 / Vision capability detection + image serialization with LiteLLM/OpenRouter: supports_vision on prefixed names leads to dropped images or 400s #1333 / LiteLLM/OpenRouter vision detection inconsistency #1334 (closed 2025-12-05) — fixed dropping images when
vision_enabledresolved toFalse(PR Fix: Enable vision for messages containing ImageContent #1279 added "OR message contains
ImageContent"). Those changes do not cover this bug: when
force_string_serializerisTrue,to_chat_dicttakes the string branch
unconditionally and never consultsvision_enabledor the message contents.
Herevision_is_active()is alreadyTrueand images are still dropped. - Umbrella [Bug]: DeepSeek v4-pro/v4-flash compatibility issues (model list, provider routing, reasoning_content) #3267 (DeepSeek v4 compatibility) is closed and never covered vision/serialization.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Confirmed bug: FORCE_STRING_SERIALIZER_MODELS in openhands-sdk/openhands/sdk/llm/utils/model_features.py contains the bare substring "deepseek". model_matches() performs an unordered case-insensitive substring test, so every DeepSeek id — including openhands/deepseek-v4.1-flash, deepseek-v4-flash, and deepseek-v4-pro — resolves force_string_serializer=True. In Message.to_chat_dict() the force_string_serializer guard is evaluated before the vision_enabled branch, so the string serializer runs unconditionally and image parts are dropped even when LLM.vision_is_active() is True.
Scope: narrow the DeepSeek entry so only ids that genuinely require string-only tool-message content match, and ensure a vision-active model is never string-serialized. The minimal coherent change is to replace "deepseek" with the specific legacy substring "deepseek-v3.2"; this keeps DeepSeek-V3.2-Exp and deepseek-v3.2-reasoner on the string serializer while freeing v4, v4.1, and deepseek-chat. Because deepseek-v4-flash-vision-exp is a verified DeepSeek id in verified_models.py, the narrowing must also preserve its images.
Non-goals:
- Do not auto-narrow
"glm","groq/kimi-k2-instruct", or"openrouter/minimax"; no evidence they regress. - Do not redesign
FORCE_STRING_SERIALIZER_MODELSinto per-model feature flags. - Do not change
capability_overrides/ profileexclude_none=Truebehavior raised in the report; that is a separate concern. - Do not add a warning/log when an image is dropped under a forced string serializer unless maintainers request it.
Acceptance Criteria
-
get_features("openhands/deepseek-v4.1-flash").force_string_serializerisFalse, and the formatted payload for a user message containingImageContentkeeps oneimage_urlpart; the same holds fordeepseek-v4-flash,deepseek-v4-pro,deepseek-v4-flash-vision-exp, anddeepseek-chat. -
get_features("DeepSeek-V3.2-Exp").force_string_serializerandget_features("deepseek-v3.2-reasoner").force_string_serializerremainTrue, preserving the behavior introduced by PR Add glm4.6 to FORCE_STRING_SERIALIZER #994/Add tests for string serializer #996. -
FORCE_STRING_SERIALIZER_MODELSno longer contains the bare"deepseek"substring; the DeepSeek entry matches only the specific legacy id(s) that require string-only content. - For a string-serialized model, an
ImageContentpart is represented in the outgoing payload rather than silently removed (image_url part present or equivalent non-dropping path), for bothrole="user"androle="tool"messages. - An explicit
force_string_serializer=Trueon a vision-capable model still takes precedence and continues to string-serialize without error. - Regression coverage exists in
tests/sdk/llm/asserting the above feature-flag and payload outcomes, extending the existingtest_force_string_serializer_full_model_namescase. - Existing DeepSeek-affected unit tests (for example
test_llm_force_string_serializer_auto_detect) pass unchanged.
Activity
fix(llm): stop string-serializing vision-capable DeepSeek v4 models
fix(llm): stop string-serializing vision-capable DeepSeek v4 models