Some OpenAI-compatible gateways (e.g. api.cline.bot) wrap non-streaming
JSON bodies in {"data": {<chat completion>}, "success": true}. The
OpenAI SDK leniently parses this into a ChatCompletion with choices=None
and keeps the envelope keys as extra fields, so auxiliary calls (vision,
compression, title generation, web extract) failed in
_validate_llm_response with a generic "LLM returned invalid response"
error. Main chat was unaffected because it streams and SSE chunks pass
through unwrapped.
Unwrap the envelope at the _validate_llm_response chokepoint: rebuild
the real completion via model_validate (SimpleNamespace synthesis as
fallback), and surface the provider's actual error message for
{"success": false, "data": {"error": ...}} envelopes. Detection is
conservative — responses with top-level choices or without a dict
"data" field are returned untouched.