Skip to content

[Bug]: litellm parse stream response as json when backend api enables stream by default #18751

Description

@coney

What happened?

my openai model api backend enables stream by default, it means that my api backend responds as streaming when stream field is omitted

when I call my api backend via litellm, if I specified {stream: true} it works fine. But when i request with {stream:false} or omit stream field, litellm try to parse response as fully received json and failed:

  1. client request to litellm without stream field, litellm parse stream response as json failed and respond 500
  2. client request to litellm with {stream: false}, litellm removed stream field, and parse stream reponse as json failed, 500
  3. on model configuration or healthcheck page, run test or healthcheck, litellm request backend without stream field and parse stream response as json failed, 500

error example:

litellm.InternalServerError: InternalServerError: OpenAIException - Empty or invalid response from LLM endpoint. Received: 'data:{"id":"cbe99165da0d49569fc616dedd9ed517","object":"chat.completion","request_timestamp":1767773234456,"created":1767773235,"created_timestamp":1767773235676,"model":"glm-4.6","choices":[{"index":0,"finish_reason":"stop","message":{"content":"\\nThat\'s an easy one! **1 + 1 = 2**.","reasoning_content":null,"role":"assistant","tool_calls":[]},"logprobs":null}],"system_fi
ld

how to fix:

  1. by pass stream field if it presents
  2. add {stream: false} to avoid difference default streaming behavior
  3. parse response according to response content-type header

Relevant log output

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.80.11

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions