litellm - ✅(Solved) Fix [Bug]: streaming_handler.py:197 - Error in _route_streaming_logging_to_handler [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#24281Fetched 2026-04-08 01:08:52
View on GitHub
Comments
0
Participants
1
Timeline
7
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×3labeled ×3referenced ×1

Error Message

LiteLLM Proxy:ERROR: streaming_handler.py:197 - Error in _route_streaming_logging_to_handler: Expecting value: line 1 column 3 (char 2)

Fix Action

Fixed

PR fix notes

PR #1: [Fix]: streaming_handler.py:197 - Error in _route_streaming_logging_to_handler for model "anthropic/deepseek-reasoner"

Description (problem / solution / changelog)

Relevant issues

When using model: anthropic/deepseek-reasoner in config.yaml (using deepseek's Anthropic compatible API), see the following error when handling requests:

LiteLLM Proxy:ERROR: streaming_handler.py:197 - Error in _route_streaming_logging_to_handler: Expecting value: line 1 column 3 (char 2)

Root cause

Call stack:

litellm/proxy/pass_through_endpoints/streaming_handler.py
litellm/proxy/pass_through_endpoints/llm_provider_handlers/anthropic_passthrough_logging_handler.py
litellm/llms/anthropic/chat/handler.py

The resons is that Deepseek returns "data: DONE" instead of a valid json string, while litellm/llms/anthropic/chat/handler.py assumes it's a valid json thus triggers a JSONDecodeError.

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🐛 Bug Fix

Changed files

  • litellm/llms/anthropic/chat/handler.py (modified, +10/-4)
  • tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_handler.py (modified, +165/-0)

Code Example

LiteLLM Proxy:ERROR: streaming_handler.py:197 - Error in _route_streaming_logging_to_handler: Expecting value: line 1 column 3 (char 2)

---
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

When using model: anthropic/deepseek-reasoner in config.yaml, see the following error when handling requests:

LiteLLM Proxy:ERROR: streaming_handler.py:197 - Error in _route_streaming_logging_to_handler: Expecting value: line 1 column 3 (char 2)

Steps to Reproduce

  1. Create a model with model: anthropic/deepseek-reasoner in config.yaml
  2. Start proxy server
  3. Send a request to the model and observe console logs

Relevant log output

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.82.4

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

The fix involves updating the streaming_handler.py to correctly parse the input data.

  • Check the input data being sent to the model for any formatting issues.
  • Update the streaming_handler.py to handle the specific input data format.
  • Specifically, the error message indicates an issue with parsing the input data, expecting a value at line 1 column 3. This suggests that the input data may not be in the expected JSON format.

Code Changes

# streaming_handler.py
import json

def _route_streaming_logging_to_handler(data):
    try:
        # Attempt to parse the input data as JSON
        json_data = json.loads(data)
        # Process the JSON data
    except json.JSONDecodeError as e:
        # Handle the error, e.g., log the error and return an error response
        print(f"Error parsing input data: {e}")
        return {"error": "Invalid input data"}

Verification

To verify the fix, send a request to the model with a valid JSON payload and check the console logs for any errors. The request should be processed correctly, and the response should be returned without any errors.

Extra Tips

  • Ensure that the input data is in the correct format (JSON) and that it is being sent correctly to the model.
  • Consider adding additional error handling and logging to help diagnose any future issues.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - ✅(Solved) Fix [Bug]: streaming_handler.py:197 - Error in _route_streaming_logging_to_handler [1 pull requests, 1 participants]