harry0703/MoneyPrinterTurbo · error · ValueError

Empty content in stream response

Error message

Empty content in stream response

What it means

Raised in the modelscope branch after streaming completed: it iterated all chunks with stream=True and enable_thinking=False, accumulated delta.content into a string, and the result was empty or whitespace-only. The HTTP call succeeded but produced no readable text.

Source

Thrown at app/services/llm.py:377

                api_key=api_key,
                base_url=base_url,
            )
            response = client.chat.completions.create(
                model=model_name,
                messages=[{"role": "user", "content": prompt}],
                extra_body={"enable_thinking": False},
                stream=True,
            )
            if response:
                for chunk in response:
                    if not chunk.choices:
                        continue
                    delta = chunk.choices[0].delta
                    if delta and delta.content:
                        content += delta.content

                if not content.strip():
                    raise ValueError("Empty content in stream response")

                return _normalize_text_response(content, llm_provider)
            else:
                raise Exception(f"[{llm_provider}] returned an empty response")

        client = OpenAI(
            api_key=api_key,
            base_url=base_url,
        )

        response = client.chat.completions.create(
            model=model_name, messages=[{"role": "user", "content": prompt}]
        )
        if response:
            if isinstance(response, ChatCompletion):
                return _extract_chat_completion_text(response, llm_provider)
            else:
                raise Exception(

View on GitHub (pinned to 1f9f19c202)

Solutions

  1. Retry once via the existing retry loop — transient empty streams occur on the free ModelScope inference tier
  2. Verify base_url is https://api-inference.modelscope.cn/v1 (or your region's equivalent) and model_name is the full ModelScope model id
  3. Try the same call with enable_thinking=True to see if the model only produces reasoning tokens; if so, switch to a non-reasoning model
  4. Test with curl using the same stream payload to inspect raw SSE chunks
  5. If persistent, switch llm_provider to another OpenAI-compatible provider

Example fix

# before
extra_body={"enable_thinking": False},
stream=True,

# after (capture finish_reason for diagnosis)
for chunk in response:
    if not chunk.choices:
        continue
    delta = chunk.choices[0].delta
    if delta and delta.content:
        content += delta.content
    finish = chunk.choices[0].finish_reason
if not content.strip():
    raise ValueError(f"Empty content in stream response (finish_reason={finish})")
Defensive patterns

Strategy: retry

Try / catch

except ValueError as e: if 'Empty content in stream' in str(e): retry — empty streams from the free ModelScope tier are frequently transient; after N retries switch model or provider

Prevention

When it happens

Trigger: ModelScope chat.completions.create(stream=True, extra_body={'enable_thinking': False}) yields only chunks with empty choices, empty delta, or role-only deltas — model server returned empty content, thinking-only output that was suppressed, content moderation filtered everything, or wrong model id for the endpoint.

Common situations: Using a ModelScope reasoning model with enable_thinking=False where the server still emits only thinking tokens; free-tier ModelScope inference (API-Inference) returning empty streams under load; model_name mismatch with the ModelScope model id (e.g. missing 'modelscope/' prefix or owner path); base_url not pointing at the ModelScope OpenAI-compatible endpoint.

Related errors


AI-assisted analysis of harry0703/MoneyPrinterTurbo@1f9f19c202 (2026-08-14). Data as JSON: /api/errors/aac3bc0e959eedef. Report an issue: GitHub.