Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

itellm.APIConnectionError: Error parsing chunk: Expecting property name enclosed in double quotes #3648

Open
etheaven opened this issue Mar 26, 2025 · 6 comments
Labels
question Further information is requested

Comments

@etheaven
Copy link

Issue

I add multiple files for both editable(4) and readonly(5)
I prepare bigger prompt for "/paste"
LLM starts replying a bit, but in the middle of it, I get an error:

itellm.APIConnectionError: Error parsing chunk: Expecting property name enclosed in double quotes: line 1 column 2 (char
1),
Received chunk: {
Traceback (most recent call last):
  File
"C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\litellm\llms\vertex_ai\gemini\vertex_and_google_ai
_studio_gemini.py", line 1469, in __next__
    return self._common_chunk_parsing_logic(chunk=chunk)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File
"C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\litellm\llms\vertex_ai\gemini\vertex_and_google_ai
_studio_gemini.py", line 1443, in _common_chunk_parsing_logic
    return self.handle_valid_json_chunk(chunk=chunk)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File
"C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\litellm\llms\vertex_ai\gemini\vertex_and_google_ai
_studio_gemini.py", line 1403, in handle_valid_json_chunk
    raise e
  File
"C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\litellm\llms\vertex_ai\gemini\vertex_and_google_ai
_studio_gemini.py", line 1395, in handle_valid_json_chunk
    json_chunk = json.loads(chunk)
                 ^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File
"C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\litellm\litellm_core_utils\streaming_handler.py",
line 1543, in __next__
    chunk = next(self.completion_stream)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File
"C:\Users\admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\litellm\llms\vertex_ai\gemini\vertex_and_google_ai
_studio_gemini.py", line 1473, in __next__

aider tries to finish the request but keeps running into the error

Version and model info

Aider v0.79.0
Model: gemini/gemini-2.5-pro-exp-03-25 with diff-fenced edit format
Git repo: .git with 52 files
Repo-map: using 4096 tokens, auto refresh

@Emasoft
Copy link

Emasoft commented Mar 26, 2025

I encountered the same issue:

litellm.APIConnectionError: Error parsing chunk: Expecting property name enclosed in double quotes: line 1 column 2 (char 1),
Received chunk: {
Traceback (most recent call last):
  File
"/Users/admin/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_go
ogle_ai_studio_gemini.py", line 1469, in __next__
    return self._common_chunk_parsing_logic(chunk=chunk)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File
"/Users/admin/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_go
ogle_ai_studio_gemini.py", line 1443, in _common_chunk_parsing_logic
    return self.handle_valid_json_chunk(chunk=chunk)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File
"/Users/admin/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_go
ogle_ai_studio_gemini.py", line 1403, in handle_valid_json_chunk
    raise e
  File
"/Users/admin/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_go
ogle_ai_studio_gemini.py", line 1395, in handle_valid_json_chunk
    json_chunk = json.loads(chunk)
                 ^^^^^^^^^^^^^^^^^
  File "/Users/admin/.local/share/uv/python/cpython-3.12.8-macos-aarch64-none/lib/python3.12/json/__init__.py", line
346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/admin/.local/share/uv/python/cpython-3.12.8-macos-aarch64-none/lib/python3.12/json/decoder.py", line
338, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/admin/.local/share/uv/python/cpython-3.12.8-macos-aarch64-none/lib/python3.12/json/decoder.py", line
354, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File
"/Users/admin/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/litellm_core_utils/streaming_handle
r.py", line 1543, in __next__
    chunk = next(self.completion_stream)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File
"/Users/admin/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_go
ogle_ai_studio_gemini.py", line 1473, in __next__

My configuration:

Aider v0.79.1
Model: gemini/gemini-2.5-pro-exp-03-25 with architect edit format
Editor model: gemini/gemini-2.5-pro-exp-03-25 with diff-fenced edit format
Git repo: .git with 4 files
Repo-map: using 4096 tokens, auto refresh
Restored previous conversation history.
Multiline mode: Enabled. Enter inserts newline, Alt-Enter submits text
Command Line Args:   --architect --model gemini-2.5-pro --multiline --yes-always --auto-accept-architect --lint-cmd "bash:
shellcheck --severity=error --extended-analysis=true" --lint-cmd "python: ruff check --ignore
E203,E402,E501,E266,W505,F841,F842,F401,W293,I001,UP015,C901,W291 --isolated --fix --output-format full" --restore-chat-history
--auto-lint

@rpofuk
Copy link

rpofuk commented Mar 26, 2025

Same here, Same configuration

@etheaven
Copy link
Author

Happens even without /paste usage.

@rpofuk
Copy link

rpofuk commented Mar 27, 2025

aider 0.79.1
--model gemini-2.5-pro
It happens how almost all the time with gemini 2.5

litellm.APIConnectionError: Error parsing chunk: Expecting property name enclosed in double quotes: line 1 column 2 (char 1),
Received chunk: {
Traceback (most recent call last):
  File "/home/pofuk/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 1469, in __next__
    return self._common_chunk_parsing_logic(chunk=chunk)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pofuk/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 1443, in 
_common_chunk_parsing_logic
    return self.handle_valid_json_chunk(chunk=chunk)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pofuk/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 1403, in handle_valid_json_chunk
    raise e
  File "/home/pofuk/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 1395, in handle_valid_json_chunk
    json_chunk = json.loads(chunk)
                 ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pofuk/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/litellm_core_utils/streaming_handler.py", line 1543, in __next__
    chunk = next(self.completion_stream)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pofuk/.local/share/uv/tools/aider-chat/lib/python3.12/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 1473, in __next__
    raise RuntimeError(f"Error parsing chunk: {e},\nReceived chunk: {chunk}")
RuntimeError: Error parsing chunk: Expecting property name enclosed in double quotes: line 1 column 2 (char 1),
Received chunk: {

@paul-gauthier
Copy link
Collaborator

Litellm has this issue open on other Gemini models for a long time. They believe the Gemini API is returning malformed json sometimes.

BerriAI/litellm#5650

@TomKaltofen
Copy link

In my project mloda, I ve seen seen also that the API is not stable e.g. this here: https://www.reddit.com/r/Bard/comments/1isf7p5/comment/mg166ol/?context=3

@github-actions github-actions bot added the question Further information is requested label Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants